Class: Wire::Resource::ResourceFactory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/wire/resource/resource.rb

Overview

ResourceFactory creates Resource objects given by symbolic name

Instance Method Summary collapse

Instance Method Details

#create(resource_symname, *resource_nameargs) ⇒ Object

given a resource_symname as a symbol (i.e. :ovsbridge) this creates a resource with given name (i.e. “testbridge”) and hands on arguments (resource_nameargs, may be 1..n) returns

  • a new Resource object, depending on type



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wire/resource/resource.rb', line 38

def create(resource_symname, *resource_nameargs)
  clazz_map = {
    :ovsbridge  => OVSBridge,
    :bridgeip   => IPAddressOnIntf,
    :dhcpconfig => DHCPRangeConfiguration,
    :figadapter => FigAdapter,
    :networkinjection => NetworkInjection
  }
  clazz = clazz_map[resource_symname]
  fail(ArgumentError, "Unknown resource type #{resource_symname}") unless clazz
  clazz.new(*resource_nameargs)
end