module DTK::DSL::ServiceAndComponentInfo::TransformFrom::Parser::TopDSL::Assemblies::NodeBindings

Public Class Methods

add_node_properties!(assembly_content, node_bindings) click to toggle source
# File lib/dsl/service_and_component_info/transform_from/parser/top_dsl/assemblies/node_bindings.rb, line 22
def self.add_node_properties!(assembly_content, node_bindings) 
  nodes = assembly_content['nodes'] || []
  return if nodes.empty?

  node_bindings.each do |node, node_binding|
    if node_content = nodes[node]
      process_node_content!(node_content, node_binding) 
    end
  end
end

Private Class Methods

ec2_properties_from_node_binding(node_binding) click to toggle source
# File lib/dsl/service_and_component_info/transform_from/parser/top_dsl/assemblies/node_bindings.rb, line 61
def self.ec2_properties_from_node_binding(node_binding)
  image, size = node_binding.split('-')
  [image, size]
end
include_node_property_component?(components) click to toggle source
# File lib/dsl/service_and_component_info/transform_from/parser/top_dsl/assemblies/node_bindings.rb, line 66
def self.include_node_property_component?(components)
  property_component = 'ec2::properties'
  components.each do |component|
    if component.is_a?(Hash)
      return components.index(component) if component.keys.first.eql?(property_component)
    else
      return components.index(component) if component.eql?(property_component)
    end
  end
  false
end
process_node_content!(node_content, node_binding) click to toggle source
# File lib/dsl/service_and_component_info/transform_from/parser/top_dsl/assemblies/node_bindings.rb, line 35
def self.process_node_content!(node_content, node_binding)
  components  = node_content['components']
  components  = components.is_a?(Array) ? components : [components]
  image, size = ec2_properties_from_node_binding(node_binding)
  new_attrs   = { 'image' => image, 'size' => size }

  if index = include_node_property_component?(components)
    ec2_properties = components[index]
    if ec2_properties.is_a?(::Hash)
      if attributes = ec2_properties.values.first['attributes']
        attributes['image'] ||= image
        attributes['size'] ||= size
      else
        ec2_properties.merge!('attributes' => new_attrs)
      end
    else
      components[index] = { ec2_properties => { 'attributes' => new_attrs } }
    end
  elsif node_attributes = node_content['attributes']
    node_attributes['image'] ||= image 
    node_attributes['size'] ||= size 
  else
    node_content['attributes'] = new_attrs
  end
end