vm_shepherd 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vm_shepherd/shepherd.rb +146 -125
- data/lib/vm_shepherd/version.rb +1 -1
- data/spec/fixtures/shepherd/aws.yml +10 -2
- data/spec/fixtures/shepherd/openstack.yml +19 -2
- data/spec/fixtures/shepherd/vcloud.yml +23 -2
- data/spec/fixtures/shepherd/vsphere.yml +29 -3
- data/spec/vm_shepherd/shepherd_spec.rb +344 -141
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0fc9f0b7a52ae491f167a0102a7a04f6b49f8ce
|
4
|
+
data.tar.gz: 7c602729eb8a957c869b4d995f1d072070497fef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae2def494be27f83ab4528e3cce896fa9fd10ea6df91dd3060d36523e62bb43331915b1e3e2bed3873e5a46c6af223617f86d97302c5caf7329d66b66f7758f1
|
7
|
+
data.tar.gz: cb19597cef1a5cfb96fb565eaf3d461eca74bf2ccdbaab8745a39b39aa3a330d9feee288353e936ffad3311fa8278547f51eca46689136ebf39606f94d45ba78
|
data/lib/vm_shepherd/shepherd.rb
CHANGED
@@ -7,112 +7,121 @@ module VmShepherd
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def deploy(path:)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
10
|
+
unless valid_iaas_types.include?(settings.iaas_type)
|
11
|
+
fail(InvalidIaas, "Unknown IaaS type: #{settings.iaas_type.inspect}")
|
12
|
+
end
|
13
|
+
vm_shepherd_configs(settings).each do |vm_shepherd_config|
|
14
|
+
case settings.iaas_type
|
15
|
+
when VmShepherd::VCLOUD_IAAS_TYPE then
|
16
|
+
VmShepherd::VcloudManager.new(
|
17
|
+
{
|
18
|
+
url: vm_shepherd_config.creds.url,
|
19
|
+
organization: vm_shepherd_config.creds.organization,
|
20
|
+
user: vm_shepherd_config.creds.user,
|
21
|
+
password: vm_shepherd_config.creds.password,
|
22
|
+
},
|
23
|
+
vm_shepherd_config.vdc.name,
|
24
|
+
error_logger
|
25
|
+
).deploy(
|
26
|
+
path,
|
27
|
+
vcloud_deploy_options(vm_shepherd_config),
|
28
|
+
)
|
29
|
+
when VmShepherd::VSPHERE_IAAS_TYPE then
|
30
|
+
VmShepherd::VsphereManager.new(
|
31
|
+
vm_shepherd_config.vcenter_creds.ip,
|
32
|
+
vm_shepherd_config.vcenter_creds.username,
|
33
|
+
vm_shepherd_config.vcenter_creds.password,
|
34
|
+
vm_shepherd_config.vsphere.datacenter,
|
35
|
+
).deploy(
|
36
|
+
path,
|
37
|
+
{
|
38
|
+
ip: vm_shepherd_config.vm.ip,
|
39
|
+
gateway: vm_shepherd_config.vm.gateway,
|
40
|
+
netmask: vm_shepherd_config.vm.netmask,
|
41
|
+
dns: vm_shepherd_config.vm.dns,
|
42
|
+
ntp_servers: vm_shepherd_config.vm.ntp_servers,
|
43
|
+
},
|
44
|
+
{
|
45
|
+
cluster: vm_shepherd_config.vsphere.cluster,
|
46
|
+
resource_pool: vm_shepherd_config.vsphere.resource_pool,
|
47
|
+
datastore: vm_shepherd_config.vsphere.datastore,
|
48
|
+
network: vm_shepherd_config.vsphere.network,
|
49
|
+
folder: vm_shepherd_config.vsphere.folder,
|
50
|
+
}
|
51
|
+
)
|
52
|
+
when VmShepherd::AWS_IAAS_TYPE then
|
53
|
+
ami_manager(vm_shepherd_config).deploy(path)
|
54
|
+
when VmShepherd::OPENSTACK_IAAS_TYPE then
|
55
|
+
openstack_vm_manager(vm_shepherd_config).deploy(path, openstack_vm_options(vm_shepherd_config))
|
56
|
+
end
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
60
|
def destroy
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
61
|
+
unless valid_iaas_types.include?(settings.iaas_type)
|
62
|
+
fail(InvalidIaas, "Unknown IaaS type: #{settings.iaas_type.inspect}")
|
63
|
+
end
|
64
|
+
vm_shepherd_configs(settings).each do |vm_shepherd_config|
|
65
|
+
case settings.iaas_type
|
66
|
+
when VmShepherd::VCLOUD_IAAS_TYPE then
|
67
|
+
VmShepherd::VcloudManager.new(
|
68
|
+
{
|
69
|
+
url: vm_shepherd_config.creds.url,
|
70
|
+
organization: vm_shepherd_config.creds.organization,
|
71
|
+
user: vm_shepherd_config.creds.user,
|
72
|
+
password: vm_shepherd_config.creds.password,
|
73
|
+
},
|
74
|
+
vm_shepherd_config.vdc.name,
|
75
|
+
error_logger
|
76
|
+
).destroy([vm_shepherd_config.vapp.ops_manager_name], vm_shepherd_config.vdc.catalog)
|
77
|
+
when VmShepherd::VSPHERE_IAAS_TYPE then
|
78
|
+
VmShepherd::VsphereManager.new(
|
79
|
+
vm_shepherd_config.vcenter_creds.ip,
|
80
|
+
vm_shepherd_config.vcenter_creds.username,
|
81
|
+
vm_shepherd_config.vcenter_creds.password,
|
82
|
+
vm_shepherd_config.vsphere.datacenter,
|
83
|
+
).destroy(vm_shepherd_config.vm.ip, vm_shepherd_config.vsphere.resource_pool)
|
84
|
+
when VmShepherd::AWS_IAAS_TYPE then
|
85
|
+
ami_manager(vm_shepherd_config).destroy
|
86
|
+
when VmShepherd::OPENSTACK_IAAS_TYPE then
|
87
|
+
openstack_vm_manager(vm_shepherd_config).destroy(openstack_vm_options(vm_shepherd_config))
|
88
|
+
end
|
83
89
|
end
|
84
90
|
end
|
85
91
|
|
86
92
|
def clean_environment
|
87
|
-
|
88
|
-
|
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
|
-
|
93
|
+
unless valid_iaas_types.include?(settings.iaas_type)
|
94
|
+
fail(InvalidIaas, "Unknown IaaS type: #{settings.iaas_type.inspect}")
|
95
|
+
end
|
96
|
+
vm_shepherd_configs(settings).each do |vm_shepherd_config|
|
97
|
+
case settings.iaas_type
|
98
|
+
when VmShepherd::VCLOUD_IAAS_TYPE then
|
99
|
+
VmShepherd::VcloudManager.new(
|
100
|
+
{
|
101
|
+
url: vm_shepherd_config.creds.url,
|
102
|
+
organization: vm_shepherd_config.creds.organization,
|
103
|
+
user: vm_shepherd_config.creds.user,
|
104
|
+
password: vm_shepherd_config.creds.password,
|
105
|
+
},
|
106
|
+
vm_shepherd_config.vdc.name,
|
107
|
+
error_logger,
|
108
|
+
).clean_environment(vm_shepherd_config.vapp.product_names, vm_shepherd_config.vapp.product_catalog)
|
109
|
+
when VmShepherd::VSPHERE_IAAS_TYPE then
|
110
|
+
VmShepherd::VsphereManager.new(
|
111
|
+
vm_shepherd_config.vcenter_creds.ip,
|
112
|
+
vm_shepherd_config.vcenter_creds.username,
|
113
|
+
vm_shepherd_config.vcenter_creds.password,
|
114
|
+
vm_shepherd_config.cleanup.datacenter,
|
115
|
+
).clean_environment(
|
116
|
+
datacenter_folders_to_clean: vm_shepherd_config.cleanup.datacenter_folders_to_clean,
|
117
|
+
datastores: vm_shepherd_config.cleanup.datastores,
|
118
|
+
datastore_folders_to_clean: vm_shepherd_config.cleanup.datastore_folders_to_clean,
|
119
|
+
)
|
120
|
+
when VmShepherd::AWS_IAAS_TYPE then
|
121
|
+
ami_manager(vm_shepherd_config).clean_environment
|
122
|
+
when VmShepherd::OPENSTACK_IAAS_TYPE then
|
123
|
+
openstack_vm_manager(vm_shepherd_config).clean_environment
|
124
|
+
end
|
116
125
|
end
|
117
126
|
end
|
118
127
|
|
@@ -126,8 +135,8 @@ module VmShepherd
|
|
126
135
|
end
|
127
136
|
end
|
128
137
|
|
129
|
-
def vcloud_deploy_options
|
130
|
-
vm =
|
138
|
+
def vcloud_deploy_options(vm_shepherd_config)
|
139
|
+
vm = vm_shepherd_config.vapp
|
131
140
|
{
|
132
141
|
name: vm.ops_manager_name,
|
133
142
|
ip: vm.ip,
|
@@ -135,44 +144,56 @@ module VmShepherd
|
|
135
144
|
netmask: vm.netmask,
|
136
145
|
dns: vm.dns,
|
137
146
|
ntp: vm.ntp,
|
138
|
-
catalog:
|
139
|
-
network:
|
147
|
+
catalog: vm_shepherd_config.vdc.catalog,
|
148
|
+
network: vm_shepherd_config.vdc.network,
|
140
149
|
}
|
141
150
|
end
|
142
151
|
|
143
|
-
def ami_manager
|
144
|
-
vm_shepherd = settings.vm_shepherd
|
152
|
+
def ami_manager(vm_shepherd_config)
|
145
153
|
VmShepherd::AwsManager.new(
|
146
|
-
aws_access_key:
|
147
|
-
aws_secret_key:
|
148
|
-
ssh_key_name:
|
149
|
-
security_group_id:
|
150
|
-
public_subnet_id:
|
151
|
-
private_subnet_id:
|
152
|
-
elastic_ip_id:
|
153
|
-
vm_name:
|
154
|
+
aws_access_key: vm_shepherd_config.aws_access_key,
|
155
|
+
aws_secret_key: vm_shepherd_config.aws_secret_key,
|
156
|
+
ssh_key_name: vm_shepherd_config.ssh_key_name,
|
157
|
+
security_group_id: vm_shepherd_config.security_group,
|
158
|
+
public_subnet_id: vm_shepherd_config.public_subnet_id,
|
159
|
+
private_subnet_id: vm_shepherd_config.private_subnet_id,
|
160
|
+
elastic_ip_id: vm_shepherd_config.elastic_ip_id,
|
161
|
+
vm_name: vm_shepherd_config.vm_name,
|
154
162
|
)
|
155
163
|
end
|
156
164
|
|
157
|
-
def openstack_vm_manager
|
165
|
+
def openstack_vm_manager(vm_shepherd_config)
|
158
166
|
OpenstackManager.new(
|
159
|
-
auth_url:
|
160
|
-
username:
|
161
|
-
api_key:
|
162
|
-
tenant:
|
167
|
+
auth_url: vm_shepherd_config.creds.auth_url,
|
168
|
+
username: vm_shepherd_config.creds.username,
|
169
|
+
api_key: vm_shepherd_config.creds.api_key,
|
170
|
+
tenant: vm_shepherd_config.creds.tenant,
|
163
171
|
)
|
164
172
|
end
|
165
173
|
|
166
|
-
def openstack_vm_options
|
174
|
+
def openstack_vm_options(vm_shepherd_config)
|
167
175
|
{
|
168
|
-
name:
|
169
|
-
min_disk_size:
|
170
|
-
network_name:
|
171
|
-
key_name:
|
172
|
-
security_group_names:
|
173
|
-
public_ip:
|
174
|
-
private_ip:
|
176
|
+
name: vm_shepherd_config.vm.name,
|
177
|
+
min_disk_size: vm_shepherd_config.vm.flavor_parameters.min_disk_size,
|
178
|
+
network_name: vm_shepherd_config.vm.network_name,
|
179
|
+
key_name: vm_shepherd_config.vm.key_name,
|
180
|
+
security_group_names: vm_shepherd_config.vm.security_group_names,
|
181
|
+
public_ip: vm_shepherd_config.vm.public_ip,
|
182
|
+
private_ip: vm_shepherd_config.vm.private_ip,
|
175
183
|
}
|
176
184
|
end
|
185
|
+
|
186
|
+
def vm_shepherd_configs(settings)
|
187
|
+
settings.vm_shepherd_configs || []
|
188
|
+
end
|
189
|
+
|
190
|
+
def valid_iaas_types
|
191
|
+
[
|
192
|
+
VmShepherd::VCLOUD_IAAS_TYPE,
|
193
|
+
VmShepherd::VSPHERE_IAAS_TYPE,
|
194
|
+
VmShepherd::AWS_IAAS_TYPE,
|
195
|
+
VmShepherd::OPENSTACK_IAAS_TYPE
|
196
|
+
]
|
197
|
+
end
|
177
198
|
end
|
178
199
|
end
|
data/lib/vm_shepherd/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
iaas_type: aws
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
vm_shepherd_configs:
|
4
|
+
- aws_access_key: aws-access-key
|
5
5
|
aws_secret_key: aws-secret-key
|
6
6
|
ssh_key_name: ssh-key-name
|
7
7
|
security_group: security-group-id
|
@@ -9,3 +9,11 @@ vm_shepherd:
|
|
9
9
|
private_subnet_id: private-subnet-id
|
10
10
|
elastic_ip_id: elastic-ip-id
|
11
11
|
vm_name: vm-name
|
12
|
+
- aws_access_key: aws-access-key-2
|
13
|
+
aws_secret_key: aws-secret-key-2
|
14
|
+
ssh_key_name: ssh-key-name-2
|
15
|
+
security_group: security-group-id-2
|
16
|
+
public_subnet_id: public-subnet-id-2
|
17
|
+
private_subnet_id: private-subnet-id-2
|
18
|
+
elastic_ip_id: elastic-ip-id-2
|
19
|
+
vm_name: vm-name-2
|
@@ -1,6 +1,6 @@
|
|
1
1
|
iaas_type: openstack
|
2
|
-
|
3
|
-
|
2
|
+
vm_shepherd_configs:
|
3
|
+
- creds:
|
4
4
|
auth_url: 'http://example.com/version/tokens'
|
5
5
|
username: 'username'
|
6
6
|
api_key: 'api-key'
|
@@ -17,3 +17,20 @@ vm_shepherd:
|
|
17
17
|
- 'security-group-C'
|
18
18
|
public_ip: 198.11.195.5
|
19
19
|
private_ip: 192.168.100.100
|
20
|
+
- creds:
|
21
|
+
auth_url: 'http://example.com/version/tokens-2'
|
22
|
+
username: 'username-2'
|
23
|
+
api_key: 'api-key-2'
|
24
|
+
tenant: 'tenant-2'
|
25
|
+
vm:
|
26
|
+
name: 'some-vm-name-2'
|
27
|
+
flavor_parameters:
|
28
|
+
min_disk_size: 152
|
29
|
+
network_name: 'some-network-2'
|
30
|
+
key_name: 'some-key-2'
|
31
|
+
security_group_names:
|
32
|
+
- 'security-group-A-2'
|
33
|
+
- 'security-group-B-2'
|
34
|
+
- 'security-group-C-2'
|
35
|
+
public_ip: 198.11.195.5-2
|
36
|
+
private_ip: 192.168.100.100-2
|
@@ -1,6 +1,6 @@
|
|
1
1
|
iaas_type: vcloud
|
2
|
-
|
3
|
-
|
2
|
+
vm_shepherd_configs:
|
3
|
+
- creds:
|
4
4
|
url: VAPP_URL
|
5
5
|
organization: VAPP_ORGANIZATION
|
6
6
|
user: VAPP_USERNAME
|
@@ -21,3 +21,24 @@ vm_shepherd:
|
|
21
21
|
netmask: VAPP_NETMASK
|
22
22
|
dns: VAPP_DNS
|
23
23
|
ntp: VAPP_NTP
|
24
|
+
- creds:
|
25
|
+
url: VAPP_URL-2
|
26
|
+
organization: VAPP_ORGANIZATION-2
|
27
|
+
user: VAPP_USERNAME-2
|
28
|
+
password: VAPP_PASSWORD-2
|
29
|
+
vdc:
|
30
|
+
name: VDC_NAME-2
|
31
|
+
catalog: VDC_CATALOG-2
|
32
|
+
network: VDC_NETWORK-2
|
33
|
+
vapp:
|
34
|
+
ops_manager_name: VAPP_NAME-2
|
35
|
+
product_catalog: PRODUCT_CATALOG-2
|
36
|
+
product_names:
|
37
|
+
- PRODUCT_1-2
|
38
|
+
- PRODUCT_2-2
|
39
|
+
ip: VAPP_IP-2
|
40
|
+
public_ip:
|
41
|
+
gateway: VAPP_GATEWAY-2
|
42
|
+
netmask: VAPP_NETMASK-2
|
43
|
+
dns: VAPP_DNS-2
|
44
|
+
ntp: VAPP_NTP-2
|
@@ -1,11 +1,10 @@
|
|
1
1
|
iaas_type: vsphere
|
2
|
-
|
3
|
-
|
2
|
+
vm_shepherd_configs:
|
3
|
+
- vcenter_creds:
|
4
4
|
ip: OVA_URL
|
5
5
|
username: OVA_ORGANIZATION
|
6
6
|
password: OVA_PASSWORD
|
7
7
|
vsphere:
|
8
|
-
host:
|
9
8
|
datacenter: VSPHERE_DATACENTER
|
10
9
|
cluster: VSPHERE_CLUSTER
|
11
10
|
network: VSPHERE_NETWORK
|
@@ -28,3 +27,30 @@ vm_shepherd:
|
|
28
27
|
- DC_FOLDER_TWO
|
29
28
|
datastore_folders_to_clean:
|
30
29
|
- DS_DISK_FOLDER
|
30
|
+
- vcenter_creds:
|
31
|
+
ip: OVA_URL-2
|
32
|
+
username: OVA_ORGANIZATION-2
|
33
|
+
password: OVA_PASSWORD-2
|
34
|
+
vsphere:
|
35
|
+
datacenter: VSPHERE_DATACENTER-2
|
36
|
+
cluster: VSPHERE_CLUSTER-2
|
37
|
+
network: VSPHERE_NETWORK-2
|
38
|
+
resource_pool: VSPHERE_RESOURCE_POOL-2
|
39
|
+
datastore: VSPHERE_DATASTORE-2
|
40
|
+
folder: VSPHERE_FOLDER-2
|
41
|
+
vm:
|
42
|
+
ip: OVA_IP-2
|
43
|
+
gateway: OVA_GATEWAY-2
|
44
|
+
netmask: OVA_NETMASK-2
|
45
|
+
dns: OVA_DNS-2
|
46
|
+
ntp_servers: OVA_NTP-2
|
47
|
+
cleanup:
|
48
|
+
datacenter: VSPHERE_OTHER_DATACENTER-2
|
49
|
+
datastores:
|
50
|
+
- VSPHERE_DATASTORE_ONE-2
|
51
|
+
- VSPHERE_DATASTORE_TWO-2
|
52
|
+
datacenter_folders_to_clean:
|
53
|
+
- DC_FOLDER_ONE-2
|
54
|
+
- DC_FOLDER_TWO-2
|
55
|
+
datastore_folders_to_clean:
|
56
|
+
- DS_DISK_FOLDER-2
|
@@ -4,38 +4,68 @@ require 'recursive_open_struct'
|
|
4
4
|
module VmShepherd
|
5
5
|
RSpec.describe Shepherd do
|
6
6
|
subject(:manager) { Shepherd.new(settings: settings) }
|
7
|
+
let(:first_config) { settings.vm_shepherd_configs.first }
|
8
|
+
let(:last_config) { settings.vm_shepherd_configs.last }
|
9
|
+
let(:settings) do
|
10
|
+
RecursiveOpenStruct.new(YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', settings_fixture_name)), recurse_over_arrays: true)
|
11
|
+
end
|
7
12
|
|
8
13
|
describe '#deploy' do
|
9
14
|
context 'with vcloud settings' do
|
10
|
-
let(:
|
11
|
-
|
12
|
-
|
13
|
-
let(:vcloud_manager) { instance_double(VcloudManager) }
|
15
|
+
let(:settings_fixture_name) { 'vcloud.yml' }
|
16
|
+
let(:first_vcloud_manager) { instance_double(VcloudManager) }
|
17
|
+
let(:last_vcloud_manager) { instance_double(VcloudManager) }
|
14
18
|
|
15
19
|
it 'uses VcloudManager to launch a vm' do
|
16
20
|
expect(VcloudManager).to receive(:new).
|
17
21
|
with(
|
18
22
|
{
|
19
|
-
url:
|
20
|
-
organization:
|
21
|
-
user:
|
22
|
-
password:
|
23
|
+
url: first_config.creds.url,
|
24
|
+
organization: first_config.creds.organization,
|
25
|
+
user: first_config.creds.user,
|
26
|
+
password: first_config.creds.password,
|
27
|
+
},
|
28
|
+
first_config.vdc.name,
|
29
|
+
instance_of(Logger)
|
30
|
+
).and_return(first_vcloud_manager)
|
31
|
+
|
32
|
+
expect(VcloudManager).to receive(:new).
|
33
|
+
with(
|
34
|
+
{
|
35
|
+
url: last_config.creds.url,
|
36
|
+
organization: last_config.creds.organization,
|
37
|
+
user: last_config.creds.user,
|
38
|
+
password: last_config.creds.password,
|
23
39
|
},
|
24
|
-
|
40
|
+
last_config.vdc.name,
|
25
41
|
instance_of(Logger)
|
26
|
-
).and_return(
|
42
|
+
).and_return(last_vcloud_manager)
|
27
43
|
|
28
|
-
expect(
|
44
|
+
expect(first_vcloud_manager).to receive(:deploy).with(
|
29
45
|
'FAKE_PATH',
|
30
46
|
{
|
31
|
-
name:
|
32
|
-
ip:
|
33
|
-
gateway:
|
34
|
-
netmask:
|
35
|
-
dns:
|
36
|
-
ntp:
|
37
|
-
catalog:
|
38
|
-
network:
|
47
|
+
name: first_config.vapp.ops_manager_name,
|
48
|
+
ip: first_config.vapp.ip,
|
49
|
+
gateway: first_config.vapp.gateway,
|
50
|
+
netmask: first_config.vapp.netmask,
|
51
|
+
dns: first_config.vapp.dns,
|
52
|
+
ntp: first_config.vapp.ntp,
|
53
|
+
catalog: first_config.vdc.catalog,
|
54
|
+
network: first_config.vdc.network,
|
55
|
+
}
|
56
|
+
)
|
57
|
+
|
58
|
+
expect(last_vcloud_manager).to receive(:deploy).with(
|
59
|
+
'FAKE_PATH',
|
60
|
+
{
|
61
|
+
name: last_config.vapp.ops_manager_name,
|
62
|
+
ip: last_config.vapp.ip,
|
63
|
+
gateway: last_config.vapp.gateway,
|
64
|
+
netmask: last_config.vapp.netmask,
|
65
|
+
dns: last_config.vapp.dns,
|
66
|
+
ntp: last_config.vapp.ntp,
|
67
|
+
catalog: last_config.vdc.catalog,
|
68
|
+
network: last_config.vdc.network,
|
39
69
|
}
|
40
70
|
)
|
41
71
|
|
@@ -44,34 +74,59 @@ module VmShepherd
|
|
44
74
|
end
|
45
75
|
|
46
76
|
context 'with vsphere settings' do
|
47
|
-
let(:
|
48
|
-
|
49
|
-
|
50
|
-
let(:ova_manager) { instance_double(VsphereManager) }
|
77
|
+
let(:settings_fixture_name) { 'vsphere.yml' }
|
78
|
+
let(:first_ova_manager) { instance_double(VsphereManager) }
|
79
|
+
let(:last_ova_manager) { instance_double(VsphereManager) }
|
51
80
|
|
52
81
|
it 'uses VsphereManager to launch a vm' do
|
53
82
|
expect(VsphereManager).to receive(:new).with(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
).and_return(
|
83
|
+
first_config.vcenter_creds.ip,
|
84
|
+
first_config.vcenter_creds.username,
|
85
|
+
first_config.vcenter_creds.password,
|
86
|
+
first_config.vsphere.datacenter,
|
87
|
+
).and_return(first_ova_manager)
|
88
|
+
|
89
|
+
|
90
|
+
expect(VsphereManager).to receive(:new).with(
|
91
|
+
last_config.vcenter_creds.ip,
|
92
|
+
last_config.vcenter_creds.username,
|
93
|
+
last_config.vcenter_creds.password,
|
94
|
+
last_config.vsphere.datacenter,
|
95
|
+
).and_return(last_ova_manager)
|
96
|
+
|
97
|
+
expect(first_ova_manager).to receive(:deploy).with(
|
98
|
+
'FAKE_PATH',
|
99
|
+
{
|
100
|
+
ip: first_config.vm.ip,
|
101
|
+
gateway: first_config.vm.gateway,
|
102
|
+
netmask: first_config.vm.netmask,
|
103
|
+
dns: first_config.vm.dns,
|
104
|
+
ntp_servers: first_config.vm.ntp_servers,
|
105
|
+
},
|
106
|
+
{
|
107
|
+
cluster: first_config.vsphere.cluster,
|
108
|
+
resource_pool: first_config.vsphere.resource_pool,
|
109
|
+
datastore: first_config.vsphere.datastore,
|
110
|
+
network: first_config.vsphere.network,
|
111
|
+
folder: first_config.vsphere.folder,
|
112
|
+
},
|
113
|
+
)
|
59
114
|
|
60
|
-
expect(
|
115
|
+
expect(last_ova_manager).to receive(:deploy).with(
|
61
116
|
'FAKE_PATH',
|
62
117
|
{
|
63
|
-
ip:
|
64
|
-
gateway:
|
65
|
-
netmask:
|
66
|
-
dns:
|
67
|
-
ntp_servers:
|
118
|
+
ip: last_config.vm.ip,
|
119
|
+
gateway: last_config.vm.gateway,
|
120
|
+
netmask: last_config.vm.netmask,
|
121
|
+
dns: last_config.vm.dns,
|
122
|
+
ntp_servers: last_config.vm.ntp_servers,
|
68
123
|
},
|
69
124
|
{
|
70
|
-
cluster:
|
71
|
-
resource_pool:
|
72
|
-
datastore:
|
73
|
-
network:
|
74
|
-
folder:
|
125
|
+
cluster: last_config.vsphere.cluster,
|
126
|
+
resource_pool: last_config.vsphere.resource_pool,
|
127
|
+
datastore: last_config.vsphere.datastore,
|
128
|
+
network: last_config.vsphere.network,
|
129
|
+
folder: last_config.vsphere.folder,
|
75
130
|
},
|
76
131
|
)
|
77
132
|
|
@@ -80,12 +135,11 @@ module VmShepherd
|
|
80
135
|
end
|
81
136
|
|
82
137
|
context 'with AWS settings' do
|
83
|
-
let(:
|
84
|
-
|
85
|
-
|
86
|
-
let(:ams_manager) { instance_double(AwsManager) }
|
138
|
+
let(:settings_fixture_name) { 'aws.yml' }
|
139
|
+
let(:first_ams_manager) { instance_double(AwsManager) }
|
140
|
+
let(:last_ams_manager) { instance_double(AwsManager) }
|
87
141
|
let(:ami_file_path) { 'PATH_TO_AMI_FILE' }
|
88
|
-
let(:
|
142
|
+
let(:first_aws_options) do
|
89
143
|
{
|
90
144
|
aws_access_key: 'aws-access-key',
|
91
145
|
aws_secret_key: 'aws-secret-key',
|
@@ -97,21 +151,36 @@ module VmShepherd
|
|
97
151
|
vm_name: 'vm-name'
|
98
152
|
}
|
99
153
|
end
|
154
|
+
let(:last_aws_options) do
|
155
|
+
{
|
156
|
+
aws_access_key: 'aws-access-key-2',
|
157
|
+
aws_secret_key: 'aws-secret-key-2',
|
158
|
+
ssh_key_name: 'ssh-key-name-2',
|
159
|
+
security_group_id: 'security-group-id-2',
|
160
|
+
public_subnet_id: 'public-subnet-id-2',
|
161
|
+
private_subnet_id: 'private-subnet-id-2',
|
162
|
+
elastic_ip_id: 'elastic-ip-id-2',
|
163
|
+
vm_name: 'vm-name-2'
|
164
|
+
}
|
165
|
+
end
|
100
166
|
|
101
167
|
it 'uses AwsManager to launch a VM' do
|
102
|
-
expect(AwsManager).to receive(:new).with(
|
103
|
-
expect(
|
168
|
+
expect(AwsManager).to receive(:new).with(first_aws_options).and_return(first_ams_manager)
|
169
|
+
expect(first_ams_manager).to receive(:deploy).with(ami_file_path)
|
170
|
+
|
171
|
+
expect(AwsManager).to receive(:new).with(last_aws_options).and_return(last_ams_manager)
|
172
|
+
expect(last_ams_manager).to receive(:deploy).with(ami_file_path)
|
173
|
+
|
104
174
|
manager.deploy(path: ami_file_path)
|
105
175
|
end
|
106
176
|
end
|
107
177
|
|
108
178
|
context 'with OpenStack settings' do
|
109
|
-
let(:
|
110
|
-
RecursiveOpenStruct.new(YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', 'openstack.yml')))
|
111
|
-
end
|
112
|
-
let(:qcow2_manager) { instance_double(OpenstackManager) }
|
179
|
+
let(:settings_fixture_name) { 'openstack.yml' }
|
113
180
|
let(:qcow2_file_path) { 'PATH_TO_QCOW2_FILE' }
|
114
|
-
let(:
|
181
|
+
let(:first_qcow2_manager) { instance_double(OpenstackManager) }
|
182
|
+
let(:last_qcow2_manager) { instance_double(OpenstackManager) }
|
183
|
+
let(:first_openstack_options) do
|
115
184
|
{
|
116
185
|
auth_url: 'http://example.com/version/tokens',
|
117
186
|
username: 'username',
|
@@ -119,7 +188,15 @@ module VmShepherd
|
|
119
188
|
tenant: 'tenant',
|
120
189
|
}
|
121
190
|
end
|
122
|
-
let(:
|
191
|
+
let(:last_openstack_options) do
|
192
|
+
{
|
193
|
+
auth_url: 'http://example.com/version/tokens-2',
|
194
|
+
username: 'username-2',
|
195
|
+
api_key: 'api-key-2',
|
196
|
+
tenant: 'tenant-2',
|
197
|
+
}
|
198
|
+
end
|
199
|
+
let(:first_openstack_vm_options) do
|
123
200
|
{
|
124
201
|
name: 'some-vm-name',
|
125
202
|
min_disk_size: 150,
|
@@ -134,18 +211,35 @@ module VmShepherd
|
|
134
211
|
private_ip: '192.168.100.100',
|
135
212
|
}
|
136
213
|
end
|
214
|
+
let(:last_openstack_vm_options) do
|
215
|
+
{
|
216
|
+
name: 'some-vm-name-2',
|
217
|
+
min_disk_size: 152,
|
218
|
+
network_name: 'some-network-2',
|
219
|
+
key_name: 'some-key-2',
|
220
|
+
security_group_names: [
|
221
|
+
'security-group-A-2',
|
222
|
+
'security-group-B-2',
|
223
|
+
'security-group-C-2',
|
224
|
+
],
|
225
|
+
public_ip: '198.11.195.5-2',
|
226
|
+
private_ip: '192.168.100.100-2',
|
227
|
+
}
|
228
|
+
end
|
137
229
|
|
138
230
|
it 'uses OpenstackManager to launch a VM' do
|
139
|
-
expect(OpenstackManager).to receive(:new).with(
|
140
|
-
expect(
|
231
|
+
expect(OpenstackManager).to receive(:new).with(first_openstack_options).and_return(first_qcow2_manager)
|
232
|
+
expect(first_qcow2_manager).to receive(:deploy).with(qcow2_file_path, first_openstack_vm_options)
|
233
|
+
|
234
|
+
expect(OpenstackManager).to receive(:new).with(last_openstack_options).and_return(last_qcow2_manager)
|
235
|
+
expect(last_qcow2_manager).to receive(:deploy).with(qcow2_file_path, last_openstack_vm_options)
|
236
|
+
|
141
237
|
manager.deploy(path: qcow2_file_path)
|
142
238
|
end
|
143
239
|
end
|
144
240
|
|
145
241
|
context 'when IAAS is unknown' do
|
146
|
-
let(:
|
147
|
-
RecursiveOpenStruct.new(YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', 'unknown.yml')))
|
148
|
-
end
|
242
|
+
let(:settings_fixture_name) { 'unknown.yml' }
|
149
243
|
|
150
244
|
it 'raises an exception' do
|
151
245
|
expect { manager.deploy(path: 'FAKE_PATH') }.to raise_error(Shepherd::InvalidIaas)
|
@@ -155,26 +249,41 @@ module VmShepherd
|
|
155
249
|
|
156
250
|
describe '#destroy' do
|
157
251
|
context 'when IAAS is vcloud' do
|
158
|
-
let(:
|
159
|
-
|
160
|
-
|
161
|
-
let(:vcloud_manager) { instance_double(VcloudManager) }
|
252
|
+
let(:settings_fixture_name) { 'vcloud.yml' }
|
253
|
+
let(:first_vcloud_manager) { instance_double(VcloudManager) }
|
254
|
+
let(:last_vcloud_manager) { instance_double(VcloudManager) }
|
162
255
|
|
163
256
|
it 'uses VcloudManager to destroy a vm' do
|
164
257
|
expect(VcloudManager).to receive(:new).with(
|
165
258
|
{
|
166
|
-
url:
|
167
|
-
organization:
|
168
|
-
user:
|
169
|
-
password:
|
259
|
+
url: first_config.creds.url,
|
260
|
+
organization: first_config.creds.organization,
|
261
|
+
user: first_config.creds.user,
|
262
|
+
password: first_config.creds.password,
|
170
263
|
},
|
171
|
-
|
264
|
+
first_config.vdc.name,
|
172
265
|
instance_of(Logger)
|
173
|
-
).and_return(
|
266
|
+
).and_return(first_vcloud_manager)
|
174
267
|
|
175
|
-
expect(
|
176
|
-
[
|
177
|
-
|
268
|
+
expect(first_vcloud_manager).to receive(:destroy).with(
|
269
|
+
[first_config.vapp.ops_manager_name],
|
270
|
+
first_config.vdc.catalog,
|
271
|
+
)
|
272
|
+
|
273
|
+
expect(VcloudManager).to receive(:new).with(
|
274
|
+
{
|
275
|
+
url: last_config.creds.url,
|
276
|
+
organization: last_config.creds.organization,
|
277
|
+
user: last_config.creds.user,
|
278
|
+
password: last_config.creds.password,
|
279
|
+
},
|
280
|
+
last_config.vdc.name,
|
281
|
+
instance_of(Logger)
|
282
|
+
).and_return(last_vcloud_manager)
|
283
|
+
|
284
|
+
expect(last_vcloud_manager).to receive(:destroy).with(
|
285
|
+
[last_config.vapp.ops_manager_name],
|
286
|
+
last_config.vdc.catalog,
|
178
287
|
)
|
179
288
|
|
180
289
|
manager.destroy
|
@@ -182,30 +291,35 @@ module VmShepherd
|
|
182
291
|
end
|
183
292
|
|
184
293
|
context 'when IAAS is vsphere' do
|
185
|
-
let(:
|
186
|
-
|
187
|
-
|
188
|
-
let(:ova_manager) { instance_double(VsphereManager) }
|
294
|
+
let(:settings_fixture_name) { 'vsphere.yml' }
|
295
|
+
let(:first_ova_manager) { instance_double(VsphereManager) }
|
296
|
+
let(:last_ova_manager) { instance_double(VsphereManager) }
|
189
297
|
|
190
298
|
it 'uses VsphereManager to destroy a vm' do
|
191
299
|
expect(VsphereManager).to receive(:new).with(
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
).and_return(
|
197
|
-
expect(
|
300
|
+
first_config.vcenter_creds.ip,
|
301
|
+
first_config.vcenter_creds.username,
|
302
|
+
first_config.vcenter_creds.password,
|
303
|
+
first_config.vsphere.datacenter,
|
304
|
+
).and_return(first_ova_manager)
|
305
|
+
expect(first_ova_manager).to receive(:destroy).with(first_config.vm.ip, first_config.vsphere.resource_pool)
|
306
|
+
|
307
|
+
expect(VsphereManager).to receive(:new).with(
|
308
|
+
last_config.vcenter_creds.ip,
|
309
|
+
last_config.vcenter_creds.username,
|
310
|
+
last_config.vcenter_creds.password,
|
311
|
+
last_config.vsphere.datacenter,
|
312
|
+
).and_return(last_ova_manager)
|
313
|
+
expect(last_ova_manager).to receive(:destroy).with(last_config.vm.ip, last_config.vsphere.resource_pool)
|
198
314
|
|
199
315
|
manager.destroy
|
200
316
|
end
|
201
317
|
end
|
202
318
|
|
203
319
|
context 'when IAAS is AWS' do
|
204
|
-
let(:
|
205
|
-
|
206
|
-
|
207
|
-
let(:ams_manager) { instance_double(AwsManager) }
|
208
|
-
let(:ami_options) do
|
320
|
+
let(:settings_fixture_name) { 'aws.yml' }
|
321
|
+
let(:first_ams_manager) { instance_double(AwsManager) }
|
322
|
+
let(:first_ami_options) do
|
209
323
|
{
|
210
324
|
aws_access_key: 'aws-access-key',
|
211
325
|
aws_secret_key: 'aws-secret-key',
|
@@ -217,21 +331,37 @@ module VmShepherd
|
|
217
331
|
vm_name: 'vm-name'
|
218
332
|
}
|
219
333
|
end
|
334
|
+
let(:last_ams_manager) { instance_double(AwsManager) }
|
335
|
+
let(:last_ami_options) do
|
336
|
+
{
|
337
|
+
aws_access_key: 'aws-access-key-2',
|
338
|
+
aws_secret_key: 'aws-secret-key-2',
|
339
|
+
ssh_key_name: 'ssh-key-name-2',
|
340
|
+
security_group_id: 'security-group-id-2',
|
341
|
+
public_subnet_id: 'public-subnet-id-2',
|
342
|
+
private_subnet_id: 'private-subnet-id-2',
|
343
|
+
elastic_ip_id: 'elastic-ip-id-2',
|
344
|
+
vm_name: 'vm-name-2'
|
345
|
+
}
|
346
|
+
end
|
220
347
|
|
221
348
|
it 'uses AwsManager to destroy a VM' do
|
222
|
-
expect(AwsManager).to receive(:new).with(
|
223
|
-
expect(
|
349
|
+
expect(AwsManager).to receive(:new).with(first_ami_options).and_return(first_ams_manager)
|
350
|
+
expect(first_ams_manager).to receive(:destroy)
|
351
|
+
|
352
|
+
expect(AwsManager).to receive(:new).with(last_ami_options).and_return(last_ams_manager)
|
353
|
+
expect(last_ams_manager).to receive(:destroy)
|
354
|
+
|
224
355
|
manager.destroy
|
225
356
|
end
|
226
357
|
end
|
227
358
|
|
228
359
|
context 'when IAAS is Openstack' do
|
229
|
-
let(:
|
230
|
-
RecursiveOpenStruct.new(YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', 'openstack.yml')))
|
231
|
-
end
|
232
|
-
let(:qcow2_manager) { instance_double(OpenstackManager) }
|
360
|
+
let(:settings_fixture_name) { 'openstack.yml' }
|
233
361
|
let(:qcow2_file_path) { 'PATH_TO_QCOW2_FILE' }
|
234
|
-
let(:
|
362
|
+
let(:first_qcow2_manager) { instance_double(OpenstackManager) }
|
363
|
+
let(:last_qcow2_manager) { instance_double(OpenstackManager) }
|
364
|
+
let(:first_openstack_options) do
|
235
365
|
{
|
236
366
|
auth_url: 'http://example.com/version/tokens',
|
237
367
|
username: 'username',
|
@@ -239,7 +369,7 @@ module VmShepherd
|
|
239
369
|
tenant: 'tenant',
|
240
370
|
}
|
241
371
|
end
|
242
|
-
let(:
|
372
|
+
let(:first_openstack_vm_options) do
|
243
373
|
{
|
244
374
|
name: 'some-vm-name',
|
245
375
|
min_disk_size: 150,
|
@@ -254,18 +384,43 @@ module VmShepherd
|
|
254
384
|
private_ip: '192.168.100.100',
|
255
385
|
}
|
256
386
|
end
|
387
|
+
let(:last_openstack_options) do
|
388
|
+
{
|
389
|
+
auth_url: 'http://example.com/version/tokens-2',
|
390
|
+
username: 'username-2',
|
391
|
+
api_key: 'api-key-2',
|
392
|
+
tenant: 'tenant-2',
|
393
|
+
}
|
394
|
+
end
|
395
|
+
let(:last_openstack_vm_options) do
|
396
|
+
{
|
397
|
+
name: 'some-vm-name-2',
|
398
|
+
min_disk_size: 152,
|
399
|
+
network_name: 'some-network-2',
|
400
|
+
key_name: 'some-key-2',
|
401
|
+
security_group_names: [
|
402
|
+
'security-group-A-2',
|
403
|
+
'security-group-B-2',
|
404
|
+
'security-group-C-2',
|
405
|
+
],
|
406
|
+
public_ip: '198.11.195.5-2',
|
407
|
+
private_ip: '192.168.100.100-2',
|
408
|
+
}
|
409
|
+
end
|
257
410
|
|
258
411
|
it 'uses OpenstackManager to destroy a VM' do
|
259
|
-
expect(OpenstackManager).to receive(:new).with(
|
260
|
-
expect(
|
412
|
+
expect(OpenstackManager).to receive(:new).with(first_openstack_options).and_return(first_qcow2_manager)
|
413
|
+
expect(first_qcow2_manager).to receive(:destroy).with(first_openstack_vm_options)
|
414
|
+
|
415
|
+
expect(OpenstackManager).to receive(:new).with(last_openstack_options).and_return(last_qcow2_manager)
|
416
|
+
expect(last_qcow2_manager).to receive(:destroy).with(last_openstack_vm_options)
|
417
|
+
|
261
418
|
manager.destroy
|
262
419
|
end
|
263
420
|
end
|
264
421
|
|
265
422
|
context 'when IAAS is unknown' do
|
266
|
-
let(:
|
267
|
-
RecursiveOpenStruct.new(YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', 'unknown.yml')))
|
268
|
-
end
|
423
|
+
let(:settings_fixture_name) { 'unknown.yml' }
|
269
424
|
|
270
425
|
it 'raises an exception' do
|
271
426
|
expect { manager.destroy }.to raise_error(Shepherd::InvalidIaas)
|
@@ -275,26 +430,41 @@ module VmShepherd
|
|
275
430
|
|
276
431
|
describe '#clean_environment' do
|
277
432
|
context 'when IAAS is vcloud' do
|
278
|
-
let(:
|
279
|
-
|
280
|
-
|
281
|
-
let(:vcloud_manager) { instance_double(VcloudManager) }
|
433
|
+
let(:settings_fixture_name) { 'vcloud.yml' }
|
434
|
+
let(:first_vcloud_manager) { instance_double(VcloudManager) }
|
435
|
+
let(:last_vcloud_manager) { instance_double(VcloudManager) }
|
282
436
|
|
283
437
|
it 'uses VcloudManager to destroy a vm' do
|
284
438
|
expect(VcloudManager).to receive(:new).with(
|
285
439
|
{
|
286
|
-
url:
|
287
|
-
organization:
|
288
|
-
user:
|
289
|
-
password:
|
440
|
+
url: first_config.creds.url,
|
441
|
+
organization: first_config.creds.organization,
|
442
|
+
user: first_config.creds.user,
|
443
|
+
password: first_config.creds.password,
|
290
444
|
},
|
291
|
-
|
445
|
+
first_config.vdc.name,
|
292
446
|
instance_of(Logger)
|
293
|
-
).and_return(
|
447
|
+
).and_return(first_vcloud_manager)
|
294
448
|
|
295
|
-
expect(
|
296
|
-
|
297
|
-
|
449
|
+
expect(first_vcloud_manager).to receive(:clean_environment).with(
|
450
|
+
first_config.vapp.product_names,
|
451
|
+
first_config.vapp.product_catalog,
|
452
|
+
)
|
453
|
+
|
454
|
+
expect(VcloudManager).to receive(:new).with(
|
455
|
+
{
|
456
|
+
url: last_config.creds.url,
|
457
|
+
organization: last_config.creds.organization,
|
458
|
+
user: last_config.creds.user,
|
459
|
+
password: last_config.creds.password,
|
460
|
+
},
|
461
|
+
last_config.vdc.name,
|
462
|
+
instance_of(Logger)
|
463
|
+
).and_return(last_vcloud_manager)
|
464
|
+
|
465
|
+
expect(last_vcloud_manager).to receive(:clean_environment).with(
|
466
|
+
last_config.vapp.product_names,
|
467
|
+
last_config.vapp.product_catalog,
|
298
468
|
)
|
299
469
|
|
300
470
|
manager.clean_environment
|
@@ -302,37 +472,48 @@ module VmShepherd
|
|
302
472
|
end
|
303
473
|
|
304
474
|
context 'when IAAS is vsphere' do
|
305
|
-
let(:
|
306
|
-
|
475
|
+
let(:settings_fixture_name) { 'vsphere.yml' }
|
476
|
+
let(:first_ova_manager) { instance_double(VsphereManager) }
|
477
|
+
let(:first_clean_environment_options) do
|
478
|
+
{
|
479
|
+
datacenter_folders_to_clean: first_config.cleanup.datacenter_folders_to_clean,
|
480
|
+
datastores: first_config.cleanup.datastores,
|
481
|
+
datastore_folders_to_clean: first_config.cleanup.datastore_folders_to_clean,
|
482
|
+
}
|
307
483
|
end
|
308
|
-
let(:
|
309
|
-
let(:
|
484
|
+
let(:last_ova_manager) { instance_double(VsphereManager) }
|
485
|
+
let(:last_clean_environment_options) do
|
310
486
|
{
|
311
|
-
datacenter_folders_to_clean:
|
312
|
-
datastores:
|
313
|
-
datastore_folders_to_clean:
|
487
|
+
datacenter_folders_to_clean: last_config.cleanup.datacenter_folders_to_clean,
|
488
|
+
datastores: last_config.cleanup.datastores,
|
489
|
+
datastore_folders_to_clean: last_config.cleanup.datastore_folders_to_clean,
|
314
490
|
}
|
315
491
|
end
|
316
492
|
|
317
493
|
it 'uses VsphereManager to destroy a vm' do
|
318
494
|
expect(VsphereManager).to receive(:new).with(
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
).and_return(
|
324
|
-
expect(
|
495
|
+
first_config.vcenter_creds.ip,
|
496
|
+
first_config.vcenter_creds.username,
|
497
|
+
first_config.vcenter_creds.password,
|
498
|
+
first_config.cleanup.datacenter,
|
499
|
+
).and_return(first_ova_manager)
|
500
|
+
expect(first_ova_manager).to receive(:clean_environment).with(first_clean_environment_options)
|
501
|
+
expect(VsphereManager).to receive(:new).with(
|
502
|
+
last_config.vcenter_creds.ip,
|
503
|
+
last_config.vcenter_creds.username,
|
504
|
+
last_config.vcenter_creds.password,
|
505
|
+
last_config.cleanup.datacenter,
|
506
|
+
).and_return(last_ova_manager)
|
507
|
+
expect(last_ova_manager).to receive(:clean_environment).with(last_clean_environment_options)
|
325
508
|
|
326
509
|
manager.clean_environment
|
327
510
|
end
|
328
511
|
end
|
329
512
|
|
330
513
|
context 'when IAAS is AWS' do
|
331
|
-
let(:
|
332
|
-
|
333
|
-
|
334
|
-
let(:ams_manager) { instance_double(AwsManager) }
|
335
|
-
let(:ami_options) do
|
514
|
+
let(:settings_fixture_name) { 'aws.yml' }
|
515
|
+
let(:first_ams_manager) { instance_double(AwsManager) }
|
516
|
+
let(:first_ami_options) do
|
336
517
|
{
|
337
518
|
aws_access_key: 'aws-access-key',
|
338
519
|
aws_secret_key: 'aws-secret-key',
|
@@ -344,21 +525,34 @@ module VmShepherd
|
|
344
525
|
vm_name: 'vm-name'
|
345
526
|
}
|
346
527
|
end
|
528
|
+
let(:last_ams_manager) { instance_double(AwsManager) }
|
529
|
+
let(:last_ami_options) do
|
530
|
+
{
|
531
|
+
aws_access_key: 'aws-access-key-2',
|
532
|
+
aws_secret_key: 'aws-secret-key-2',
|
533
|
+
ssh_key_name: 'ssh-key-name-2',
|
534
|
+
security_group_id: 'security-group-id-2',
|
535
|
+
public_subnet_id: 'public-subnet-id-2',
|
536
|
+
private_subnet_id: 'private-subnet-id-2',
|
537
|
+
elastic_ip_id: 'elastic-ip-id-2',
|
538
|
+
vm_name: 'vm-name-2'
|
539
|
+
}
|
540
|
+
end
|
347
541
|
|
348
542
|
it 'uses AwsManager to destroy a VM' do
|
349
|
-
expect(AwsManager).to receive(:new).with(
|
350
|
-
expect(
|
543
|
+
expect(AwsManager).to receive(:new).with(first_ami_options).and_return(first_ams_manager)
|
544
|
+
expect(first_ams_manager).to receive(:clean_environment)
|
545
|
+
expect(AwsManager).to receive(:new).with(last_ami_options).and_return(last_ams_manager)
|
546
|
+
expect(last_ams_manager).to receive(:clean_environment)
|
351
547
|
manager.clean_environment
|
352
548
|
end
|
353
549
|
end
|
354
550
|
|
355
551
|
context 'when IAAS is Openstack' do
|
356
|
-
let(:
|
357
|
-
RecursiveOpenStruct.new(YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', 'openstack.yml')))
|
358
|
-
end
|
359
|
-
let(:qcow2_manager) { instance_double(OpenstackManager) }
|
552
|
+
let(:settings_fixture_name) { 'openstack.yml' }
|
360
553
|
let(:qcow2_file_path) { 'PATH_TO_QCOW2_FILE' }
|
361
|
-
let(:
|
554
|
+
let(:first_qcow2_manager) { instance_double(OpenstackManager) }
|
555
|
+
let(:first_openstack_options) do
|
362
556
|
{
|
363
557
|
auth_url: 'http://example.com/version/tokens',
|
364
558
|
username: 'username',
|
@@ -366,18 +560,27 @@ module VmShepherd
|
|
366
560
|
tenant: 'tenant',
|
367
561
|
}
|
368
562
|
end
|
563
|
+
let(:last_qcow2_manager) { instance_double(OpenstackManager) }
|
564
|
+
let(:last_openstack_options) do
|
565
|
+
{
|
566
|
+
auth_url: 'http://example.com/version/tokens-2',
|
567
|
+
username: 'username-2',
|
568
|
+
api_key: 'api-key-2',
|
569
|
+
tenant: 'tenant-2',
|
570
|
+
}
|
571
|
+
end
|
369
572
|
|
370
573
|
it 'uses OpenstackManager to destroy a VM' do
|
371
|
-
expect(OpenstackManager).to receive(:new).with(
|
372
|
-
expect(
|
574
|
+
expect(OpenstackManager).to receive(:new).with(first_openstack_options).and_return(first_qcow2_manager)
|
575
|
+
expect(first_qcow2_manager).to receive(:clean_environment)
|
576
|
+
expect(OpenstackManager).to receive(:new).with(last_openstack_options).and_return(last_qcow2_manager)
|
577
|
+
expect(last_qcow2_manager).to receive(:clean_environment)
|
373
578
|
manager.clean_environment
|
374
579
|
end
|
375
580
|
end
|
376
581
|
|
377
582
|
context 'when IAAS is unknown' do
|
378
|
-
let(:
|
379
|
-
RecursiveOpenStruct.new(YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', 'unknown.yml')))
|
380
|
-
end
|
583
|
+
let(:settings_fixture_name) { 'unknown.yml' }
|
381
584
|
|
382
585
|
it 'raises an exception' do
|
383
586
|
expect { manager.clean_environment }.to raise_error(Shepherd::InvalidIaas)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vm_shepherd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ops Manager Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-v1
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.4.
|
194
|
+
rubygems_version: 2.4.5
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: A tool for booting and tearing down Ops Manager VMs on various Infrastructures.
|