fog-azure-rm 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +27 -0
  3. data/CONTRIBUTORS.md +4 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +82 -0
  6. data/lib/fog/azurerm.rb +40 -0
  7. data/lib/fog/azurerm/compute.rb +61 -0
  8. data/lib/fog/azurerm/config.rb +1 -0
  9. data/lib/fog/azurerm/core.rb +12 -0
  10. data/lib/fog/azurerm/credentials.rb +37 -0
  11. data/lib/fog/azurerm/dns.rb +48 -0
  12. data/lib/fog/azurerm/models/compute/availability_set.rb +31 -0
  13. data/lib/fog/azurerm/models/compute/availability_sets.rb +36 -0
  14. data/lib/fog/azurerm/models/compute/server.rb +94 -0
  15. data/lib/fog/azurerm/models/compute/servers.rb +32 -0
  16. data/lib/fog/azurerm/models/dns/record_set.rb +28 -0
  17. data/lib/fog/azurerm/models/dns/record_sets.rb +44 -0
  18. data/lib/fog/azurerm/models/dns/zone.rb +21 -0
  19. data/lib/fog/azurerm/models/dns/zones.rb +30 -0
  20. data/lib/fog/azurerm/models/network/network_interface.rb +34 -0
  21. data/lib/fog/azurerm/models/network/network_interfaces.rb +35 -0
  22. data/lib/fog/azurerm/models/network/public_ip.rb +34 -0
  23. data/lib/fog/azurerm/models/network/public_ips.rb +46 -0
  24. data/lib/fog/azurerm/models/network/subnet.rb +34 -0
  25. data/lib/fog/azurerm/models/network/subnets.rb +37 -0
  26. data/lib/fog/azurerm/models/network/virtual_network.rb +30 -0
  27. data/lib/fog/azurerm/models/network/virtual_networks.rb +42 -0
  28. data/lib/fog/azurerm/models/resources/resource_group.rb +21 -0
  29. data/lib/fog/azurerm/models/resources/resource_groups.rb +28 -0
  30. data/lib/fog/azurerm/models/storage/storage_account.rb +37 -0
  31. data/lib/fog/azurerm/models/storage/storage_accounts.rb +45 -0
  32. data/lib/fog/azurerm/network.rb +67 -0
  33. data/lib/fog/azurerm/requests/compute/create_availability_set.rb +45 -0
  34. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +100 -0
  35. data/lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb +26 -0
  36. data/lib/fog/azurerm/requests/compute/delete_availability_set.rb +26 -0
  37. data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +26 -0
  38. data/lib/fog/azurerm/requests/compute/generalize_virtual_machine.rb +26 -0
  39. data/lib/fog/azurerm/requests/compute/get_virtual_machine.rb +24 -0
  40. data/lib/fog/azurerm/requests/compute/list_availability_sets.rb +24 -0
  41. data/lib/fog/azurerm/requests/compute/list_available_sizes_for_virtual_machine.rb +24 -0
  42. data/lib/fog/azurerm/requests/compute/list_virtual_machines.rb +64 -0
  43. data/lib/fog/azurerm/requests/compute/power_off_virtual_machine.rb +26 -0
  44. data/lib/fog/azurerm/requests/compute/redeploy_virtual_machine.rb +26 -0
  45. data/lib/fog/azurerm/requests/compute/restart_virtual_machine.rb +26 -0
  46. data/lib/fog/azurerm/requests/compute/start_virtual_machine.rb +26 -0
  47. data/lib/fog/azurerm/requests/dns/check_for_zone.rb +39 -0
  48. data/lib/fog/azurerm/requests/dns/create_record_set.rb +61 -0
  49. data/lib/fog/azurerm/requests/dns/create_zone.rb +47 -0
  50. data/lib/fog/azurerm/requests/dns/delete_record_set.rb +38 -0
  51. data/lib/fog/azurerm/requests/dns/delete_zone.rb +38 -0
  52. data/lib/fog/azurerm/requests/dns/get_records_from_record_set.rb +57 -0
  53. data/lib/fog/azurerm/requests/dns/list_record_sets.rb +44 -0
  54. data/lib/fog/azurerm/requests/dns/list_zones.rb +52 -0
  55. data/lib/fog/azurerm/requests/network/check_for_public_ip.rb +27 -0
  56. data/lib/fog/azurerm/requests/network/check_for_virtual_network.rb +27 -0
  57. data/lib/fog/azurerm/requests/network/create_network_interface.rb +52 -0
  58. data/lib/fog/azurerm/requests/network/create_public_ip.rb +28 -0
  59. data/lib/fog/azurerm/requests/network/create_subnet.rb +30 -0
  60. data/lib/fog/azurerm/requests/network/create_virtual_network.rb +80 -0
  61. data/lib/fog/azurerm/requests/network/delete_network_interface.rb +27 -0
  62. data/lib/fog/azurerm/requests/network/delete_public_ip.rb +27 -0
  63. data/lib/fog/azurerm/requests/network/delete_subnet.rb +27 -0
  64. data/lib/fog/azurerm/requests/network/delete_virtual_network.rb +27 -0
  65. data/lib/fog/azurerm/requests/network/list_network_interfaces.rb +32 -0
  66. data/lib/fog/azurerm/requests/network/list_public_ips.rb +32 -0
  67. data/lib/fog/azurerm/requests/network/list_subnets.rb +30 -0
  68. data/lib/fog/azurerm/requests/network/list_virtual_networks.rb +29 -0
  69. data/lib/fog/azurerm/requests/resources/create_resource_group.rb +27 -0
  70. data/lib/fog/azurerm/requests/resources/delete_resource_group.rb +25 -0
  71. data/lib/fog/azurerm/requests/resources/list_resource_groups.rb +28 -0
  72. data/lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb +33 -0
  73. data/lib/fog/azurerm/requests/storage/create_storage_account.rb +33 -0
  74. data/lib/fog/azurerm/requests/storage/delete_storage_account.rb +27 -0
  75. data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +25 -0
  76. data/lib/fog/azurerm/requests/storage/list_storage_accounts.rb +28 -0
  77. data/lib/fog/azurerm/resources.rb +48 -0
  78. data/lib/fog/azurerm/storage.rb +51 -0
  79. data/lib/fog/azurerm/version.rb +5 -0
  80. metadata +278 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 086b6f020bf8dccb6fe47578df34eacfac015719
4
+ data.tar.gz: 584f0ad3a486c34686af2cdfc7e470c0d730bd77
5
+ SHA512:
6
+ metadata.gz: 8b228877689c27b572c230aa1eb60f75adae338133ff3b902eca215fc1dec4f8e798c1a780621add6c8908b77cd5fb4b5fc4fae1f6d0fd13a0b2b96530a6f490
7
+ data.tar.gz: 8d6ad541e4b35af0f57e7d7fcc4036835774086f94360325beeb367697c5585f01041430d5d81ef2df12e61e0bb83b4a5d9ccb9f1ee4a5a762e9831a9605a48b
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,27 @@
1
+ ## Getting Involved
2
+
3
+ New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
4
+
5
+ ### Coding
6
+
7
+ * Pick a task:
8
+ * Offer feedback on open [pull requests](https://github.com/Confiz/fog-azure-rm/pulls).
9
+ * Review open [issues](https://github.com/Confiz/fog-azure-rm/issues) for things to help on.
10
+ * [Create an issue](https://github.com/Confiz/fog-azure-rm/issues/new) to start a discussion on additions or features.
11
+ * Fork the project, add your changes and tests to cover them in a topic branch.
12
+ * [Fork](https://github.com/Confiz/fog-azure-rm/fork)
13
+ * Create your feature branch (`git checkout -b my-new-feature`)
14
+ * Commit your changes (`git commit -am 'Add some feature'`)
15
+ * Push to the branch (`git push origin my-new-feature`)
16
+ * Create a new pull request
17
+ * Commit your changes and rebase against `Confiz/fog-azure-rm` to ensure everything is up to date.
18
+ * [Submit a pull request](https://github.com/Confiz/fog-azure-rm/compare/).
19
+
20
+ ### Non-Coding
21
+
22
+ * Offer feedback on open [issues](https://github.com/Confiz/fog-azure-rm/issues).
23
+ * Organize or volunteer at events.
24
+ * Write and help edit [documentation](https://github.com/Confiz/fog-azure-rm/tree/develop/lib/fog/azurerm/docs).
25
+
26
+ ## Testing
27
+
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,4 @@
1
+
2
+ * Adnan Khalil <adnan.khalil@confiz.com>
3
+ * Samawia Moin <samawia.moin@confiz.com>
4
+ * Shaffan Chaudhry <shaffan.chaudhry@confiz.com>
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2015 [CONTRIBUTORS.md](https://github.com/Confiz/fog-azure-rm/blob/develop/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Fog Azure Resource Manager
2
+
3
+ This document describes how to get started with Fog using Microsoft Azure as a cloud resource management services provider.
4
+
5
+ ## Pre-requisites
6
+
7
+ * Fog supports Ruby version 2.0.0 or later
8
+ * Fog requires Azure SDK For Ruby version 0.2.1.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'fog-azure-rm'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install fog-azure-rm
25
+
26
+
27
+ ## Usage
28
+
29
+ You can use this gem against the Microsoft Azure Resource Manager Services in the cloud. Of course, to use the Microsoft Azure Resource Manager Services in the cloud, you need to first [create a Microsoft Azure account](http://www.azure.com/en-us/pricing/free-trial/).
30
+
31
+
32
+ ### Authentication
33
+
34
+ The next step to use this gem, is authentication and permissioning. It is important to get familiar with this concept. For a reference on setting up a service principal from the command line see
35
+ [Authenticating a service principal with Azure Resource Manager](http://aka.ms/cli-service-principal) or
36
+ [Unattended Authentication](http://aka.ms/auth-unattended). For a more robust explanation of authentication in Azure,
37
+ see [Developer’s guide to auth with Azure Resource Manager API](http://aka.ms/arm-auth-dev-guide).
38
+
39
+ After creating the service principal, you should have three pieces of information, a client id (GUID), client secret
40
+ (string) and tenant id (GUID).
41
+
42
+ ### Compute
43
+
44
+ Fog-AzureRM for compute includes implementaion of Virtual Machines and Availability Sets. Readme for the usage of [Compute](https://github.com/Confiz/fog-azure-rm/blob/develop/lib/fog/azurerm/docs/compute.md) module.
45
+
46
+ ### Resources
47
+
48
+ Fog-AzureRM for resources includes implementaion of Resource Groups. Readme for the usage of [Resources](https://github.com/Confiz/fog-azure-rm/blob/develop/lib/fog/azurerm/docs/resources.md) module.
49
+
50
+ ### DNS
51
+
52
+ Fog-AzureRM for dns includes implementaion of Record sets and Zones. Readme for the usage of [DNS](https://github.com/Confiz/fog-azure-rm/blob/develop/lib/fog/azurerm/docs/dns.md) module.
53
+
54
+ ### Network
55
+
56
+ Fog-AzureRM for network includes implementaion of Network Interfaces, Public IPs, Subnets and Virtual Networks. Readme for the usage of [Network](https://github.com/Confiz/fog-azure-rm/blob/develop/lib/fog/azurerm/docs/network.md) module.
57
+
58
+ ### Storage
59
+
60
+ Fog-AzureRM for storage includes implementaion of Storage Accounts. Readme for the usage of [Storage](https://github.com/Confiz/fog-azure-rm/blob/develop/lib/fog/azurerm/docs/storage.md) module.
61
+
62
+ ## Supported Services
63
+
64
+ Use following command for the complete list of services, Fog provides for Azure Resource Manager.
65
+
66
+ ```ruby
67
+ Fog::AzureRM.services
68
+ ```
69
+
70
+
71
+ ## Contributing
72
+
73
+ See [CONTRIBUTING.md](https://github.com/Confiz/fog-azure-rm/blob/develop/CONTRIBUTING.md) in this repository.
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+
79
+
80
+
81
+
82
+
@@ -0,0 +1,40 @@
1
+ require 'ms_rest_azure'
2
+ require 'rest_client'
3
+ require 'erb'
4
+ require 'fog/azurerm/config'
5
+ require 'fog/azurerm/version'
6
+ require 'fog/azurerm/core'
7
+ require 'fog/azurerm/dns'
8
+ require 'fog/azurerm/resources'
9
+ require 'fog/azurerm/storage'
10
+ require 'fog/azurerm/network'
11
+ require 'fog/azurerm/compute'
12
+
13
+
14
+ module Fog
15
+ module AzureRM
16
+ def self.services
17
+ begin
18
+ array_of_services = []
19
+ ENV['BUNDLE_GEM'] = File.expand_path('../../lib', File.dirname(__FILE__))
20
+ gem_path = ENV['BUNDLE_GEM']
21
+ files = Dir.entries(File.join(gem_path,'/fog/azurerm')).select {|f| !File.directory? f}
22
+ files.each do |file|
23
+ next if file == "config.rb"
24
+ next if file == "core.rb"
25
+ next if file == "credentials.rb"
26
+ next if file == "docs"
27
+ next if file == "models"
28
+ next if file == "requests"
29
+ next if file == "version.rb"
30
+ array_of_services.push((file.split(".").first).upcase)
31
+ end
32
+ array_of_services
33
+ rescue => e
34
+ Fog::Logger.warning(e.message)
35
+ raise e.message
36
+ # typically occurs if folder_to_count does not exist
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,61 @@
1
+ require 'fog/azurerm/core'
2
+ # rubocop:disable LineLength
3
+ module Fog
4
+ module Compute
5
+ # This class registers models, requests and collections
6
+ class AzureRM < Fog::Service
7
+ requires :tenant_id
8
+ requires :client_id
9
+ requires :client_secret
10
+ requires :subscription_id
11
+
12
+ request_path 'fog/azurerm/requests/compute'
13
+ request :create_availability_set
14
+ request :delete_availability_set
15
+ request :list_availability_sets
16
+ request :create_virtual_machine
17
+ request :delete_virtual_machine
18
+ request :get_virtual_machine
19
+ request :list_virtual_machines
20
+ request :list_available_sizes_for_virtual_machine
21
+ request :generalize_virtual_machine
22
+ request :deallocate_virtual_machine
23
+ request :power_off_virtual_machine
24
+ request :redeploy_virtual_machine
25
+ request :restart_virtual_machine
26
+ request :start_virtual_machine
27
+
28
+ model_path 'fog/azurerm/models/compute'
29
+ model :availability_set
30
+ collection :availability_sets
31
+ model :server
32
+ collection :servers
33
+ # This class provides the mock implementation for unit tests.
34
+ class Mock
35
+ def initialize(_options = {})
36
+ begin
37
+ require 'azure_mgmt_compute'
38
+ rescue LoadError => e
39
+ retry if require('rubygems')
40
+ raise e.message
41
+ end
42
+ end
43
+ end
44
+ # This class provides the actual implemention for service calls.
45
+ class Real
46
+ def initialize(options)
47
+ begin
48
+ require 'azure_mgmt_compute'
49
+ rescue LoadError => e
50
+ retry if require('rubygems')
51
+ raise e.message
52
+ end
53
+
54
+ credentials = Fog::Credentials::AzureRM.get_credentials(options[:tenant_id], options[:client_id], options[:client_secret])
55
+ @compute_mgmt_client = ::Azure::ARM::Compute::ComputeManagementClient.new(credentials)
56
+ @compute_mgmt_client.subscription_id = options[:subscription_id]
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1 @@
1
+ AZURE_RESOURCE = 'https://management.azure.com'
@@ -0,0 +1,12 @@
1
+ require 'fog/core'
2
+
3
+ module Fog
4
+ module AzureRM
5
+ extend Fog::Provider
6
+ service(:resources, 'Resources')
7
+ service(:dns, 'DNS')
8
+ service(:storage, 'Storage')
9
+ service(:network, 'Network')
10
+ service(:compute, 'Compute')
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ module Credentials
3
+ class AzureRM
4
+
5
+ def self.get_credentials(tenant_id, client_id, client_secret)
6
+ if @credentials.nil? || new_client(tenant_id, client_id, client_secret)
7
+ get_new_credentials(tenant_id, client_id, client_secret)
8
+ else
9
+ @credentials
10
+ end
11
+ end
12
+
13
+ def self.get_token(tenant_id, client_id, client_secret)
14
+ get_credentials(tenant_id, client_id, client_secret) if @credentials.nil?
15
+ @token_provider.get_authentication_header
16
+ end
17
+
18
+ def self.get_new_credentials(tenant_id, client_id, client_secret)
19
+ @tenant_id = tenant_id
20
+ @client_id = client_id
21
+ @client_secret = client_secret
22
+ @token_provider = MsRestAzure::ApplicationTokenProvider.new(@tenant_id, @client_id, @client_secret)
23
+ @credentials = MsRest::TokenCredentials.new(@token_provider)
24
+ @credentials
25
+ end
26
+
27
+ def self.new_client(tenant_id, client_id, client_secret)
28
+ @tenant_id != tenant_id ||
29
+ @client_id != client_id ||
30
+ @client_secret != client_secret
31
+ end
32
+
33
+ private_class_method :get_new_credentials
34
+ private_class_method :new_client
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,48 @@
1
+ require 'fog/azurerm/core'
2
+ require 'fog/azurerm/credentials'
3
+
4
+ module Fog
5
+ module DNS
6
+ class AzureRM < Fog::Service
7
+ requires :tenant_id
8
+ requires :client_id
9
+ requires :client_secret
10
+ requires :subscription_id
11
+
12
+ request_path 'fog/azurerm/requests/dns'
13
+ request :create_zone
14
+ request :delete_zone
15
+ request :check_for_zone
16
+ request :list_zones
17
+ request :create_record_set
18
+ request :delete_record_set
19
+ request :list_record_sets
20
+ request :get_records_from_record_set
21
+
22
+ model_path 'fog/azurerm/models/dns'
23
+ model :zone
24
+ collection :zones
25
+ model :record_set
26
+ collection :record_sets
27
+
28
+ class Mock
29
+ def initialize(options = {})
30
+ end
31
+ end
32
+
33
+ class Real
34
+ def initialize(options)
35
+ @tenant_id = options[:tenant_id]
36
+ @client_id = options[:client_id]
37
+ @client_secret = options[:client_secret]
38
+ @subscription_id = options[:subscription_id]
39
+ @resources = Fog::Resources::AzureRM.new(
40
+ tenant_id: options[:tenant_id],
41
+ client_id: options[:client_id],
42
+ client_secret: options[:client_secret],
43
+ subscription_id: options[:subscription_id])
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,31 @@
1
+ # rubocop:disable MethodLength
2
+ # rubocop:disable AbcSize
3
+ module Fog
4
+ module Compute
5
+ class AzureRM
6
+ # This class is giving implementation of create/save and
7
+ # delete/destroy for Availability Set.
8
+ class AvailabilitySet < Fog::Model
9
+ attribute :id
10
+ identity :name
11
+ attribute :type
12
+ attribute :location
13
+ attribute :tags
14
+ attribute :resource_group
15
+ attribute :properties
16
+
17
+ def save
18
+ requires :name
19
+ requires :location
20
+ requires :resource_group
21
+ # need to create the availability set
22
+ service.create_availability_set(resource_group, name, location)
23
+ end
24
+
25
+ def destroy
26
+ service.delete_availability_set(resource_group, name)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/azurerm/models/compute/availability_set'
3
+ # rubocop:disable MethodLength
4
+ module Fog
5
+ module Compute
6
+ class AzureRM
7
+ # This class is giving implementation of all/list, get and
8
+ # check name availability for storage account.
9
+ class AvailabilitySets < Fog::Collection
10
+ model Fog::Compute::AzureRM::AvailabilitySet
11
+ attribute :resource_group
12
+ def all
13
+ accounts = []
14
+ requires :resource_group
15
+ list_of_availability_sets =
16
+ service.list_availability_sets(resource_group)
17
+ unless list_of_availability_sets.nil?
18
+ list_of_availability_sets.each do |account|
19
+ hash = {}
20
+ account.instance_variables.each do |var|
21
+ hash[var.to_s.delete('@')] = account.instance_variable_get(var)
22
+ end
23
+ hash['resource_group'] = resource_group
24
+ accounts << hash
25
+ end
26
+ end
27
+ load(accounts)
28
+ end
29
+
30
+ def get(resource_group, identity)
31
+ all.find { |as| as.resource_group == resource_group && as.name == identity }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,94 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class is giving implementation of create/save and
5
+ # delete/destroy for Virtual Machine.
6
+ class Server < Fog::Model
7
+ attribute :id
8
+ identity :name
9
+ attribute :location
10
+ attribute :resource_group
11
+ attribute :vm_size
12
+ attribute :storage_account_name
13
+ attribute :os_disk_name
14
+ attribute :vhd_uri
15
+ attribute :publisher
16
+ attribute :offer
17
+ attribute :sku
18
+ attribute :version
19
+ attribute :username
20
+ attribute :password
21
+ attribute :disable_password_authentication
22
+ attribute :ssh_key_path
23
+ attribute :ssh_key_data
24
+ attribute :network_interface_card_id
25
+ attribute :availability_set_id
26
+
27
+ def self.parse(vm)
28
+ hash = {}
29
+ hash['id'] = vm['id']
30
+ hash['name'] = vm['name']
31
+ hash['location'] = vm['location']
32
+ hash['resource_group'] = vm['id'].split('/')[4]
33
+ hash['vm_size'] = vm['properties']['hardwareProfile']['vmSize']
34
+ hash['os_disk_name'] = vm['properties']['storageProfile']['osDisk']['name']
35
+ hash['vhd_uri'] = vm['properties']['storageProfile']['osDisk']['vhd']['uri']
36
+ hash['publisher'] = vm['properties']['storageProfile']['imageReference']['publisher']
37
+ hash['offer'] = vm['properties']['storageProfile']['imageReference']['offer']
38
+ hash['sku'] = vm['properties']['storageProfile']['imageReference']['sku']
39
+ hash['version'] = vm['properties']['storageProfile']['imageReference']['version']
40
+ hash['username'] = vm['properties']['osProfile']['adminUsername']
41
+ hash['disable_password_authentication'] = vm['properties']['osProfile']['linuxConfiguration']['disablePasswordAuthentication']
42
+ hash['network_interface_card_id'] = vm['properties']['networkProfile']['networkInterfaces'][0]['id']
43
+ hash['availability_set_id'] = vm['properties']['availabilitySet']['id'] unless vm['properties']['availabilitySet'].nil?
44
+ hash
45
+ end
46
+
47
+ def save
48
+ requires :name, :location, :resource_group, :vm_size, :storage_account_name,
49
+ :username, :password, :disable_password_authentication,
50
+ :network_interface_card_id, :publisher, :offer, :sku, :version
51
+
52
+ ssh_key_path = "/home/#{username}/.ssh/authorized_keys" unless ssh_key_data.nil?
53
+ vm = service.create_virtual_machine(name, location, resource_group, vm_size, storage_account_name,
54
+ username, password, disable_password_authentication,
55
+ ssh_key_path, ssh_key_data, network_interface_card_id,
56
+ availability_set_id, publisher, offer, sku, version)
57
+ merge_attributes(Fog::Compute::AzureRM::Server.parse(vm))
58
+ end
59
+
60
+ def destroy
61
+ service.delete_virtual_machine(resource_group, name)
62
+ end
63
+
64
+ def generalize
65
+ service.generalize_virtual_machine(resource_group, name)
66
+ end
67
+
68
+ def power_off
69
+ service.power_off_virtual_machine(resource_group, name)
70
+ end
71
+
72
+ def start
73
+ service.start_virtual_machine(resource_group, name)
74
+ end
75
+
76
+ def restart
77
+ service.restart_virtual_machine(resource_group, name)
78
+ end
79
+
80
+ def deallocate
81
+ service.deallocate_virtual_machine(resource_group, name)
82
+ end
83
+
84
+ def redeploy
85
+ service.redeploy_virtual_machine(resource_group, name)
86
+ end
87
+
88
+ def list_available_sizes
89
+ service.list_available_sizes_for_virtual_machine(resource_group, name)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end