fog-azure-rm 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/fog/azurerm/compute.rb +6 -0
- data/lib/fog/azurerm/docs/compute.md +67 -11
- data/lib/fog/azurerm/docs/network.md +59 -0
- data/lib/fog/azurerm/docs/storage.md +107 -35
- data/lib/fog/azurerm/models/compute/server.rb +15 -9
- data/lib/fog/azurerm/models/compute/virtual_machine_extension.rb +78 -0
- data/lib/fog/azurerm/models/compute/virtual_machine_extensions.rb +30 -0
- data/lib/fog/azurerm/models/network/express_route_circuit.rb +21 -21
- data/lib/fog/azurerm/models/network/express_route_circuit_peering.rb +21 -21
- data/lib/fog/azurerm/models/network/express_route_service_provider.rb +8 -8
- data/lib/fog/azurerm/models/network/network_security_rule.rb +27 -0
- data/lib/fog/azurerm/models/network/network_security_rules.rb +31 -0
- data/lib/fog/azurerm/models/network/subnet.rb +16 -12
- data/lib/fog/azurerm/models/network/virtual_network_gateway.rb +6 -6
- data/lib/fog/azurerm/models/storage/{containers.rb → directories.rb} +10 -10
- data/lib/fog/azurerm/models/storage/{container.rb → directory.rb} +13 -13
- data/lib/fog/azurerm/models/storage/file.rb +151 -0
- data/lib/fog/azurerm/models/storage/files.rb +31 -0
- data/lib/fog/azurerm/network.rb +6 -0
- data/lib/fog/azurerm/requests/compute/create_or_update_vm_extension.rb +63 -0
- data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +45 -8
- data/lib/fog/azurerm/requests/compute/delete_vm_extension.rb +28 -0
- data/lib/fog/azurerm/requests/compute/get_vm_extension.rb +46 -0
- data/lib/fog/azurerm/requests/network/create_or_update_express_route_circuit.rb +44 -31
- data/lib/fog/azurerm/requests/network/create_or_update_express_route_circuit_peering.rb +23 -13
- data/lib/fog/azurerm/requests/network/create_or_update_network_security_rule.rb +59 -0
- data/lib/fog/azurerm/requests/network/create_or_update_virtual_network_gateway.rb +23 -15
- data/lib/fog/azurerm/requests/network/delete_network_security_rule.rb +30 -0
- data/lib/fog/azurerm/requests/network/get_available_ipaddresses_count.rb +23 -0
- data/lib/fog/azurerm/requests/network/get_network_security_rule.rb +47 -0
- data/lib/fog/azurerm/requests/network/list_network_security_groups.rb +1 -1
- data/lib/fog/azurerm/requests/network/list_network_security_rules.rb +51 -0
- data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +29 -0
- data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +29 -0
- data/lib/fog/azurerm/requests/storage/check_blob_exist.rb +25 -0
- data/lib/fog/azurerm/requests/storage/compare_blob.rb +73 -0
- data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
- data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
- data/lib/fog/azurerm/requests/storage/delete_blob.rb +27 -0
- data/lib/fog/azurerm/requests/storage/download_blob_to_file.rb +56 -0
- data/lib/fog/azurerm/requests/storage/get_blob_metadata.rb +37 -9
- data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +53 -0
- data/lib/fog/azurerm/requests/storage/get_container_metadata.rb +2 -2
- data/lib/fog/azurerm/requests/storage/list_blobs.rb +82 -0
- data/lib/fog/azurerm/requests/storage/list_containers.rb +1 -1
- data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +27 -0
- data/lib/fog/azurerm/requests/storage/release_container_lease.rb +27 -0
- data/lib/fog/azurerm/requests/storage/set_blob_metadata.rb +4 -4
- data/lib/fog/azurerm/requests/storage/set_blob_properties.rb +26 -0
- data/lib/fog/azurerm/requests/storage/set_container_metadata.rb +3 -3
- data/lib/fog/azurerm/requests/storage/upload_block_blob_from_file.rb +60 -0
- data/lib/fog/azurerm/storage.rb +26 -8
- data/lib/fog/azurerm/utilities/general.rb +14 -1
- data/lib/fog/azurerm/version.rb +1 -1
- data/test/api_stub.rb +8 -4
- data/test/api_stub/models/compute/virtual_machine_extension.rb +31 -0
- data/test/api_stub/models/network/network_security_rule.rb +30 -0
- data/test/api_stub/models/storage/{container.rb → directory.rb} +1 -1
- data/test/api_stub/models/storage/file.rb +178 -0
- data/test/api_stub/requests/compute/virtual_machine.rb +119 -0
- data/test/api_stub/requests/compute/virtual_machine_extension.rb +46 -0
- data/test/api_stub/requests/network/network_security_rule.rb +72 -0
- data/test/api_stub/requests/storage/{container.rb → directory.rb} +2 -2
- data/test/api_stub/requests/storage/file.rb +164 -0
- data/test/integration/availability_set.rb +6 -0
- data/test/integration/blob.rb +205 -0
- data/test/integration/credentials/azure.yml +4 -4
- data/test/integration/deployment.rb +9 -0
- data/test/integration/external_load_balancer.rb +9 -0
- data/test/integration/internal_load_balancer.rb +8 -0
- data/test/integration/network_security_group.rb +9 -0
- data/test/integration/network_security_rule.rb +86 -0
- data/test/integration/server.rb +62 -9
- data/test/integration/server_custom_image.rb +118 -0
- data/test/integration/subnet.rb +12 -1
- data/test/integration/virtual_machine_extension.rb +148 -0
- data/test/integration/virtual_network.rb +9 -1
- data/test/integration/virtual_network_gateway.rb +7 -29
- data/test/integration/virtual_network_gateway_connection_to_express_route.rb +116 -0
- data/test/models/compute/test_virtual_machine_extension.rb +61 -0
- data/test/models/compute/test_virtual_machine_extensions.rb +36 -0
- data/test/models/network/test_express_route_circuit.rb +4 -10
- data/test/models/network/test_express_route_circuit_peering.rb +4 -10
- data/test/models/network/test_network_interface.rb +4 -8
- data/test/models/network/test_network_security_rule.rb +14 -0
- data/test/models/network/test_network_security_rules.rb +42 -0
- data/test/models/network/test_subnet.rb +5 -0
- data/test/models/storage/test_directories.rb +106 -0
- data/test/models/storage/test_directory.rb +125 -0
- data/test/models/storage/test_file.rb +258 -0
- data/test/models/storage/test_files.rb +67 -0
- data/test/models/storage/test_storage_account.rb +2 -4
- data/test/requests/compute/test_create_virtual_machine.rb +19 -5
- data/test/requests/compute/test_create_vm_extension.rb +35 -0
- data/test/requests/compute/test_get_vm_extension.rb +26 -0
- data/test/requests/compute/test_update_vm_extension.rb +35 -0
- data/test/requests/network/test_create_or_update_network_security_rule.rb +28 -0
- data/test/requests/network/test_delete_network_security_rule.rb +25 -0
- data/test/requests/network/test_get_available_ipaddresses_count.rb +18 -0
- data/test/requests/network/test_get_network_security_rule.rb +26 -0
- data/test/requests/network/test_list_network_security_groups.rb +2 -2
- data/test/requests/network/test_list_network_security_rules.rb +26 -0
- data/test/requests/storage/test_acquire_blob_lease.rb +17 -0
- data/test/requests/storage/test_acquire_container_lease.rb +17 -0
- data/test/requests/storage/test_check_blob_exist.rb +17 -0
- data/test/requests/storage/test_compare_blob.rb +17 -0
- data/test/requests/storage/test_copy_blob.rb +17 -0
- data/test/requests/storage/test_copy_blob_from_uri.rb +17 -0
- data/test/requests/storage/test_create_container.rb +2 -2
- data/test/requests/storage/test_delete_blob.rb +22 -0
- data/test/requests/storage/test_delete_container.rb +1 -1
- data/test/requests/storage/test_download_blob_to_file.rb +25 -0
- data/test/requests/storage/test_get_blob_metadata.rb +2 -2
- data/test/requests/storage/test_get_blob_properties.rb +23 -0
- data/test/requests/storage/test_get_container_access_control_list.rb +2 -2
- data/test/requests/storage/test_get_container_metadata.rb +2 -2
- data/test/requests/storage/test_get_container_properties.rb +2 -2
- data/test/requests/storage/test_list_blobs_in_container.rb +23 -0
- data/test/requests/storage/test_list_containers.rb +2 -2
- data/test/requests/storage/test_release_blob_lease.rb +16 -0
- data/test/requests/storage/test_release_container_lease.rb +16 -0
- data/test/requests/storage/test_set_blob_metadata.rb +1 -1
- data/test/requests/storage/test_set_blob_properties.rb +16 -0
- data/test/requests/storage/test_set_container_metadata.rb +1 -1
- data/test/requests/storage/test_upload_block_blob_from_file.rb +23 -0
- data/test/test_helper.rb +116 -3
- metadata +73 -15
- data/.DS_Store +0 -0
- data/lib/fog/azurerm/fog_azure_rm_exception.rb +0 -13
- data/lib/fog/azurerm/models/storage/blob.rb +0 -13
- data/lib/fog/azurerm/models/storage/blobs.rb +0 -22
- data/test/api_stub/models/storage/blob.rb +0 -17
- data/test/api_stub/requests/storage/blob.rb +0 -24
- data/test/models/storage/test_blobs.rb +0 -32
- data/test/models/storage/test_container.rb +0 -67
- data/test/models/storage/test_containers.rb +0 -56
@@ -0,0 +1,151 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class is giving implementation of create/save and
|
5
|
+
# delete/destroy for Blob.
|
6
|
+
class File < Fog::Model
|
7
|
+
identity :key, aliases: %w(Name name)
|
8
|
+
attribute :accept_ranges
|
9
|
+
attribute :cache_control
|
10
|
+
attribute :committed_block_count
|
11
|
+
attribute :content_length
|
12
|
+
attribute :content_type
|
13
|
+
attribute :content_md5
|
14
|
+
attribute :content_encoding
|
15
|
+
attribute :content_language
|
16
|
+
attribute :content_disposition
|
17
|
+
attribute :copy_completion_time
|
18
|
+
attribute :copy_status
|
19
|
+
attribute :copy_status_description
|
20
|
+
attribute :copy_id
|
21
|
+
attribute :copy_progress
|
22
|
+
attribute :copy_source
|
23
|
+
attribute :directory
|
24
|
+
attribute :etag
|
25
|
+
attribute :file_path
|
26
|
+
attribute :last_modified
|
27
|
+
attribute :lease_duration
|
28
|
+
attribute :lease_state
|
29
|
+
attribute :lease_status
|
30
|
+
attribute :metadata
|
31
|
+
attribute :sequence_number
|
32
|
+
attribute :blob_type
|
33
|
+
|
34
|
+
def save(options = {})
|
35
|
+
requires :key
|
36
|
+
requires :directory
|
37
|
+
merge_attributes(File.parse(service.upload_block_blob_from_file(directory, key, file_path, options)))
|
38
|
+
end
|
39
|
+
|
40
|
+
alias create save
|
41
|
+
|
42
|
+
def destroy(options = {})
|
43
|
+
requires :key
|
44
|
+
requires :directory
|
45
|
+
service.delete_blob directory, key, options
|
46
|
+
end
|
47
|
+
|
48
|
+
def save_to_file(file_path, options = {})
|
49
|
+
requires :key
|
50
|
+
requires :directory
|
51
|
+
merge_attributes(file_path: file_path)
|
52
|
+
merge_attributes(File.parse(service.download_blob_to_file(directory, key, file_path, options)))
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_properties(options = {})
|
56
|
+
requires :key
|
57
|
+
requires :directory
|
58
|
+
merge_attributes(File.parse(service.get_blob_properties(directory, key, options)))
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_properties(properties = {})
|
62
|
+
requires :key
|
63
|
+
requires :directory
|
64
|
+
service.set_blob_properties(directory, key, properties)
|
65
|
+
merge_attributes(properties)
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_metadata(options = {})
|
69
|
+
requires :key
|
70
|
+
requires :directory
|
71
|
+
merge_attributes(metadata: service.get_blob_metadata(directory, key, options))
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_metadata(metadata, options = {})
|
75
|
+
requires :key
|
76
|
+
requires :directory
|
77
|
+
service.set_blob_metadata(directory, key, metadata, options)
|
78
|
+
merge_attributes(metadata: metadata)
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.parse(blob)
|
82
|
+
if blob.is_a? Hash
|
83
|
+
parse_hash blob
|
84
|
+
else
|
85
|
+
parse_object blob
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.parse_hash(blob)
|
90
|
+
hash = {}
|
91
|
+
hash['key'] = blob['name']
|
92
|
+
hash['metadata'] = blob['metadata']
|
93
|
+
return hash unless blob.key?('properties')
|
94
|
+
|
95
|
+
hash['last_modified'] = blob['properties']['last_modified']
|
96
|
+
hash['etag'] = blob['properties']['etag']
|
97
|
+
hash['lease_duration'] = blob['properties']['lease_duration']
|
98
|
+
hash['lease_status'] = blob['properties']['lease_status']
|
99
|
+
hash['lease_state'] = blob['properties']['lease_state']
|
100
|
+
hash['content_length'] = blob['properties']['content_length']
|
101
|
+
hash['content_type'] = blob['properties']['content_type']
|
102
|
+
hash['content_encoding'] = blob['properties']['content_encoding']
|
103
|
+
hash['content_language'] = blob['properties']['content_language']
|
104
|
+
hash['content_disposition'] = blob['properties']['content_disposition']
|
105
|
+
hash['content_md5'] = blob['properties']['content_md5']
|
106
|
+
hash['cache_control'] = blob['properties']['cache_control']
|
107
|
+
hash['sequence_number'] = blob['properties']['sequence_number']
|
108
|
+
hash['blob_type'] = blob['properties']['blob_type']
|
109
|
+
hash['copy_id'] = blob['properties']['copy_id']
|
110
|
+
hash['copy_status'] = blob['properties']['copy_status']
|
111
|
+
hash['copy_source'] = blob['properties']['copy_source']
|
112
|
+
hash['copy_progress'] = blob['properties']['copy_progress']
|
113
|
+
hash['copy_completion_time'] = blob['properties']['copy_completion_time']
|
114
|
+
hash['copy_status_description'] = blob['properties']['copy_status_description']
|
115
|
+
hash['accept_ranges'] = blob['properties']['accept_ranges']
|
116
|
+
hash
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.parse_object(blob)
|
120
|
+
hash = {}
|
121
|
+
hash['key'] = blob.name
|
122
|
+
hash['metadata'] = blob.metadata
|
123
|
+
return hash unless blob.respond_to?('properties')
|
124
|
+
|
125
|
+
hash['last_modified'] = blob.properties[:last_modified]
|
126
|
+
hash['etag'] = blob.properties[:etag]
|
127
|
+
hash['lease_duration'] = blob.properties[:lease_duration]
|
128
|
+
hash['lease_status'] = blob.properties[:lease_status]
|
129
|
+
hash['lease_state'] = blob.properties[:lease_state]
|
130
|
+
hash['content_length'] = blob.properties[:content_length]
|
131
|
+
hash['content_type'] = blob.properties[:content_type]
|
132
|
+
hash['content_encoding'] = blob.properties[:content_encoding]
|
133
|
+
hash['content_language'] = blob.properties[:content_language]
|
134
|
+
hash['content_disposition'] = blob.properties[:content_disposition]
|
135
|
+
hash['content_md5'] = blob.properties[:content_md5]
|
136
|
+
hash['cache_control'] = blob.properties[:cache_control]
|
137
|
+
hash['sequence_number'] = blob.properties[:sequence_number]
|
138
|
+
hash['blob_type'] = blob.properties[:blob_type]
|
139
|
+
hash['copy_id'] = blob.properties[:copy_id]
|
140
|
+
hash['copy_status'] = blob.properties[:copy_status]
|
141
|
+
hash['copy_source'] = blob.properties[:copy_source]
|
142
|
+
hash['copy_progress'] = blob.properties[:copy_progress]
|
143
|
+
hash['copy_completion_time'] = blob.properties[:copy_completion_time]
|
144
|
+
hash['copy_status_description'] = blob.properties[:copy_status_description]
|
145
|
+
hash['accept_ranges'] = blob.properties[:accept_ranges]
|
146
|
+
hash
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/azurerm/models/storage/file'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Storage
|
6
|
+
class AzureRM
|
7
|
+
# This class is giving implementation of listing blobs.
|
8
|
+
class Files < Fog::Collection
|
9
|
+
model Fog::Storage::AzureRM::File
|
10
|
+
attribute :directory
|
11
|
+
|
12
|
+
def all(options = { metadata: true })
|
13
|
+
files = []
|
14
|
+
service.list_blobs(directory, options).each do |blob|
|
15
|
+
hash = File.parse blob
|
16
|
+
hash['directory'] = directory
|
17
|
+
files << hash
|
18
|
+
end
|
19
|
+
load files
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(directory, name)
|
23
|
+
file = File.new(service: service)
|
24
|
+
file.directory = directory
|
25
|
+
file.key = name
|
26
|
+
file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/fog/azurerm/network.rb
CHANGED
@@ -31,6 +31,7 @@ module Fog
|
|
31
31
|
request :detach_route_table_from_subnet
|
32
32
|
request :list_subnets
|
33
33
|
request :get_subnet
|
34
|
+
request :get_available_ipaddresses_count
|
34
35
|
request :delete_subnet
|
35
36
|
request :create_or_update_network_interface
|
36
37
|
request :delete_network_interface
|
@@ -76,6 +77,10 @@ module Fog
|
|
76
77
|
request :get_connection_shared_key
|
77
78
|
request :reset_connection_shared_key
|
78
79
|
request :set_connection_shared_key
|
80
|
+
request :create_or_update_network_security_rule
|
81
|
+
request :delete_network_security_rule
|
82
|
+
request :get_network_security_rule
|
83
|
+
request :list_network_security_rules
|
79
84
|
|
80
85
|
model_path 'fog/azurerm/models/network'
|
81
86
|
model :virtual_network
|
@@ -96,6 +101,7 @@ module Fog
|
|
96
101
|
model :network_security_group
|
97
102
|
collection :network_security_groups
|
98
103
|
model :network_security_rule
|
104
|
+
collection :network_security_rules
|
99
105
|
model :path_rule
|
100
106
|
model :vpn_client_configuration
|
101
107
|
model :vpn_client_revoked_certificates
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Compute Request
|
5
|
+
class Real
|
6
|
+
def create_or_update_vm_extension(vm_extension_params)
|
7
|
+
msg = "Creating/Updating Extension #{vm_extension_params[:name]} for Virtual Machine #{vm_extension_params[:vm_name]} in Resource Group #{vm_extension_params[:resource_group]}"
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
|
10
|
+
vm_extension = create_virtual_machine_extension_object(vm_extension_params)
|
11
|
+
begin
|
12
|
+
vm_extension_obj = @compute_mgmt_client.virtual_machine_extensions.create_or_update(vm_extension_params[:resource_group], vm_extension_params[:vm_name], vm_extension_params[:name], vm_extension)
|
13
|
+
rescue MsRestAzure::AzureOperationError => e
|
14
|
+
raise_azure_exception(e, msg)
|
15
|
+
end
|
16
|
+
Fog::Logger.debug "Extension #{vm_extension.name} for Virtual Machine #{vm_extension_params[:vm_name]} in Resource Group #{vm_extension_params[:resource_group]} created/updated successfully"
|
17
|
+
vm_extension_obj
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def create_virtual_machine_extension_object(virtual_machine_extension)
|
23
|
+
vm_extension = Azure::ARM::Compute::Models::VirtualMachineExtension.new
|
24
|
+
vm_extension.name = virtual_machine_extension[:name]
|
25
|
+
vm_extension.location = virtual_machine_extension[:location]
|
26
|
+
vm_extension.virtual_machine_extension_type = virtual_machine_extension[:type]
|
27
|
+
vm_extension.publisher = virtual_machine_extension[:publisher]
|
28
|
+
vm_extension.type_handler_version = virtual_machine_extension[:type_handler_version]
|
29
|
+
vm_extension.auto_upgrade_minor_version = virtual_machine_extension[:auto_upgrade_minor_version]
|
30
|
+
vm_extension.settings = virtual_machine_extension[:settings]
|
31
|
+
vm_extension.protected_settings = virtual_machine_extension[:protected_settings]
|
32
|
+
vm_extension
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Mock class for Compute Request
|
37
|
+
class Mock
|
38
|
+
def add_or_update_vm_extension(*)
|
39
|
+
body = {
|
40
|
+
'id' => '/subscriptions/########-####-####-####-############/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/TestVM/extensions/IaaSAntimalware',
|
41
|
+
'name' => 'IaasAntimalware',
|
42
|
+
'resource_group' => 'fog-test-rg',
|
43
|
+
'location' => 'West US',
|
44
|
+
'properties' => {
|
45
|
+
'publisher' => 'Microsoft.Azure.Security',
|
46
|
+
'type' => 'IaaSAntimalware',
|
47
|
+
'typeHandlerVersion' => '1.3',
|
48
|
+
'autoUpgradeMinorVersion' => 'true',
|
49
|
+
'forceUpdateTag' => 'RerunExtension',
|
50
|
+
'settings' => {
|
51
|
+
'AnitmalwareEnabled' => 'true',
|
52
|
+
'RealtimeProtectionEnabled' => 'false'
|
53
|
+
},
|
54
|
+
'protected_settings' => {}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
extension_mapper = Azure::ARM::Compute::Models::VirtualMachineExtension.mapper
|
58
|
+
@compute_mgmt_client.deserialize(extension_mapper, body, 'result.body')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -26,7 +26,11 @@ module Fog
|
|
26
26
|
vm_hash[:publisher],
|
27
27
|
vm_hash[:offer],
|
28
28
|
vm_hash[:sku],
|
29
|
-
vm_hash[:version]
|
29
|
+
vm_hash[:version],
|
30
|
+
vm_hash[:vhd_path],
|
31
|
+
vm_hash[:platform],
|
32
|
+
vm_hash[:resource_group])
|
33
|
+
|
30
34
|
virtual_machine.os_profile = if vm_hash[:platform].casecmp(WINDOWS).zero?
|
31
35
|
define_windows_os_profile(vm_hash[:name],
|
32
36
|
vm_hash[:username],
|
@@ -62,21 +66,54 @@ module Fog
|
|
62
66
|
hw_profile
|
63
67
|
end
|
64
68
|
|
65
|
-
def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version)
|
69
|
+
def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version, vhd_path, platform, resource_group)
|
66
70
|
storage_profile = Azure::ARM::Compute::Models::StorageProfile.new
|
67
71
|
os_disk = Azure::ARM::Compute::Models::OSDisk.new
|
68
72
|
vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
|
69
|
-
image_reference = Azure::ARM::Compute::Models::ImageReference.new
|
70
73
|
|
71
|
-
image_reference.publisher = publisher
|
72
|
-
image_reference.offer = offer
|
73
|
-
image_reference.sku = sku
|
74
|
-
image_reference.version = version
|
75
74
|
vhd.uri = "http://#{storage_account_name}.blob.core.windows.net/vhds/#{vm_name}_os_disk.vhd"
|
75
|
+
|
76
|
+
if vhd_path.nil?
|
77
|
+
image_reference = Azure::ARM::Compute::Models::ImageReference.new
|
78
|
+
image_reference.publisher = publisher
|
79
|
+
image_reference.offer = offer
|
80
|
+
image_reference.sku = sku
|
81
|
+
image_reference.version = version
|
82
|
+
storage_profile.image_reference = image_reference
|
83
|
+
else
|
84
|
+
# Copy if VHD does not exist belongs to same storage account.
|
85
|
+
vhd_storage_account = (vhd_path.split('/')[2]).split('.')[0]
|
86
|
+
if storage_account_name != vhd_storage_account
|
87
|
+
storage_account = @storage_service.storage_accounts.get(resource_group, storage_account_name)
|
88
|
+
access_key = storage_account.get_access_keys[0].value
|
89
|
+
storage_data = Fog::Storage.new(provider: 'AzureRM', azure_storage_account_name: storage_account_name, azure_storage_access_key: access_key)
|
90
|
+
|
91
|
+
container_name = 'customimagevhd'
|
92
|
+
blob_name = 'vhd_image.vhd'
|
93
|
+
storage_data.directories.create(
|
94
|
+
key: container_name
|
95
|
+
)
|
96
|
+
|
97
|
+
storage_data.copy_blob_from_uri(container_name, blob_name, vhd_path)
|
98
|
+
until storage_data.get_blob_properties(container_name, blob_name).properties[:copy_status] == 'success'
|
99
|
+
Fog::Logger.debug 'Waiting disk to ready'
|
100
|
+
sleep(10)
|
101
|
+
end
|
102
|
+
new_vhd_path = "http://#{storage_account_name}.blob.core.windows.net/customimagevhd/vhd_image.vhd"
|
103
|
+
Fog::Logger.debug "Path:#{new_vhd_path}. | Copy done"
|
104
|
+
else
|
105
|
+
new_vhd_path = vhd_path
|
106
|
+
end
|
107
|
+
|
108
|
+
img_vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
|
109
|
+
img_vhd.uri = new_vhd_path
|
110
|
+
os_disk.image = img_vhd
|
111
|
+
os_disk.os_type = platform
|
112
|
+
end
|
113
|
+
|
76
114
|
os_disk.name = "#{vm_name}_os_disk"
|
77
115
|
os_disk.vhd = vhd
|
78
116
|
os_disk.create_option = Azure::ARM::Compute::Models::DiskCreateOptionTypes::FromImage
|
79
|
-
storage_profile.image_reference = image_reference
|
80
117
|
storage_profile.os_disk = os_disk
|
81
118
|
storage_profile
|
82
119
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Compute Request
|
5
|
+
class Real
|
6
|
+
def delete_vm_extension(resource_group, vm_name, extension_name)
|
7
|
+
msg = "Deleting Extension #{extension_name} of Virtual Machine #{vm_name} in Resource Group #{resource_group}"
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
begin
|
10
|
+
@compute_mgmt_client.virtual_machine_extensions.delete(resource_group, vm_name, extension_name)
|
11
|
+
rescue MsRestAzure::AzureOperationError => e
|
12
|
+
raise_azure_exception(e, msg)
|
13
|
+
end
|
14
|
+
Fog::Logger.debug "Extension #{extension_name} of Virtual Machine #{vm_name} in Resource Group #{resource_group} deleted successfully"
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Mock class for Compute Request
|
20
|
+
class Mock
|
21
|
+
def delete_vm_extension(*)
|
22
|
+
Fog::Logger.debug 'Extension extension_name of Virtual Machine vm_name in Resource Group resource_group deleted successfully'
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Compute Request
|
5
|
+
class Real
|
6
|
+
def get_vm_extension(resource_group_name, virtual_machine_name, vm_extension_name)
|
7
|
+
msg = "Getting Extension #{vm_extension_name} of Virtual Machine #{virtual_machine_name} in Resource Group #{resource_group_name}"
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
begin
|
10
|
+
vm_extension = @compute_mgmt_client.virtual_machine_extensions.get(resource_group_name, virtual_machine_name, vm_extension_name)
|
11
|
+
rescue MsRestAzure::AzureOperationError => e
|
12
|
+
raise_azure_exception(e, msg)
|
13
|
+
end
|
14
|
+
Fog::Logger.debug "#{msg} successful"
|
15
|
+
vm_extension
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Mock class for Compute Request
|
20
|
+
class Mock
|
21
|
+
def get_vm_extension(*)
|
22
|
+
body = {
|
23
|
+
'id' => '/subscriptions/########-####-####-####-############/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/TestVM/extensions/IaaSAntimalware',
|
24
|
+
'name' => 'IaasAntimalware',
|
25
|
+
'resource_group' => 'fog-test-rg',
|
26
|
+
'location' => 'West US',
|
27
|
+
'properties' => {
|
28
|
+
'publisher' => 'Microsoft.Azure.Security',
|
29
|
+
'type' => 'IaaSAntimalware',
|
30
|
+
'typeHandlerVersion' => '1.3',
|
31
|
+
'autoUpgradeMinorVersion' => 'true',
|
32
|
+
'forceUpdateTag' => 'RerunExtension',
|
33
|
+
'settings' => {
|
34
|
+
'AnitmalwareEnabled' => 'true',
|
35
|
+
'RealtimeProtectionEnabled' => 'false'
|
36
|
+
},
|
37
|
+
'protected_settings' => {}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
extension_mapper = Azure::ARM::Compute::Models::VirtualMachineExtension.mapper
|
41
|
+
@compute_mgmt_client.deserialize(extension_mapper, body, 'result.body')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -19,53 +19,66 @@ module Fog
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def get_express_route_circuit_object(circuit_parameters)
|
22
|
+
sku = create_express_route_circuit_sku(circuit_parameters[:sku_name], circuit_parameters[:sku_family], circuit_parameters[:sku_tier])
|
23
|
+
service_provider_prop = create_express_route_service_provider_properties(circuit_parameters[:service_provider_name], circuit_parameters[:peering_location], circuit_parameters[:bandwidth_in_mbps])
|
24
|
+
create_express_route_circuit(service_provider_prop, circuit_parameters[:peerings], circuit_parameters[:circuit_name], circuit_parameters[:location], sku, circuit_parameters[:tags])
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_express_route_circuit_sku(sku_name, sku_family, sku_tier)
|
22
28
|
sku = Azure::ARM::Network::Models::ExpressRouteCircuitSku.new
|
23
|
-
sku.name =
|
24
|
-
sku.family =
|
25
|
-
sku.tier =
|
29
|
+
sku.name = sku_name
|
30
|
+
sku.family = sku_family
|
31
|
+
sku.tier = sku_tier
|
32
|
+
sku
|
33
|
+
end
|
26
34
|
|
35
|
+
def create_express_route_service_provider_properties(service_provider_name, peering_location, bandwidth_in_mbps)
|
27
36
|
service_provider_prop = Azure::ARM::Network::Models::ExpressRouteCircuitServiceProviderProperties.new
|
28
|
-
service_provider_prop.service_provider_name =
|
29
|
-
service_provider_prop.peering_location =
|
30
|
-
service_provider_prop.bandwidth_in_mbps =
|
37
|
+
service_provider_prop.service_provider_name = service_provider_name
|
38
|
+
service_provider_prop.peering_location = peering_location
|
39
|
+
service_provider_prop.bandwidth_in_mbps = bandwidth_in_mbps
|
40
|
+
service_provider_prop
|
41
|
+
end
|
31
42
|
|
43
|
+
def create_express_route_circuit(service_provider_prop, peerings, circuit_name, location, sku, tags)
|
32
44
|
express_route_circuit = Azure::ARM::Network::Models::ExpressRouteCircuit.new
|
33
45
|
express_route_circuit.service_provider_properties = service_provider_prop
|
34
|
-
if
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
express_route_circuit.name = circuit_parameters[:circuit_name]
|
39
|
-
express_route_circuit.location = circuit_parameters[:location]
|
46
|
+
express_route_circuit.peerings = get_circuit_peerings(peerings) if peerings
|
47
|
+
express_route_circuit.name = circuit_name
|
48
|
+
express_route_circuit.location = location
|
40
49
|
express_route_circuit.sku = sku
|
41
|
-
express_route_circuit.tags =
|
42
|
-
|
50
|
+
express_route_circuit.tags = tags if express_route_circuit.tags.nil?
|
43
51
|
express_route_circuit
|
44
52
|
end
|
45
53
|
|
46
54
|
def get_circuit_peerings(peerings)
|
47
55
|
circuit_peerings = []
|
48
56
|
peerings.each do |peering|
|
49
|
-
|
50
|
-
|
51
|
-
circuit_peering.peer_asn = peering[:peer_asn]
|
52
|
-
circuit_peering.primary_peer_address_prefix = peering[:primary_peer_address_prefix]
|
53
|
-
circuit_peering.secondary_peer_address_prefix = peering[:secondary_peer_address_prefix]
|
54
|
-
circuit_peering.vlan_id = peering[:vlan_id]
|
55
|
-
if peering[:peering_type].casecmp(MICROSOFT_PEERING) == 0
|
56
|
-
peering_config = Azure::ARM::Network::Models::ExpressRouteCircuitPeeringConfig.new
|
57
|
-
peering_config.advertised_public_prefixes = peering[:advertised_public_prefixes]
|
58
|
-
peering_config.advertised_public_prefixes_state = peering[:advertised_public_prefix_state]
|
59
|
-
peering_config.customer_asn = peering[:customer_asn]
|
60
|
-
peering_config.routing_registry_name = peering[:routing_registry_name]
|
61
|
-
circuit_peering.microsoft_peering_config = peering_config
|
62
|
-
end
|
63
|
-
|
64
|
-
circuit_peering.name = peering[:name]
|
65
|
-
circuit_peerings.push(circuit_peering)
|
57
|
+
circuit_peering_object = get_circuit_peering_object(peering)
|
58
|
+
circuit_peerings.push(circuit_peering_object)
|
66
59
|
end
|
67
60
|
circuit_peerings
|
68
61
|
end
|
62
|
+
|
63
|
+
def create_express_route_circuit_peering(peering_type, peer_asn, primary_peer_address_prefix, secondary_peer_address_prefix, vlan_id, name)
|
64
|
+
circuit_peering = Azure::ARM::Network::Models::ExpressRouteCircuitPeering.new
|
65
|
+
circuit_peering.peering_type = peering_type
|
66
|
+
circuit_peering.peer_asn = peer_asn
|
67
|
+
circuit_peering.primary_peer_address_prefix = primary_peer_address_prefix
|
68
|
+
circuit_peering.secondary_peer_address_prefix = secondary_peer_address_prefix
|
69
|
+
circuit_peering.vlan_id = vlan_id
|
70
|
+
circuit_peering.name = name
|
71
|
+
circuit_peering
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_express_route_circuit_peering_config(advertised_public_prefixes, advertised_public_prefix_state, customer_asn, routing_registry_name)
|
75
|
+
peering_config = Azure::ARM::Network::Models::ExpressRouteCircuitPeeringConfig.new
|
76
|
+
peering_config.advertised_public_prefixes = advertised_public_prefixes
|
77
|
+
peering_config.advertised_public_prefixes_state = advertised_public_prefix_state
|
78
|
+
peering_config.customer_asn = customer_asn
|
79
|
+
peering_config.routing_registry_name = routing_registry_name
|
80
|
+
peering_config
|
81
|
+
end
|
69
82
|
end
|
70
83
|
|
71
84
|
# Mock class for Network Request
|