fog-azure-rm 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fog/azurerm/docs/compute.md +9 -3
- data/lib/fog/azurerm/models/compute/server.rb +49 -28
- data/lib/fog/azurerm/models/compute/servers.rb +16 -6
- data/lib/fog/azurerm/requests/compute/attach_data_disk_to_vm.rb +12 -4
- data/lib/fog/azurerm/requests/compute/check_vm_exists.rb +13 -5
- data/lib/fog/azurerm/requests/compute/check_vm_status.rb +1 -1
- data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +42 -34
- data/lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/requests/compute/detach_data_disk_from_vm.rb +12 -4
- data/lib/fog/azurerm/requests/compute/generalize_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/requests/compute/get_virtual_machine.rb +8 -4
- data/lib/fog/azurerm/requests/compute/list_available_sizes_for_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/requests/compute/power_off_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/requests/compute/redeploy_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/requests/compute/restart_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/requests/compute/start_virtual_machine.rb +12 -4
- data/lib/fog/azurerm/version.rb +1 -1
- data/test/models/compute/test_server.rb +51 -1
- data/test/requests/compute/test_deallocate_virtual_machine.rb +11 -2
- data/test/requests/compute/test_delete_virtual_machine.rb +11 -2
- data/test/requests/compute/test_generalize_virtual_machine.rb +11 -2
- data/test/requests/compute/test_list_available_sizes_for_virtual_machine.rb +11 -2
- data/test/requests/compute/test_power_off_virtual_machine.rb +11 -2
- data/test/requests/compute/test_redeploy_virtual_machine.rb +12 -2
- data/test/requests/compute/test_restart_virtual_machine.rb +11 -2
- data/test/requests/compute/test_start_virtual_machine.rb +11 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33c1b3dbf863e197bc2a541c66577f56bc7e4aac
|
4
|
+
data.tar.gz: 3a7d2a9906695e7be641e1d641bbb7f1bf89c798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a37083a43154de9aae645b01e329b44856cc2ac5b74b6baf972937d996980d1b2e32b3752a0be8e1b0130827fff01533c4e1166642af2d6615f8704ac23af547
|
7
|
+
data.tar.gz: d5d45fd735a93a8c0e6c93f10cd613d6c59c247e97e688ac66f9278352a84e2ba2b3bf56a3b567c7ac6dd18e4bc0dd58318e189cd8c74a39b1be7daed414dae5
|
@@ -38,6 +38,9 @@ Create a new linux server
|
|
38
38
|
**Info:**
|
39
39
|
Attribute **network_interface_card_ids** is an array of NICs ids. The NIC id at index zero will become primary NIC of this server(virtual machine) by default.
|
40
40
|
|
41
|
+
**Info:**
|
42
|
+
When using **managed_disk_storage_type** you should not pass the **vhd_path** as the managed disk will be used for the OS disk. Also, data disks cannot be attached to a VM which uses managed disks for the OS disk.
|
43
|
+
|
41
44
|
```ruby
|
42
45
|
azure_compute_service.servers.create(
|
43
46
|
name: '<VM Name>',
|
@@ -56,7 +59,8 @@ Attribute **network_interface_card_ids** is an array of NICs ids. The NIC id at
|
|
56
59
|
platform: 'Linux',
|
57
60
|
vhd_path: '<Path of VHD>', # Optional, if you want to create the VM from a custom image.
|
58
61
|
custom_data: 'echo customData', # Optional, if you want to add custom data in this VM.
|
59
|
-
os_disk_caching: Fog::ARM::Compute::Models::CachingTypes::None # Optional, can be one of None, ReadOnly, ReadWrite
|
62
|
+
os_disk_caching: Fog::ARM::Compute::Models::CachingTypes::None, # Optional, can be one of None, ReadOnly, ReadWrite
|
63
|
+
managed_disk_storage_type: Azure::ARM::Compute::Models::StorageAccountTypes::StandardLRS # Optional, can be StandardLRS or PremiumLRS
|
60
64
|
)
|
61
65
|
```
|
62
66
|
|
@@ -79,7 +83,8 @@ Create a new windows server
|
|
79
83
|
version: 'latest', # Not required if custom image is being used
|
80
84
|
platform: 'Windows',
|
81
85
|
vhd_path: '<Path of VHD>', # Optional, if you want to create the VM from a custom image.
|
82
|
-
custom_data: 'echo customData' # Optional, if you want to add custom data in this VM.
|
86
|
+
custom_data: 'echo customData', # Optional, if you want to add custom data in this VM.
|
87
|
+
managed_disk_storage_type: Azure::ARM::Compute::Models::StorageAccountTypes::StandardLRS # Optional, can be StandardLRS or PremiumLRS
|
83
88
|
)
|
84
89
|
```
|
85
90
|
|
@@ -105,7 +110,8 @@ Create a new linux server asynchronously
|
|
105
110
|
platform: 'Linux',
|
106
111
|
vhd_path: '<Path of VHD>', # Optional, if you want to create the VM from a custom image.
|
107
112
|
custom_data: 'echo customData', # Optional, if you want to add custom data in this VM.
|
108
|
-
os_disk_caching: Fog::ARM::Compute::Models::CachingTypes::None # Optional, can be one of None, ReadOnly, ReadWrite
|
113
|
+
os_disk_caching: Fog::ARM::Compute::Models::CachingTypes::None, # Optional, can be one of None, ReadOnly, ReadWrite
|
114
|
+
managed_disk_storage_type: Azure::ARM::Compute::Models::StorageAccountTypes::StandardLRS # Optional, can be StandardLRS or PremiumLRS
|
109
115
|
)
|
110
116
|
```
|
111
117
|
Following methods are available to handle async respoonse:
|
@@ -30,6 +30,7 @@ module Fog
|
|
30
30
|
attribute :availability_set_id
|
31
31
|
attribute :custom_data
|
32
32
|
attribute :vhd_path
|
33
|
+
attribute :managed_disk_storage_type
|
33
34
|
|
34
35
|
def self.parse(vm)
|
35
36
|
hash = {}
|
@@ -40,8 +41,14 @@ module Fog
|
|
40
41
|
hash['vm_size'] = vm.hardware_profile.vm_size unless vm.hardware_profile.vm_size.nil?
|
41
42
|
unless vm.storage_profile.nil?
|
42
43
|
hash['os_disk_name'] = vm.storage_profile.os_disk.name
|
43
|
-
|
44
|
-
|
44
|
+
|
45
|
+
if vm.storage_profile.os_disk.vhd.nil?
|
46
|
+
hash['managed_disk_storage_type'] = vm.storage_profile.os_disk.managed_disk.storage_account_type
|
47
|
+
else
|
48
|
+
hash['os_disk_vhd_uri'] = vm.storage_profile.os_disk.vhd.uri
|
49
|
+
hash['storage_account_name'] = hash['os_disk_vhd_uri'].split('/')[2].split('.')[0]
|
50
|
+
end
|
51
|
+
|
45
52
|
hash['os_disk_caching'] = vm.storage_profile.os_disk.caching
|
46
53
|
unless vm.storage_profile.image_reference.nil?
|
47
54
|
hash['publisher'] = vm.storage_profile.image_reference.publisher
|
@@ -76,7 +83,7 @@ module Fog
|
|
76
83
|
def save(async = false)
|
77
84
|
requires :name, :location, :resource_group, :vm_size, :storage_account_name,
|
78
85
|
:username, :network_interface_card_ids
|
79
|
-
requires :publisher, :offer, :sku, :version if vhd_path.nil?
|
86
|
+
requires :publisher, :offer, :sku, :version if vhd_path.nil? && managed_disk_storage_type.nil?
|
80
87
|
|
81
88
|
if platform_is_linux?(platform)
|
82
89
|
requires :disable_password_authentication
|
@@ -94,50 +101,58 @@ module Fog
|
|
94
101
|
end
|
95
102
|
end
|
96
103
|
|
97
|
-
def destroy
|
98
|
-
service.delete_virtual_machine(resource_group, name)
|
104
|
+
def destroy(async = false)
|
105
|
+
response = service.delete_virtual_machine(resource_group, name, async)
|
106
|
+
async ? create_fog_async_response(response) : response
|
99
107
|
end
|
100
108
|
|
101
|
-
def generalize
|
102
|
-
service.generalize_virtual_machine(resource_group, name)
|
109
|
+
def generalize(async = false)
|
110
|
+
response = service.generalize_virtual_machine(resource_group, name, async)
|
111
|
+
async ? create_fog_async_response(response) : response
|
103
112
|
end
|
104
113
|
|
105
|
-
def power_off
|
106
|
-
service.power_off_virtual_machine(resource_group, name)
|
114
|
+
def power_off(async = false)
|
115
|
+
response = service.power_off_virtual_machine(resource_group, name, async)
|
116
|
+
async ? create_fog_async_response(response) : response
|
107
117
|
end
|
108
118
|
|
109
|
-
def start
|
110
|
-
service.start_virtual_machine(resource_group, name)
|
119
|
+
def start(async = false)
|
120
|
+
response = service.start_virtual_machine(resource_group, name, async)
|
121
|
+
async ? create_fog_async_response(response) : response
|
111
122
|
end
|
112
123
|
|
113
|
-
def restart
|
114
|
-
service.restart_virtual_machine(resource_group, name)
|
124
|
+
def restart(async = false)
|
125
|
+
response = service.restart_virtual_machine(resource_group, name, async)
|
126
|
+
async ? create_fog_async_response(response) : response
|
115
127
|
end
|
116
128
|
|
117
|
-
def deallocate
|
118
|
-
service.deallocate_virtual_machine(resource_group, name)
|
129
|
+
def deallocate(async = false)
|
130
|
+
response = service.deallocate_virtual_machine(resource_group, name, async)
|
131
|
+
async ? create_fog_async_response(response) : response
|
119
132
|
end
|
120
133
|
|
121
|
-
def redeploy
|
122
|
-
service.redeploy_virtual_machine(resource_group, name)
|
134
|
+
def redeploy(async = false)
|
135
|
+
response = service.redeploy_virtual_machine(resource_group, name, async)
|
136
|
+
async ? create_fog_async_response(response) : response
|
123
137
|
end
|
124
138
|
|
125
|
-
def list_available_sizes
|
126
|
-
service.list_available_sizes_for_virtual_machine(resource_group, name)
|
139
|
+
def list_available_sizes(async = false)
|
140
|
+
response = service.list_available_sizes_for_virtual_machine(resource_group, name, async)
|
141
|
+
async ? create_fog_async_response(response) : response
|
127
142
|
end
|
128
143
|
|
129
|
-
def vm_status
|
130
|
-
service.check_vm_status(resource_group, name)
|
144
|
+
def vm_status(async = false)
|
145
|
+
service.check_vm_status(resource_group, name, async)
|
131
146
|
end
|
132
147
|
|
133
|
-
def attach_data_disk(disk_name, disk_size, storage_account_name)
|
134
|
-
|
135
|
-
merge_attributes(Fog::Compute::AzureRM::Server.parse(
|
148
|
+
def attach_data_disk(disk_name, disk_size, storage_account_name, async = false)
|
149
|
+
response = service.attach_data_disk_to_vm(resource_group, name, disk_name, disk_size, storage_account_name, async)
|
150
|
+
async ? create_fog_async_response(response) : merge_attributes(Fog::Compute::AzureRM::Server.parse(response))
|
136
151
|
end
|
137
152
|
|
138
|
-
def detach_data_disk(disk_name)
|
139
|
-
|
140
|
-
merge_attributes(Fog::Compute::AzureRM::Server.parse(
|
153
|
+
def detach_data_disk(disk_name, async = false)
|
154
|
+
response = service.detach_data_disk_from_vm(resource_group, name, disk_name, async)
|
155
|
+
async ? create_fog_async_response(response) : merge_attributes(Fog::Compute::AzureRM::Server.parse(response))
|
141
156
|
end
|
142
157
|
|
143
158
|
private
|
@@ -146,6 +161,11 @@ module Fog
|
|
146
161
|
platform.strip.casecmp(PLATFORM_LINUX).zero?
|
147
162
|
end
|
148
163
|
|
164
|
+
def create_fog_async_response(response)
|
165
|
+
server = Fog::Compute::AzureRM::Server.new(service: service)
|
166
|
+
Fog::AzureRM::AsyncResponse.new(server, response)
|
167
|
+
end
|
168
|
+
|
149
169
|
def virtual_machine_params(ssh_key_path)
|
150
170
|
{
|
151
171
|
resource_group: resource_group,
|
@@ -169,7 +189,8 @@ module Fog
|
|
169
189
|
enable_automatic_updates: enable_automatic_updates,
|
170
190
|
custom_data: custom_data,
|
171
191
|
vhd_path: vhd_path,
|
172
|
-
os_disk_caching: os_disk_caching
|
192
|
+
os_disk_caching: os_disk_caching,
|
193
|
+
managed_disk_storage_type: managed_disk_storage_type
|
173
194
|
}
|
174
195
|
end
|
175
196
|
end
|
@@ -22,14 +22,24 @@ module Fog
|
|
22
22
|
Fog::AzureRM::AsyncResponse.new(server, async_response)
|
23
23
|
end
|
24
24
|
|
25
|
-
def get(resource_group_name, virtual_machine_name)
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def get(resource_group_name, virtual_machine_name, async = false)
|
26
|
+
response = service.get_virtual_machine(resource_group_name, virtual_machine_name, async)
|
27
|
+
virtual_machine = Fog::Compute::AzureRM::Server.new(service: service)
|
28
|
+
if async
|
29
|
+
Fog::AzureRM::AsyncResponse.new(virtual_machine, response)
|
30
|
+
else
|
31
|
+
virtual_machine.merge_attributes(Fog::Compute::AzureRM::Server.parse(response))
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
|
-
def check_vm_exists(resource_group, name)
|
32
|
-
service.check_vm_exists(resource_group, name)
|
35
|
+
def check_vm_exists(resource_group, name, async = false)
|
36
|
+
response = service.check_vm_exists(resource_group, name, async)
|
37
|
+
if async
|
38
|
+
server = Fog::Compute::AzureRM::Server.new(service: service)
|
39
|
+
Fog::AzureRM::AsyncResponse.new(server, response)
|
40
|
+
else
|
41
|
+
response
|
42
|
+
end
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
@@ -3,7 +3,7 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def attach_data_disk_to_vm(resource_group, vm_name, disk_name, disk_size, storage_account_name)
|
6
|
+
def attach_data_disk_to_vm(resource_group, vm_name, disk_name, disk_size, storage_account_name, async)
|
7
7
|
msg = "Attaching Data Disk #{disk_name} to Virtual Machine #{vm_name} in Resource Group #{resource_group}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
vm = get_virtual_machine_instance(resource_group, vm_name, @compute_mgmt_client)
|
@@ -13,7 +13,11 @@ module Fog
|
|
13
13
|
vm.storage_profile.data_disks.push(data_disk)
|
14
14
|
vm.resources = nil
|
15
15
|
begin
|
16
|
-
|
16
|
+
if async
|
17
|
+
response = @compute_mgmt_client.virtual_machines.create_or_update_async(resource_group, vm_name, vm)
|
18
|
+
else
|
19
|
+
virtual_machine = @compute_mgmt_client.virtual_machines.create_or_update(resource_group, vm_name, vm)
|
20
|
+
end
|
17
21
|
rescue MsRestAzure::AzureOperationError => e
|
18
22
|
if e.body.to_s =~ /InvalidParameter/ && e.body.to_s =~ /already exists/
|
19
23
|
Fog::Logger.debug 'The disk is already attached'
|
@@ -21,8 +25,12 @@ module Fog
|
|
21
25
|
raise_azure_exception(e, msg)
|
22
26
|
end
|
23
27
|
end
|
24
|
-
|
25
|
-
|
28
|
+
if async
|
29
|
+
response
|
30
|
+
else
|
31
|
+
Fog::Logger.debug "Data Disk #{disk_name} attached to Virtual Machine #{vm_name} successfully."
|
32
|
+
virtual_machine
|
33
|
+
end
|
26
34
|
end
|
27
35
|
|
28
36
|
private
|
@@ -3,21 +3,29 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def check_vm_exists(resource_group, name)
|
6
|
+
def check_vm_exists(resource_group, name, async)
|
7
7
|
msg = "Checking Virtual Machine #{name}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.get_async(resource_group, name, 'instanceView')
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.get(resource_group, name, 'instanceView')
|
14
|
+
end
|
13
15
|
rescue MsRestAzure::AzureOperationError => e
|
14
16
|
if e.body['error']['code'] == 'ResourceNotFound'
|
15
17
|
Fog::Logger.debug "Virtual machine #{name} doesn't exist."
|
16
|
-
false
|
18
|
+
return false
|
17
19
|
else
|
18
20
|
raise_azure_exception(e, msg)
|
19
21
|
end
|
20
22
|
end
|
23
|
+
if async
|
24
|
+
response
|
25
|
+
else
|
26
|
+
Fog::Logger.debug "Virtual machine #{name} exists."
|
27
|
+
true
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
# This class provides the mock implementation for unit tests.
|
@@ -3,7 +3,7 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def check_vm_status(resource_group, name)
|
6
|
+
def check_vm_status(resource_group, name, async)
|
7
7
|
msg = "Checking Virtual Machine #{name} status"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
@@ -30,7 +30,8 @@ module Fog
|
|
30
30
|
vm_hash[:vhd_path],
|
31
31
|
vm_hash[:os_disk_caching],
|
32
32
|
vm_hash[:platform],
|
33
|
-
vm_hash[:resource_group]
|
33
|
+
vm_hash[:resource_group],
|
34
|
+
vm_hash[:managed_disk_storage_type])
|
34
35
|
|
35
36
|
virtual_machine.os_profile = if vm_hash[:platform].casecmp(WINDOWS).zero?
|
36
37
|
define_windows_os_profile(vm_hash[:name],
|
@@ -80,48 +81,55 @@ module Fog
|
|
80
81
|
image_reference
|
81
82
|
end
|
82
83
|
|
83
|
-
def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version, vhd_path, os_disk_caching, platform, resource_group)
|
84
|
+
def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version, vhd_path, os_disk_caching, platform, resource_group, managed_disk_storage_type)
|
84
85
|
storage_profile = Azure::ARM::Compute::Models::StorageProfile.new
|
86
|
+
storage_profile.image_reference = image_reference(publisher, offer, sku, version)
|
85
87
|
os_disk = Azure::ARM::Compute::Models::OSDisk.new
|
86
|
-
vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
|
87
88
|
|
88
|
-
|
89
|
+
if managed_disk_storage_type.nil?
|
90
|
+
vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
|
91
|
+
vhd.uri = get_blob_endpoint(storage_account_name) + "/vhds/#{vm_name}_os_disk.vhd"
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
key: container_name
|
104
|
-
)
|
93
|
+
unless vhd_path.nil?
|
94
|
+
# Copy if VHD does not exist belongs to same storage account.
|
95
|
+
vhd_storage_account = (vhd_path.split('/')[2]).split('.')[0]
|
96
|
+
if storage_account_name != vhd_storage_account
|
97
|
+
storage_account = @storage_service.storage_accounts.get(resource_group, storage_account_name)
|
98
|
+
access_key = storage_account.get_access_keys.first.value
|
99
|
+
storage_data = Fog::Storage::AzureRM.new(provider: 'AzureRM', azure_storage_account_name: storage_account_name, azure_storage_access_key: access_key)
|
100
|
+
new_time = current_time
|
101
|
+
container_name = "customvhd#{new_time}"
|
102
|
+
blob_name = "vhd_image#{new_time}.vhd"
|
103
|
+
storage_data.directories.create(
|
104
|
+
key: container_name
|
105
|
+
)
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
storage_data.copy_blob_from_uri(container_name, blob_name, vhd_path)
|
108
|
+
until storage_data.get_blob_properties(container_name, blob_name).properties[:copy_status] == 'success'
|
109
|
+
Fog::Logger.debug 'Waiting disk to ready'
|
110
|
+
sleep(10)
|
111
|
+
end
|
112
|
+
new_vhd_path = get_blob_endpoint(storage_account_name) + "/#{container_name}/#{blob_name}"
|
113
|
+
Fog::Logger.debug "Path:#{new_vhd_path}. | Copy done"
|
114
|
+
else
|
115
|
+
new_vhd_path = vhd_path
|
110
116
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
117
|
+
|
118
|
+
img_vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
|
119
|
+
img_vhd.uri = new_vhd_path
|
120
|
+
os_disk.image = img_vhd
|
115
121
|
end
|
116
122
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
123
|
+
os_disk.vhd = vhd
|
124
|
+
else
|
125
|
+
managed_disk = Azure::ARM::Compute::Models::ManagedDiskParameters.new
|
126
|
+
managed_disk.storage_account_type = managed_disk_storage_type
|
127
|
+
os_disk.managed_disk = managed_disk
|
121
128
|
end
|
122
|
-
|
129
|
+
|
123
130
|
os_disk.name = "#{vm_name}_os_disk"
|
124
|
-
os_disk.
|
131
|
+
os_disk.os_type = platform
|
132
|
+
|
125
133
|
os_disk.create_option = Azure::ARM::Compute::Models::DiskCreateOptionTypes::FromImage
|
126
134
|
os_disk.caching = unless os_disk_caching.nil?
|
127
135
|
case os_disk_caching
|
@@ -133,7 +141,7 @@ module Fog
|
|
133
141
|
Azure::ARM::Compute::Models::CachingTypes::ReadWrite
|
134
142
|
end
|
135
143
|
end
|
136
|
-
|
144
|
+
|
137
145
|
storage_profile.os_disk = os_disk
|
138
146
|
storage_profile
|
139
147
|
end
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def deallocate_virtual_machine(resource_group, name)
|
6
|
+
def deallocate_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Deallocating Virtual Machine #{name} in Resource Group #{resource_group}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.deallocate_async(resource_group, name)
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.deallocate(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Virtual Machine #{name} Deallocated Successfully."
|
22
|
+
true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def delete_virtual_machine(resource_group, name)
|
6
|
+
def delete_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Deleting Virtual Machine #{name} from Resource Group #{resource_group}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.delete_async(resource_group, name)
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.delete(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Virtual Machine #{name} Deleted Successfully."
|
22
|
+
true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
@@ -3,7 +3,7 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def detach_data_disk_from_vm(resource_group, vm_name, disk_name)
|
6
|
+
def detach_data_disk_from_vm(resource_group, vm_name, disk_name, async)
|
7
7
|
msg = "Detaching Data Disk #{disk_name} from Virtual Machine #{vm_name} in Resource Group #{resource_group}."
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
vm = get_virtual_machine_instance(resource_group, vm_name, @compute_mgmt_client)
|
@@ -14,12 +14,20 @@ module Fog
|
|
14
14
|
end
|
15
15
|
vm.resources = nil
|
16
16
|
begin
|
17
|
-
|
17
|
+
if async
|
18
|
+
response = @compute_mgmt_client.virtual_machines.create_or_update_async(resource_group, vm_name, vm)
|
19
|
+
else
|
20
|
+
virtual_machine = @compute_mgmt_client.virtual_machines.create_or_update(resource_group, vm_name, vm)
|
21
|
+
end
|
18
22
|
rescue MsRestAzure::AzureOperationError => e
|
19
23
|
raise_azure_exception(e, msg)
|
20
24
|
end
|
21
|
-
|
22
|
-
|
25
|
+
if async
|
26
|
+
response
|
27
|
+
else
|
28
|
+
Fog::Logger.debug "Data Disk #{disk_name} detached from Virtual Machine #{vm_name} successfully."
|
29
|
+
virtual_machine
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def generalize_virtual_machine(resource_group, name)
|
6
|
+
def generalize_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Generalizing Virtual Machine #{name} in Resource Group #{resource_group}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.generalize_async(resource_group, name)
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.generalize(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Virtual Machine #{name} Generalized Successfully."
|
22
|
+
true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,20 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def get_virtual_machine(resource_group, name)
|
6
|
+
def get_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Getting Virtual Machine #{name} from Resource Group '#{resource_group}'"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.get_async(resource_group, name)
|
12
|
+
else
|
13
|
+
response = @compute_mgmt_client.virtual_machines.get(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
Fog::Logger.debug "Getting Virtual Machine #{name} from Resource Group '#{resource_group}' successful"
|
15
|
-
|
18
|
+
Fog::Logger.debug "Getting Virtual Machine #{name} from Resource Group '#{resource_group}' successful" unless async
|
19
|
+
response
|
16
20
|
end
|
17
21
|
end
|
18
22
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def list_available_sizes_for_virtual_machine(resource_group, name)
|
6
|
+
def list_available_sizes_for_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Listing sizes for Virtual Machine #{name} in Resource Group #{resource_group}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.list_available_sizes_async(resource_group, name)
|
12
|
+
else
|
13
|
+
vm_sizes = @compute_mgmt_client.virtual_machines.list_available_sizes(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Successfully listed sizes for Virtual Machine #{name} in Resource Group #{resource_group}"
|
22
|
+
vm_sizes.value
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def power_off_virtual_machine(resource_group, name)
|
6
|
+
def power_off_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Powering off Virtual Machine #{name} in Resource Group #{resource_group}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.power_off_async(resource_group, name)
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.power_off(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Virtual Machine #{name} Powered off Successfully."
|
22
|
+
true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def redeploy_virtual_machine(resource_group, name)
|
6
|
+
def redeploy_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Redeploying Virtual Machine #{name} in Resource Group #{resource_group}."
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.redeploy_async(resource_group, name)
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.redeploy(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Virtual Machine #{name} Redeployed Successfully."
|
22
|
+
true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def restart_virtual_machine(resource_group, name)
|
6
|
+
def restart_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Restarting Virtual Machine #{name} in Resource Group #{resource_group}"
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.restart_async(resource_group, name)
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.restart(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Virtual Machine #{name} Restarted Successfully."
|
22
|
+
true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
@@ -3,16 +3,24 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def start_virtual_machine(resource_group, name)
|
6
|
+
def start_virtual_machine(resource_group, name, async)
|
7
7
|
msg = "Starting Virtual Machine #{name} in Resource Group #{resource_group}."
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
|
10
|
+
if async
|
11
|
+
response = @compute_mgmt_client.virtual_machines.start_async(resource_group, name)
|
12
|
+
else
|
13
|
+
@compute_mgmt_client.virtual_machines.start(resource_group, name)
|
14
|
+
end
|
11
15
|
rescue MsRestAzure::AzureOperationError => e
|
12
16
|
raise_azure_exception(e, msg)
|
13
17
|
end
|
14
|
-
|
15
|
-
|
18
|
+
if async
|
19
|
+
response
|
20
|
+
else
|
21
|
+
Fog::Logger.debug "Virtual Machine #{name} started Successfully."
|
22
|
+
true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
# This class provides the mock implementation for unit tests.
|
data/lib/fog/azurerm/version.rb
CHANGED
@@ -84,42 +84,77 @@ class TestServer < Minitest::Test
|
|
84
84
|
@service.stub :delete_virtual_machine, true do
|
85
85
|
assert @server.destroy
|
86
86
|
end
|
87
|
+
|
88
|
+
async_response = Concurrent::Promise.execute { 10 }
|
89
|
+
@service.stub :delete_virtual_machine, async_response do
|
90
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.destroy(true)
|
91
|
+
end
|
87
92
|
end
|
88
93
|
|
89
94
|
def test_generalize_method_response
|
90
95
|
@service.stub :generalize_virtual_machine, true do
|
91
96
|
assert @server.generalize
|
92
97
|
end
|
98
|
+
|
99
|
+
async_response = Concurrent::Promise.execute { 10 }
|
100
|
+
@service.stub :generalize_virtual_machine, async_response do
|
101
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.generalize(true)
|
102
|
+
end
|
93
103
|
end
|
94
104
|
|
95
105
|
def test_power_off_method_response
|
96
106
|
@service.stub :power_off_virtual_machine, true do
|
97
107
|
assert @server.power_off
|
98
108
|
end
|
109
|
+
|
110
|
+
async_response = Concurrent::Promise.execute { 10 }
|
111
|
+
@service.stub :power_off_virtual_machine, async_response do
|
112
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.power_off(true)
|
113
|
+
end
|
99
114
|
end
|
100
115
|
|
101
116
|
def test_start_method_response
|
102
117
|
@service.stub :start_virtual_machine, true do
|
103
118
|
assert @server.start
|
104
119
|
end
|
120
|
+
|
121
|
+
async_response = Concurrent::Promise.execute { 10 }
|
122
|
+
@service.stub :start_virtual_machine, async_response do
|
123
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.start(true)
|
124
|
+
end
|
105
125
|
end
|
106
126
|
|
107
127
|
def test_restart_method_response
|
108
128
|
@service.stub :restart_virtual_machine, true do
|
109
129
|
assert @server.restart
|
110
130
|
end
|
131
|
+
|
132
|
+
async_response = Concurrent::Promise.execute { 10 }
|
133
|
+
@service.stub :restart_virtual_machine, async_response do
|
134
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.restart(true)
|
135
|
+
end
|
111
136
|
end
|
112
137
|
|
113
138
|
def test_deallocate_method_response
|
114
139
|
@service.stub :deallocate_virtual_machine, true do
|
115
140
|
assert @server.deallocate
|
116
141
|
end
|
142
|
+
|
143
|
+
async_response = Concurrent::Promise.execute { 10 }
|
144
|
+
@service.stub :deallocate_virtual_machine, async_response do
|
145
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.deallocate(true)
|
146
|
+
end
|
117
147
|
end
|
118
148
|
|
119
149
|
def test_redeploy_method_response
|
120
150
|
@service.stub :redeploy_virtual_machine, true do
|
121
151
|
assert @server.redeploy
|
122
152
|
end
|
153
|
+
|
154
|
+
async_response = Concurrent::Promise.execute { 10 }
|
155
|
+
@service.stub :redeploy_virtual_machine, async_response do
|
156
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.redeploy(true)
|
157
|
+
end
|
123
158
|
end
|
124
159
|
|
125
160
|
def test_vm_status_method_response
|
@@ -131,7 +166,12 @@ class TestServer < Minitest::Test
|
|
131
166
|
def test_list_available_sizes_method_response
|
132
167
|
response = ApiStub::Models::Compute::Server.list_available_sizes_for_virtual_machine_response(@compute_client)
|
133
168
|
@service.stub :list_available_sizes_for_virtual_machine, response do
|
134
|
-
assert_instance_of Array, @server.list_available_sizes
|
169
|
+
assert_instance_of Array, @server.list_available_sizes(false)
|
170
|
+
end
|
171
|
+
|
172
|
+
async_response = Concurrent::Promise.execute { 10 }
|
173
|
+
@service.stub :list_available_sizes_for_virtual_machine, async_response do
|
174
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.list_available_sizes(true)
|
135
175
|
end
|
136
176
|
end
|
137
177
|
|
@@ -140,6 +180,11 @@ class TestServer < Minitest::Test
|
|
140
180
|
@service.stub :attach_data_disk_to_vm, response do
|
141
181
|
assert_instance_of Fog::Compute::AzureRM::Server, @server.attach_data_disk('disk1', '10', 'mystorage1')
|
142
182
|
end
|
183
|
+
|
184
|
+
async_response = Concurrent::Promise.execute { 10 }
|
185
|
+
@service.stub :attach_data_disk_to_vm, async_response do
|
186
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.attach_data_disk('disk', '10', 'mystorage1', true)
|
187
|
+
end
|
143
188
|
end
|
144
189
|
|
145
190
|
def test_detach_data_disk_response
|
@@ -147,5 +192,10 @@ class TestServer < Minitest::Test
|
|
147
192
|
@service.stub :detach_data_disk_from_vm, response do
|
148
193
|
assert_instance_of Fog::Compute::AzureRM::Server, @server.detach_data_disk('disk1')
|
149
194
|
end
|
195
|
+
|
196
|
+
async_response = Concurrent::Promise.execute { 10 }
|
197
|
+
@service.stub :detach_data_disk_from_vm, async_response do
|
198
|
+
assert_instance_of Fog::AzureRM::AsyncResponse, @server.detach_data_disk('disk1', true)
|
199
|
+
end
|
150
200
|
end
|
151
201
|
end
|
@@ -10,14 +10,23 @@ class TestDeallocateVirtualMachine < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_deallocate_virtual_machine_success
|
12
12
|
@virtual_machines.stub :deallocate, true do
|
13
|
-
assert @service.deallocate_virtual_machine('fog-test-rg', 'fog-test-server')
|
13
|
+
assert @service.deallocate_virtual_machine('fog-test-rg', 'fog-test-server', false)
|
14
|
+
end
|
15
|
+
|
16
|
+
async_response = Concurrent::Promise.execute { 10 }
|
17
|
+
@virtual_machines.stub :deallocate_async, async_response do
|
18
|
+
assert @service.deallocate_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def test_deallocate_virtual_machine_failure
|
18
23
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
19
24
|
@virtual_machines.stub :deallocate, response do
|
20
|
-
assert_raises(RuntimeError) { @service.deallocate_virtual_machine('fog-test-rg', 'fog-test-server') }
|
25
|
+
assert_raises(RuntimeError) { @service.deallocate_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
26
|
+
end
|
27
|
+
|
28
|
+
@virtual_machines.stub :deallocate_async, response do
|
29
|
+
assert_raises(RuntimeError) { @service.deallocate_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -10,14 +10,23 @@ class TestDeleteVirtualMachine < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_delete_virtual_machine_success
|
12
12
|
@virtual_machines.stub :delete, true do
|
13
|
-
assert @service.delete_virtual_machine('fog-test-rg', 'fog-test-server')
|
13
|
+
assert @service.delete_virtual_machine('fog-test-rg', 'fog-test-server', false)
|
14
|
+
end
|
15
|
+
|
16
|
+
async_response = Concurrent::Promise.execute { 10 }
|
17
|
+
@virtual_machines.stub :delete_async, async_response do
|
18
|
+
assert @service.delete_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def test_delete_virtual_machine_failure
|
18
23
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
19
24
|
@virtual_machines.stub :delete, response do
|
20
|
-
assert_raises(RuntimeError) { @service.delete_virtual_machine('fog-test-rg', 'fog-test-server') }
|
25
|
+
assert_raises(RuntimeError) { @service.delete_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
26
|
+
end
|
27
|
+
|
28
|
+
@virtual_machines.stub :delete_async, response do
|
29
|
+
assert_raises(RuntimeError) { @service.delete_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -10,14 +10,23 @@ class TestGeneralizeVirtualMachine < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_generalize_virtual_machine_success
|
12
12
|
@virtual_machines.stub :generalize, true do
|
13
|
-
assert @service.generalize_virtual_machine('fog-test-rg', 'fog-test-server')
|
13
|
+
assert @service.generalize_virtual_machine('fog-test-rg', 'fog-test-server', false)
|
14
|
+
end
|
15
|
+
|
16
|
+
async_response = Concurrent::Promise.execute { 10 }
|
17
|
+
@virtual_machines.stub :generalize_async, async_response do
|
18
|
+
assert @service.generalize_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def test_generalize_virtual_machine_failure
|
18
23
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
19
24
|
@virtual_machines.stub :generalize, response do
|
20
|
-
assert_raises(RuntimeError) { @service.generalize_virtual_machine('fog-test-rg', 'fog-test-server') }
|
25
|
+
assert_raises(RuntimeError) { @service.generalize_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
26
|
+
end
|
27
|
+
|
28
|
+
@virtual_machines.stub :generalize_async, response do
|
29
|
+
assert_raises(RuntimeError) { @service.generalize_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -11,14 +11,23 @@ class TestListAvailableSizesForVirtualMachine < Minitest::Test
|
|
11
11
|
def test_list_available_sizes_for_virtual_machine_success
|
12
12
|
response = ApiStub::Requests::Compute::VirtualMachine.list_available_sizes_for_virtual_machine_response(@compute_client)
|
13
13
|
@virtual_machines.stub :list_available_sizes, response do
|
14
|
-
assert_equal @service.list_available_sizes_for_virtual_machine('fog-test-rg', 'fog-test-server'), response.value
|
14
|
+
assert_equal @service.list_available_sizes_for_virtual_machine('fog-test-rg', 'fog-test-server', false), response.value
|
15
|
+
end
|
16
|
+
|
17
|
+
async_response = Concurrent::Promise.execute { 10 }
|
18
|
+
@virtual_machines.stub :list_available_sizes_async, async_response do
|
19
|
+
assert @service.list_available_sizes_for_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
23
|
def test_list_available_sizes_for_virtual_machine_failure
|
19
24
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
20
25
|
@virtual_machines.stub :list_available_sizes, response do
|
21
|
-
assert_raises(RuntimeError) { @service.list_available_sizes_for_virtual_machine('fog-test-rg', 'fog-test-server') }
|
26
|
+
assert_raises(RuntimeError) { @service.list_available_sizes_for_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
27
|
+
end
|
28
|
+
|
29
|
+
@virtual_machines.stub :list_available_sizes_async, response do
|
30
|
+
assert_raises(RuntimeError) { @service.list_available_sizes_for_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
@@ -10,14 +10,23 @@ class TestPowerOffVirtualMachine < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_power_off_virtual_machine_success
|
12
12
|
@virtual_machines.stub :power_off, true do
|
13
|
-
assert @service.power_off_virtual_machine('fog-test-rg', 'fog-test-server')
|
13
|
+
assert @service.power_off_virtual_machine('fog-test-rg', 'fog-test-server' ,false)
|
14
|
+
end
|
15
|
+
|
16
|
+
async_response = Concurrent::Promise.execute { 10 }
|
17
|
+
@virtual_machines.stub :power_off_async, async_response do
|
18
|
+
assert @service.power_off_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def test_power_off_virtual_machine_failure
|
18
23
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
19
24
|
@virtual_machines.stub :power_off, response do
|
20
|
-
assert_raises(RuntimeError) { @service.power_off_virtual_machine('fog-test-rg', 'fog-test-server') }
|
25
|
+
assert_raises(RuntimeError) { @service.power_off_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
26
|
+
end
|
27
|
+
|
28
|
+
@virtual_machines.stub :power_off_async, response do
|
29
|
+
assert_raises(RuntimeError) { @service.power_off_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -10,14 +10,24 @@ class TestRedeployVirtualMachine < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_redeploy_virtual_machine_success
|
12
12
|
@virtual_machines.stub :redeploy, true do
|
13
|
-
assert @service.redeploy_virtual_machine('fog-test-rg', 'fog-test-server')
|
13
|
+
assert @service.redeploy_virtual_machine('fog-test-rg', 'fog-test-server', false)
|
14
|
+
end
|
15
|
+
|
16
|
+
async_response = Concurrent::Promise.execute { 10 }
|
17
|
+
@virtual_machines.stub :redeploy_async, async_response do
|
18
|
+
assert @service.redeploy_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def test_redeploy_virtual_machine_failure
|
18
23
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
19
24
|
@virtual_machines.stub :redeploy, response do
|
20
|
-
assert_raises(RuntimeError) { @service.redeploy_virtual_machine('fog-test-rg', 'fog-test-server') }
|
25
|
+
assert_raises(RuntimeError) { @service.redeploy_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
26
|
+
end
|
27
|
+
|
28
|
+
async_response = Concurrent::Promise.execute { 10 }
|
29
|
+
@virtual_machines.stub :redeploy_async, response do
|
30
|
+
assert_raises(RuntimeError) { @service.redeploy_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
21
31
|
end
|
22
32
|
end
|
23
33
|
end
|
@@ -10,14 +10,23 @@ class TestRestartVirtualMachine < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_restart_virtual_machine_success
|
12
12
|
@virtual_machines.stub :restart, true do
|
13
|
-
assert @service.restart_virtual_machine('fog-test-rg', 'fog-test-server')
|
13
|
+
assert @service.restart_virtual_machine('fog-test-rg', 'fog-test-server', false)
|
14
|
+
end
|
15
|
+
|
16
|
+
async_response = Concurrent::Promise.execute { 10 }
|
17
|
+
@virtual_machines.stub :restart_async, async_response do
|
18
|
+
assert @service.restart_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def test_restart_virtual_machine_failure
|
18
23
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
19
24
|
@virtual_machines.stub :restart, response do
|
20
|
-
assert_raises(RuntimeError) { @service.restart_virtual_machine('fog-test-rg', 'fog-test-server') }
|
25
|
+
assert_raises(RuntimeError) { @service.restart_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
26
|
+
end
|
27
|
+
|
28
|
+
@virtual_machines.stub :restart_async, response do
|
29
|
+
assert_raises(RuntimeError) { @service.restart_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -10,14 +10,23 @@ class TestStartVirtualMachine < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_start_virtual_machine_success
|
12
12
|
@virtual_machines.stub :start, true do
|
13
|
-
assert @service.start_virtual_machine('fog-test-rg', 'fog-test-server')
|
13
|
+
assert @service.start_virtual_machine('fog-test-rg', 'fog-test-server', false)
|
14
|
+
end
|
15
|
+
|
16
|
+
async_response = Concurrent::Promise.execute { 10 }
|
17
|
+
@virtual_machines.stub :start_async, async_response do
|
18
|
+
assert @service.start_virtual_machine('fog-test-rg', 'fog-test-server', true), async_response
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def test_start_virtual_machine_failure
|
18
23
|
response = proc { fail MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
19
24
|
@virtual_machines.stub :start, response do
|
20
|
-
assert_raises(RuntimeError) { @service.start_virtual_machine('fog-test-rg', 'fog-test-server') }
|
25
|
+
assert_raises(RuntimeError) { @service.start_virtual_machine('fog-test-rg', 'fog-test-server', false) }
|
26
|
+
end
|
27
|
+
|
28
|
+
@virtual_machines.stub :start_async, response do
|
29
|
+
assert_raises(RuntimeError) { @service.start_virtual_machine('fog-test-rg', 'fog-test-server', true) }
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-azure-rm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaffan Chaudhry
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2017-
|
17
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: rake
|