Class: Ironfan::Dsl::MachineManifest

Inherits:
Object
  • Object
show all
Includes:
Gorillib::Model
Defined in:
lib/ironfan/dsl/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_computer(computer) ⇒ Object

Reconstruct machine manifest from a computer, pulling information from remote sources as necessary.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ironfan/dsl/server.rb', line 70

def self.from_computer(computer)
  node = get_node(computer.name)
  cluster_name = node['cluster_name']
  Chef::Log.info "name is whoa: #{cluster_name}"
  facet_name = node['facet_name']
  instance = node['facet_index']

  from_remote(
              cluster_name,
              facet_name,
              instance,
              node,
              computer.machine,
              computer.server.clouds.to_a.first,
              get_role("#{cluster_name}-cluster"),
              get_role("#{cluster_name}-#{facet_name}-facet")
            )
end

.from_remote(cluster_name, facet_name, instance, node, machine, cloud, cluster_role, facet_role) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/ironfan/dsl/server.rb', line 89

def self.from_remote(cluster_name,
                     facet_name,
                     instance,
                     node,
                     machine,
                     cloud,
                     cluster_role,
                     facet_role)
  machine = NilCheckDelegate.new(machine)
  cloud = NilCheckDelegate.new(cloud)
  cluster_role = NilCheckDelegate.new(cluster_role)
  facet_role = NilCheckDelegate.new(facet_role)

  result = Ironfan::Dsl::MachineManifest.
    receive(

            # base server fields

            environment: node.chef_environment,
            name: instance,
            cluster_name: cluster_name,
            facet_name: facet_name,
            components: remote_components(node),
            run_list: remote_run_list(node),
            cluster_default_attributes: (cluster_role.default_attributes || {}),
            cluster_override_attributes: (cluster_role.override_attributes || {}),
            facet_default_attributes: (facet_role.default_attributes || {}),
            facet_override_attributes: (facet_role.override_attributes || {}),

            # cloud fields

            backing: machine.root_device_type,
            cloud_name: cloud.name,
            availability_zones: [*machine.availability_zone],
            ebs_optimized: machine.ebs_optimized,
            flavor: machine.flavor_id,
            image_id: machine.image_id,
            keypair: machine.nilcheck_depth(1).key_pair.name,
            monitoring: machine.monitoring,
            placement_group: machine.placement_group,
            region: machine.availability_zone.to_s[/.*-.*-\d+/],
            security_groups: machine.nilcheck_depth(1).groups.map{|x| {name: x}},
            subnet: machine.subnet_id,
            vpc: machine.vpc_id

            #-----------------------------------------------------------------------------------
            # # FIXME: I haven't determined how to pull some of these fields
            # #        in from the remote machines. In fact, some of these
            # #        will have to be omitted when comparing. Since
            # #        they'll only be necessary when we refactor the
            # #        backend to accept manifests for launch, I'm going
            # #        to leave these commented out for now. --josh
            #
            # # base server fields
            #
            # volume: local_manifest.volume
            #
            # # cloud fields 
            #
            # bits: local_manifest.bits,
            # bootstrap_distro: local_manifest.bootstrap_distro,
            # chef_client_script: local_manifest.chef_client_script,                  
            # default_availability_zone: local_manifest.default_availability_zone,
            # iam_server_certificates: launch_description.fetch(:iam_server_certificates),
            # image_name: local_manifest.image_name,
            # elastic_load_balancers: launch_description.fetch(:elastic_load_balancers),
            # mount_ephemerals: local_manifest.mount_ephemerals,
            # permanent: local_manifest.permanent,
            # provider: local_manifest.provider,
            # elastic_ip: local_manifest.elastic_ip,
            # auto_elastic_ip: local_manifest.auto_elastic_ip,
            # allocation_id: local_manifest.allocation_id,
            # ssh_user: local_manifest.ssh_user,
            # ssh_identity_dir: local_manifest.ssh_identity_dir,
            # validation_key: local_manifest.validation_key,
            #-----------------------------------------------------------------------------------
            )
end

Instance Method Details

#to_comparableObject



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/ironfan/dsl/server.rb', line 168

def to_comparable
  deep_stringify(to_wire.tap do |hsh|
                   hsh.delete(:_type)
                   hsh.delete(:ssh_user)
                   #hsh[:security_groups] = Hash[hsh[:security_groups].map{|x| [x.fetch(:name), x]}]
                   hsh[:components] = Hash[hsh[:components].to_a.map do |component|
                                             [component[:name].to_s, component]
                                           end]
                   hsh[:run_list] = hsh[:run_list].to_a.map do |x|
                     x.end_with?(']') ? x : "recipe[#{x}]"
                   end
                 end)
end