vm_shepherd 1.11.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 763cd128f7302c5fb7250c56c5fb6f2902659a7b
4
- data.tar.gz: aac10b49759fcb9b8c5b385e8f9a3bb4fc6b32d6
3
+ metadata.gz: 158b8027d9711d2346b03702c5a3302d9f723f35
4
+ data.tar.gz: ad05a0ea0e8928fd0bbbae0db8c833ef0edd08ee
5
5
  SHA512:
6
- metadata.gz: b67e18537b886374536aaf33ec441b389c81ffeb283fcaff7ddff1c53899db708f9fceebc9b22ea90a70d29b810b56f04f6486d7689d17721cea9a8304247075
7
- data.tar.gz: 7e0e37f43205234107f6350dde7dcbf3d6c409b4b25357fd486710b95504563cd7e3d825f7e5ab6365a8981b0913d9a99d21c1a5e4748b8c19a0ae72377ac1b1
6
+ metadata.gz: ebc04c69df9a355dd6cd9424463f591142ac1d74414677df1c3ddf8965564afa02a1d8176afb73bc92fd8083a3935c546cdcf50273cd5c5e244b9584a8f9e324
7
+ data.tar.gz: 9031ac449813be9d4f4986a00d345cd03edc2c73603ad727790e12063ee6940a805867f77d7cc435e2ad80e6b77e81407123bb101cdebab11108a0649d21cddb
data/lib/vm_shepherd.rb CHANGED
@@ -9,8 +9,8 @@ require 'vm_shepherd/vcloud/vapp_config'
9
9
  require 'vm_shepherd/vsphere_manager'
10
10
 
11
11
  module VmShepherd
12
- AWS_IAAS_TYPE = 'aws'.freeze
12
+ AWS_IAAS_TYPE = 'aws'.freeze
13
13
  OPENSTACK_IAAS_TYPE = 'openstack'.freeze
14
- VCLOUD_IAAS_TYPE = 'vcloud'.freeze
15
- VSPHERE_IAAS_TYPE = 'vsphere'.freeze
14
+ VCLOUD_IAAS_TYPE = 'vcloud'.freeze
15
+ VSPHERE_IAAS_TYPE = 'vsphere'.freeze
16
16
  end
@@ -6,24 +6,24 @@ module VmShepherd
6
6
  include VmShepherd::RetryHelper
7
7
 
8
8
  OPS_MANAGER_INSTANCE_TYPE = 'm3.medium'
9
- DO_NOT_TERMINATE_TAG_KEY = 'do_not_terminate'
10
- ELB_SECURITY_GROUP_NAME = 'ELB Security Group'
9
+ DO_NOT_TERMINATE_TAG_KEY = 'do_not_terminate'
10
+ ELB_SECURITY_GROUP_NAME = 'ELB Security Group'
11
11
 
12
- CREATE_IN_PROGRESS = 'CREATE_IN_PROGRESS'
13
- CREATE_COMPLETE = 'CREATE_COMPLETE'
12
+ CREATE_IN_PROGRESS = 'CREATE_IN_PROGRESS'
13
+ CREATE_COMPLETE = 'CREATE_COMPLETE'
14
14
  ROLLBACK_IN_PROGRESS = 'ROLLBACK_IN_PROGRESS'
15
- ROLLBACK_COMPLETE = 'ROLLBACK_COMPLETE'
16
- DELETE_IN_PROGRESS = 'DELETE_IN_PROGRESS'
17
- DELETE_COMPLETE = 'DELETE_COMPLETE'
15
+ ROLLBACK_COMPLETE = 'ROLLBACK_COMPLETE'
16
+ DELETE_IN_PROGRESS = 'DELETE_IN_PROGRESS'
17
+ DELETE_COMPLETE = 'DELETE_COMPLETE'
18
18
 
19
19
  def initialize(env_config:, logger:)
20
20
  AWS.config(
21
- access_key_id: env_config.fetch(:aws_access_key),
21
+ access_key_id: env_config.fetch(:aws_access_key),
22
22
  secret_access_key: env_config.fetch(:aws_secret_key),
23
- region: env_config.fetch(:region),
23
+ region: env_config.fetch(:region),
24
24
  )
25
25
  @env_config = env_config
26
- @logger = logger
26
+ @logger = logger
27
27
  end
28
28
 
29
29
  def prepare_environment(cloudformation_template_file)
@@ -63,11 +63,11 @@ module VmShepherd
63
63
  retry_until do
64
64
  begin
65
65
  AWS.ec2.instances.create(
66
- image_id: image_id,
67
- key_name: env_config.fetch(:outputs).fetch(:ssh_key_name),
66
+ image_id: image_id,
67
+ key_name: env_config.fetch(:outputs).fetch(:ssh_key_name),
68
68
  security_group_ids: [env_config.fetch(:outputs).fetch(:security_group)],
69
- subnet: env_config.fetch(:outputs).fetch(:public_subnet_id),
70
- instance_type: OPS_MANAGER_INSTANCE_TYPE
69
+ subnet: env_config.fetch(:outputs).fetch(:public_subnet_id),
70
+ instance_type: OPS_MANAGER_INSTANCE_TYPE
71
71
  )
72
72
  rescue AWS::EC2::Errors::InvalidIPAddress::InUse
73
73
  false
@@ -92,6 +92,9 @@ module VmShepherd
92
92
  else
93
93
  logger.info('Creating an Elastic IP and assigning it to the instance')
94
94
  elastic_ip = AWS.ec2.elastic_ips.create(vpc: true)
95
+ retry_until do
96
+ elastic_ip.exists?
97
+ end
95
98
  end
96
99
  instance.associate_elastic_ip(elastic_ip)
97
100
  instance.add_tag('Name', value: vm_config.fetch(:vm_name))
@@ -124,7 +127,7 @@ module VmShepherd
124
127
  AWS.ec2.instances.each do |instance|
125
128
  if instance.tags.to_h['Name'] == vm_config.fetch(:vm_name)
126
129
  vm_ip_address = vm_config.fetch(:vm_ip_address, nil)
127
- elastic_ip = instance.elastic_ip unless vm_ip_address
130
+ elastic_ip = instance.elastic_ip unless vm_ip_address
128
131
  if elastic_ip
129
132
  elastic_ip.disassociate
130
133
  elastic_ip.delete
@@ -147,7 +150,7 @@ module VmShepherd
147
150
 
148
151
  def clear_subnet(subnet_id)
149
152
  logger.info("Clearing contents of subnet: #{subnet_id}")
150
- subnet = AWS.ec2.subnets[subnet_id]
153
+ subnet = AWS.ec2.subnets[subnet_id]
151
154
  volumes = []
152
155
  subnet.instances.each do |instance|
153
156
  instance.attachments.each do |_, attachment|
@@ -173,7 +176,7 @@ module VmShepherd
173
176
 
174
177
  def delete_elb(elb_name)
175
178
  if (elb = AWS::ELB.new.load_balancers.find { |lb| lb.name == elb_name })
176
- sg = elb.security_groups.first
179
+ sg = elb.security_groups.first
177
180
  net_interfaces = AWS.ec2.network_interfaces.select do |ni|
178
181
  begin
179
182
  ni.security_groups.map(&:id).include? sg.id
@@ -193,17 +196,17 @@ module VmShepherd
193
196
  end
194
197
 
195
198
  def create_elb(stack, elb_config)
196
- elb = AWS::ELB.new
199
+ elb = AWS::ELB.new
197
200
  elb_params = {
198
201
  load_balancer_name: elb_config[:name],
199
- listeners: [],
200
- subnets: [subnet_id(stack, elb_config)],
201
- security_groups: [create_security_group(stack, elb_config).security_group_id]
202
+ listeners: [],
203
+ subnets: [subnet_id(stack, elb_config)],
204
+ security_groups: [create_security_group(stack, elb_config).security_group_id]
202
205
  }
203
206
 
204
207
  elb_config[:port_mappings].each do |port_mapping|
205
208
  elb_params[:listeners] << {
206
- protocol: 'TCP', load_balancer_port: port_mapping[0],
209
+ protocol: 'TCP', load_balancer_port: port_mapping[0],
207
210
  instance_protocol: 'TCP', instance_port: port_mapping[1]
208
211
  }
209
212
  end
@@ -213,11 +216,11 @@ module VmShepherd
213
216
  end
214
217
 
215
218
  def create_security_group(stack, elb_config)
216
- vpc_id = vpc_id(stack, elb_config)
219
+ vpc_id = vpc_id(stack, elb_config)
217
220
  sg_params = {
218
- group_name: [stack.name, elb_config[:name]].join('_'),
221
+ group_name: [stack.name, elb_config[:name]].join('_'),
219
222
  description: 'ELB Security Group',
220
- vpc_id: vpc_id,
223
+ vpc_id: vpc_id,
221
224
  }
222
225
 
223
226
  logger.info('Creating a Security Group for the ELB')
@@ -231,7 +234,7 @@ module VmShepherd
231
234
  end
232
235
 
233
236
  def delete_stack(stack_name)
234
- cfm = AWS::CloudFormation.new
237
+ cfm = AWS::CloudFormation.new
235
238
  stack = cfm.stacks[stack_name]
236
239
  logger.info('deleting CloudFormation stack')
237
240
  stack.delete
@@ -8,41 +8,41 @@ module VmShepherd
8
8
  def initialize(auth_url:, username:, api_key:, tenant:)
9
9
  @auth_url = auth_url
10
10
  @username = username
11
- @api_key = api_key
12
- @tenant = tenant
11
+ @api_key = api_key
12
+ @tenant = tenant
13
13
  end
14
14
 
15
15
  def deploy(raw_file_path, vm_options)
16
16
  say "Uploading the image #{raw_file_path}"
17
17
  image = image_service.images.create(
18
- name: vm_options[:name],
19
- size: File.size(raw_file_path),
20
- disk_format: 'raw',
18
+ name: vm_options[:name],
19
+ size: File.size(raw_file_path),
20
+ disk_format: 'raw',
21
21
  container_format: 'bare',
22
- location: raw_file_path,
22
+ location: raw_file_path,
23
23
  )
24
24
  say 'Finished uploading the image'
25
25
 
26
- flavor = find_flavor(vm_options[:flavor_name])
27
- network = network_service.networks.find { |net| net.name == vm_options[:network_name] }
26
+ flavor = find_flavor(vm_options[:flavor_name])
27
+ network = network_service.networks.find { |net| net.name == vm_options[:network_name] }
28
28
  security_groups = vm_options[:security_group_names]
29
29
 
30
30
  say('Launching an instance')
31
31
  server = service.servers.create(
32
- name: vm_options[:name],
33
- flavor_ref: flavor.id,
34
- image_ref: image.id,
35
- key_name: vm_options[:key_name],
32
+ name: vm_options[:name],
33
+ flavor_ref: flavor.id,
34
+ image_ref: image.id,
35
+ key_name: vm_options[:key_name],
36
36
  security_groups: security_groups,
37
- nics: [
38
- {net_id: network.id, v4_fixed_ip: vm_options[:private_ip]}
39
- ],
37
+ nics: [
38
+ {net_id: network.id, v4_fixed_ip: vm_options[:private_ip]}
39
+ ],
40
40
  )
41
41
  server.wait_for { ready? }
42
42
  say('Finished launching an instance')
43
43
 
44
44
  say('Assigning a Public IP to the instance')
45
- ip = service.addresses.find { |address| address.instance_id.nil? && address.ip == vm_options[:public_ip] }
45
+ ip = service.addresses.find { |address| address.instance_id.nil? && address.ip == vm_options[:public_ip] }
46
46
  ip.server = server
47
47
  say('Finished assigning a Public IP to the instance')
48
48
  end
@@ -114,42 +114,42 @@ module VmShepherd
114
114
 
115
115
  def service
116
116
  @service ||= Fog::Compute.new(
117
- provider: 'openstack',
117
+ provider: 'openstack',
118
118
  openstack_auth_url: auth_url,
119
119
  openstack_username: username,
120
- openstack_tenant: tenant,
121
- openstack_api_key: api_key,
120
+ openstack_tenant: tenant,
121
+ openstack_api_key: api_key,
122
122
  )
123
123
  end
124
124
 
125
125
  def image_service
126
126
  @image_service ||= Fog::Image.new(
127
- provider: 'openstack',
128
- openstack_auth_url: auth_url,
129
- openstack_username: username,
130
- openstack_tenant: tenant,
131
- openstack_api_key: api_key,
127
+ provider: 'openstack',
128
+ openstack_auth_url: auth_url,
129
+ openstack_username: username,
130
+ openstack_tenant: tenant,
131
+ openstack_api_key: api_key,
132
132
  openstack_endpoint_type: 'publicURL',
133
133
  )
134
134
  end
135
135
 
136
136
  def network_service
137
137
  @network_service ||= Fog::Network.new(
138
- provider: 'openstack',
138
+ provider: 'openstack',
139
139
  openstack_auth_url: auth_url,
140
140
  openstack_username: username,
141
- openstack_tenant: tenant,
142
- openstack_api_key: api_key,
141
+ openstack_tenant: tenant,
142
+ openstack_api_key: api_key,
143
143
  )
144
144
  end
145
145
 
146
146
  def storage_service
147
147
  @network_service ||= Fog::Storage.new(
148
- provider: 'openstack',
148
+ provider: 'openstack',
149
149
  openstack_auth_url: auth_url,
150
150
  openstack_username: username,
151
- openstack_tenant: tenant,
152
- openstack_api_key: api_key,
151
+ openstack_tenant: tenant,
152
+ openstack_api_key: api_key,
153
153
  )
154
154
  end
155
155
 
@@ -3,11 +3,11 @@ module VmShepherd
3
3
  class RetryLimitExceeded < StandardError
4
4
  end
5
5
 
6
- RETRY_LIMIT = 10
6
+ RETRY_LIMIT = 10
7
7
  RETRY_INTERVAL = 60
8
8
 
9
9
  def retry_until(retry_limit: RETRY_LIMIT, &block)
10
- tries = 0
10
+ tries = 0
11
11
  condition_reached = false
12
12
  loop do
13
13
  tries += 1
@@ -20,10 +20,10 @@ module VmShepherd
20
20
  when VmShepherd::VCLOUD_IAAS_TYPE then
21
21
  VmShepherd::VcloudManager.new(
22
22
  {
23
- url: vm_shepherd_config.creds.url,
23
+ url: vm_shepherd_config.creds.url,
24
24
  organization: vm_shepherd_config.creds.organization,
25
- user: vm_shepherd_config.creds.user,
26
- password: vm_shepherd_config.creds.password,
25
+ user: vm_shepherd_config.creds.user,
26
+ password: vm_shepherd_config.creds.password,
27
27
  },
28
28
  vm_shepherd_config.vdc.name,
29
29
  stdout_logger
@@ -41,18 +41,18 @@ module VmShepherd
41
41
  ).deploy(
42
42
  path,
43
43
  {
44
- ip: vm_shepherd_config.vm.ip,
45
- gateway: vm_shepherd_config.vm.gateway,
46
- netmask: vm_shepherd_config.vm.netmask,
47
- dns: vm_shepherd_config.vm.dns,
44
+ ip: vm_shepherd_config.vm.ip,
45
+ gateway: vm_shepherd_config.vm.gateway,
46
+ netmask: vm_shepherd_config.vm.netmask,
47
+ dns: vm_shepherd_config.vm.dns,
48
48
  ntp_servers: vm_shepherd_config.vm.ntp_servers,
49
49
  },
50
50
  {
51
- cluster: vm_shepherd_config.vsphere.cluster,
51
+ cluster: vm_shepherd_config.vsphere.cluster,
52
52
  resource_pool: vm_shepherd_config.vsphere.resource_pool,
53
- datastore: vm_shepherd_config.vsphere.datastore,
54
- network: vm_shepherd_config.vsphere.network,
55
- folder: vm_shepherd_config.vsphere.folder,
53
+ datastore: vm_shepherd_config.vsphere.datastore,
54
+ network: vm_shepherd_config.vsphere.network,
55
+ folder: vm_shepherd_config.vsphere.folder,
56
56
  }
57
57
  )
58
58
  when VmShepherd::AWS_IAAS_TYPE then
@@ -72,10 +72,10 @@ module VmShepherd
72
72
  vm_shepherd_configs(settings).each do |vm_shepherd_config|
73
73
  VmShepherd::VcloudManager.new(
74
74
  {
75
- url: vm_shepherd_config.creds.url,
75
+ url: vm_shepherd_config.creds.url,
76
76
  organization: vm_shepherd_config.creds.organization,
77
- user: vm_shepherd_config.creds.user,
78
- password: vm_shepherd_config.creds.password,
77
+ user: vm_shepherd_config.creds.user,
78
+ password: vm_shepherd_config.creds.password,
79
79
  },
80
80
  vm_shepherd_config.vdc.name,
81
81
  stdout_logger
@@ -109,10 +109,10 @@ module VmShepherd
109
109
  when VmShepherd::VCLOUD_IAAS_TYPE then
110
110
  VmShepherd::VcloudManager.new(
111
111
  {
112
- url: vm_shepherd_config.creds.url,
112
+ url: vm_shepherd_config.creds.url,
113
113
  organization: vm_shepherd_config.creds.organization,
114
- user: vm_shepherd_config.creds.user,
115
- password: vm_shepherd_config.creds.password,
114
+ user: vm_shepherd_config.creds.user,
115
+ password: vm_shepherd_config.creds.password,
116
116
  },
117
117
  vm_shepherd_config.vdc.name,
118
118
  stdout_logger
@@ -142,10 +142,10 @@ module VmShepherd
142
142
  vm_shepherd_configs(settings).each do |vm_shepherd_config|
143
143
  VmShepherd::VcloudManager.new(
144
144
  {
145
- url: vm_shepherd_config.creds.url,
145
+ url: vm_shepherd_config.creds.url,
146
146
  organization: vm_shepherd_config.creds.organization,
147
- user: vm_shepherd_config.creds.user,
148
- password: vm_shepherd_config.creds.password,
147
+ user: vm_shepherd_config.creds.user,
148
+ password: vm_shepherd_config.creds.password,
149
149
  },
150
150
  vm_shepherd_config.vdc.name,
151
151
  stdout_logger,
@@ -161,8 +161,8 @@ module VmShepherd
161
161
  stdout_logger,
162
162
  ).clean_environment(
163
163
  datacenter_folders_to_clean: vm_shepherd_config.cleanup.datacenter_folders_to_clean,
164
- datastores: vm_shepherd_config.cleanup.datastores,
165
- datastore_folders_to_clean: vm_shepherd_config.cleanup.datastore_folders_to_clean,
164
+ datastores: vm_shepherd_config.cleanup.datastores,
165
+ datastore_folders_to_clean: vm_shepherd_config.cleanup.datastore_folders_to_clean,
166
166
  )
167
167
  end
168
168
  when VmShepherd::AWS_IAAS_TYPE then
@@ -185,12 +185,12 @@ module VmShepherd
185
185
  def vcloud_deploy_options(vm_shepherd_config)
186
186
  vm = vm_shepherd_config.vapp
187
187
  VmShepherd::Vcloud::VappConfig.new(
188
- name: vm.ops_manager_name,
189
- ip: vm.ip,
188
+ name: vm.ops_manager_name,
189
+ ip: vm.ip,
190
190
  gateway: vm.gateway,
191
191
  netmask: vm.netmask,
192
- dns: vm.dns,
193
- ntp: vm.ntp,
192
+ dns: vm.dns,
193
+ ntp: vm.ntp,
194
194
  catalog: vm_shepherd_config.vdc.catalog,
195
195
  network: vm_shepherd_config.vdc.network,
196
196
  )
@@ -200,15 +200,15 @@ module VmShepherd
200
200
  @ami_manager ||=
201
201
  VmShepherd::AwsManager.new(
202
202
  env_config: {
203
- stack_name: settings.vm_shepherd.env_config.stack_name,
204
- aws_access_key: settings.vm_shepherd.env_config.aws_access_key,
205
- aws_secret_key: settings.vm_shepherd.env_config.aws_secret_key,
206
- region: settings.vm_shepherd.env_config.region,
207
- json_file: settings.vm_shepherd.env_config.json_file,
208
- parameters: settings.vm_shepherd.env_config.parameters_as_a_hash,
209
- outputs: settings.vm_shepherd.env_config.outputs.to_h,
210
- }.merge(ami_elb_config),
211
- logger: stdout_logger,
203
+ stack_name: settings.vm_shepherd.env_config.stack_name,
204
+ aws_access_key: settings.vm_shepherd.env_config.aws_access_key,
205
+ aws_secret_key: settings.vm_shepherd.env_config.aws_secret_key,
206
+ region: settings.vm_shepherd.env_config.region,
207
+ json_file: settings.vm_shepherd.env_config.json_file,
208
+ parameters: settings.vm_shepherd.env_config.parameters_as_a_hash,
209
+ outputs: settings.vm_shepherd.env_config.outputs.to_h,
210
+ }.merge(ami_elb_config),
211
+ logger: stdout_logger,
212
212
  )
213
213
  end
214
214
 
@@ -232,20 +232,20 @@ module VmShepherd
232
232
  OpenstackManager.new(
233
233
  auth_url: vm_shepherd_config.creds.auth_url,
234
234
  username: vm_shepherd_config.creds.username,
235
- api_key: vm_shepherd_config.creds.api_key,
236
- tenant: vm_shepherd_config.creds.tenant,
235
+ api_key: vm_shepherd_config.creds.api_key,
236
+ tenant: vm_shepherd_config.creds.tenant,
237
237
  )
238
238
  end
239
239
 
240
240
  def openstack_vm_options(vm_shepherd_config)
241
241
  {
242
- name: vm_shepherd_config.vm.name,
243
- flavor_name: vm_shepherd_config.vm.flavor_name,
244
- network_name: vm_shepherd_config.vm.network_name,
245
- key_name: vm_shepherd_config.vm.key_name,
242
+ name: vm_shepherd_config.vm.name,
243
+ flavor_name: vm_shepherd_config.vm.flavor_name,
244
+ network_name: vm_shepherd_config.vm.network_name,
245
+ key_name: vm_shepherd_config.vm.key_name,
246
246
  security_group_names: vm_shepherd_config.vm.security_group_names,
247
- public_ip: vm_shepherd_config.vm.public_ip,
248
- private_ip: vm_shepherd_config.vm.private_ip,
247
+ public_ip: vm_shepherd_config.vm.public_ip,
248
+ private_ip: vm_shepherd_config.vm.private_ip,
249
249
  }
250
250
  end
251
251
 
@@ -8,11 +8,11 @@ module VmShepherd
8
8
  catalog.upload_vapp_template(vdc_name, vapp_config.name, ovf_dir)
9
9
 
10
10
  # instantiate template
11
- network_config = VCloudSdk::NetworkConfig.new(vapp_config.network, 'Network 1')
12
- vapp = catalog.instantiate_vapp_template(vapp_config.name, vdc_name, vapp_config.name, nil, nil, network_config)
11
+ network_config = VCloudSdk::NetworkConfig.new(vapp_config.network, 'Network 1')
12
+ vapp = catalog.instantiate_vapp_template(vapp_config.name, vdc_name, vapp_config.name, nil, nil, network_config)
13
13
 
14
14
  # reconfigure vm
15
- vm = vapp.find_vm_by_name(vapp_config.name)
15
+ vm = vapp.find_vm_by_name(vapp_config.name)
16
16
  vm.product_section_properties = vapp_config.build_properties
17
17
 
18
18
  # power on vapp