Class: Topo::Provision::ResourceGenerator
- Inherits:
-
Object
- Object
- Topo::Provision::ResourceGenerator
- Includes:
- Topo::ParseGen
- Defined in:
- lib/topo/provision/generators/resource.rb
Direct Known Subclasses
AwsAutoScalingGroupGenerator, AwsLaunchConfigurationGenerator, AwsNodeGroupGenerator, ChefNodeGenerator, LoadBalancerGenerator, MachineGenerator, NodeGroupGenerator
Constant Summary collapse
- @@templates =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource_attributes ⇒ Object
readonly
Returns the value of attribute resource_attributes.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#undeploy_action ⇒ Object
readonly
Returns the value of attribute undeploy_action.
Instance Method Summary collapse
- #default_action(action) ⇒ Object
- #default_resource_template(action) ⇒ Object
- #deploy ⇒ Object
- #do_action(action) ⇒ Object
-
#initialize(data) ⇒ ResourceGenerator
constructor
A new instance of ResourceGenerator.
- #template(action) ⇒ Object
- #template_root_dir ⇒ Object
- #undeploy ⇒ Object
Methods included from Topo::ParseGen
#convert_keys_to_sym, #convert_keys_to_sym_deep, #expand_ref, #lazy_attribute_to_s, #topo_refs, #value_from_path
Constructor Details
#initialize(data) ⇒ ResourceGenerator
Returns a new instance of ResourceGenerator.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/topo/provision/generators/resource.rb', line 34 def initialize(data) @resource_type||= "resource" # define in each class @template_base_name = @resource_type @undeploy_action = "destroy" @resource_attributes = {} # define in each class @name = data['name'] provisioning = data['provisioning'] %w[ driver chef_server].each do |key| @resource_attributes[key] = provisioning[key] if provisioning && provisioning.key?(key) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/topo/provision/generators/resource.rb', line 31 def name @name end |
#resource_attributes ⇒ Object (readonly)
Returns the value of attribute resource_attributes.
31 32 33 |
# File 'lib/topo/provision/generators/resource.rb', line 31 def resource_attributes @resource_attributes end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
31 32 33 |
# File 'lib/topo/provision/generators/resource.rb', line 31 def resource_type @resource_type end |
#undeploy_action ⇒ Object (readonly)
Returns the value of attribute undeploy_action.
31 32 33 |
# File 'lib/topo/provision/generators/resource.rb', line 31 def undeploy_action @undeploy_action end |
Instance Method Details
#default_action(action) ⇒ Object
62 63 |
# File 'lib/topo/provision/generators/resource.rb', line 62 def default_action(action) end |
#default_resource_template(action) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/topo/provision/generators/resource.rb', line 69 def default_resource_template(action) default = "resource_#{action}" if @@templates[default] == nil path = File.join(File.("../templates", __FILE__), "#{default}.erb") @@templates[default] = ERB.new(File.new(path).read, nil, '>') end @@templates[default] end |
#deploy ⇒ Object
54 55 56 |
# File 'lib/topo/provision/generators/resource.rb', line 54 def deploy() puts(template("deploy").result(binding)) end |
#do_action(action) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/topo/provision/generators/resource.rb', line 46 def do_action(action) if (self.respond_to? action) self.send(action) else self.send("default_action", action) end end |
#template(action) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/topo/provision/generators/resource.rb', line 79 def template(action) name = "#{@template_base_name}_#{action}" if (@@templates[name] == nil) path = File.join(template_root_dir, "#{name}.erb") @@templates[name] = File.exists?(path) ? ERB.new(File.new(path).read, nil, '>') : default_resource_template(action) end @@templates[name] end |
#template_root_dir ⇒ Object
65 66 67 |
# File 'lib/topo/provision/generators/resource.rb', line 65 def template_root_dir File.("../templates", __FILE__) end |
#undeploy ⇒ Object
58 59 60 |
# File 'lib/topo/provision/generators/resource.rb', line 58 def undeploy() puts(template("undeploy").result(binding)) end |