azure-armrest 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/CHANGES +2 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/README.md +78 -0
- data/Rakefile +20 -0
- data/azure-armrest.gemspec +33 -0
- data/lib/azure-armrest.rb +1 -0
- data/lib/azure/armrest.rb +32 -0
- data/lib/azure/armrest/armrest_manager.rb +402 -0
- data/lib/azure/armrest/availability_set_manager.rb +50 -0
- data/lib/azure/armrest/event_manager.rb +32 -0
- data/lib/azure/armrest/storage_account_manager.rb +165 -0
- data/lib/azure/armrest/subnet_manager.rb +59 -0
- data/lib/azure/armrest/version.rb +5 -0
- data/lib/azure/armrest/virtual_machine_extension_manager.rb +59 -0
- data/lib/azure/armrest/virtual_machine_image_manager.rb +135 -0
- data/lib/azure/armrest/virtual_machine_manager.rb +359 -0
- data/lib/azure/armrest/virtual_network_manager.rb +62 -0
- metadata +157 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
# Azure namespace
|
2
|
+
module Azure
|
3
|
+
# Armrest namespace
|
4
|
+
module Armrest
|
5
|
+
# Base class for managing availability sets.
|
6
|
+
class AvailabilitySetManager < ArmrestManager
|
7
|
+
|
8
|
+
# Create and return a new AvailabilitySetManager (ASM) instance. Most
|
9
|
+
# methods for an ASM instance will return one or more AvailabilitySet
|
10
|
+
# instances.
|
11
|
+
#
|
12
|
+
def initialize(options = {})
|
13
|
+
super
|
14
|
+
|
15
|
+
@base_url += "resourceGroups/#{@resource_group}/"
|
16
|
+
@base_url += "providers/Microsoft.Compute/availabilitySets"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Creates a new availability set.
|
20
|
+
#
|
21
|
+
# TODO: The current documentation doesn't seem to list all the possible
|
22
|
+
# options at this time.
|
23
|
+
#--
|
24
|
+
def create(set_name, options = {})
|
25
|
+
url = @uri + "#{set_name}?api-version=#{api_version}"
|
26
|
+
url
|
27
|
+
end
|
28
|
+
|
29
|
+
alias update create
|
30
|
+
|
31
|
+
# Deletes the +set_name+ availability set.
|
32
|
+
def delete(set_name)
|
33
|
+
url = @uri + "#{set_name}?api-version=#{api_version}"
|
34
|
+
url
|
35
|
+
end
|
36
|
+
|
37
|
+
# Retrieves the options of an availability set.
|
38
|
+
def get(set_name)
|
39
|
+
url = @uri + "#{set_name}?api-version=#{api_version}"
|
40
|
+
url
|
41
|
+
end
|
42
|
+
|
43
|
+
# List availability sets.
|
44
|
+
def list
|
45
|
+
url = @uri + "?api-version=#{api_version}"
|
46
|
+
url
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
class EventManager < ArmrestManager
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
super
|
7
|
+
|
8
|
+
@base_url += "providers/microsoft.insights/eventtypes/management/values"
|
9
|
+
@base_url += "?api-version=#{@api_version}"
|
10
|
+
end
|
11
|
+
|
12
|
+
# check what data type the event channel is
|
13
|
+
|
14
|
+
def get_rg_events(starttime, endtime, channels, rg_name )
|
15
|
+
@uri += build_filter += " and resourceGroupName eq '#{rg_name}'"
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_resource_events(starttime, endtime, channels, resource_uri )
|
19
|
+
@uri += build_filter += " and resourceUri eq '#{resource_uri}'"
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_filter(starttime, endtime, channels)
|
23
|
+
"$filter=eventTimestamp ge '#{starttime}' and eventTimestamp le '#{endtime}'
|
24
|
+
and eventChannels eq '#{channels}'"
|
25
|
+
end
|
26
|
+
|
27
|
+
def select_properties(property_names)
|
28
|
+
"&$select={property_names}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
# Class for managing storage accounts.
|
4
|
+
class StorageAccountManager < ArmrestManager
|
5
|
+
|
6
|
+
# Valid account types for the create or update method.
|
7
|
+
VALID_ACCOUNT_TYPES = %w[
|
8
|
+
Standard_LRS
|
9
|
+
Standard_ZRS
|
10
|
+
Standard_GRS
|
11
|
+
Standard_RAGRS
|
12
|
+
]
|
13
|
+
|
14
|
+
# Creates and returns a new StorageAccountManager (SAM) instance. Most
|
15
|
+
# methods for a SAM instance will return a StorageAccount object.
|
16
|
+
def initialize(options = {})
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return information for the given storage account name for the
|
21
|
+
# provided +group+. If no group is specified, it will use the
|
22
|
+
# group set in the constructor.
|
23
|
+
#
|
24
|
+
# Example:
|
25
|
+
#
|
26
|
+
# sam.get('portalvhdstjn1ty0dlc2dg')
|
27
|
+
# sam.get('portalvhdstjn1ty0dlc2dg', 'Default-Storage-CentralUS')
|
28
|
+
#
|
29
|
+
def get(account_name, group = @resource_group)
|
30
|
+
set_default_subscription
|
31
|
+
|
32
|
+
raise ArgumentError, "must specify resource group" unless group
|
33
|
+
|
34
|
+
@api_version = '2014-06-01'
|
35
|
+
url = build_url(@subscription_id, group, account_name)
|
36
|
+
|
37
|
+
JSON.parse(rest_get(url))
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns a list of available storage accounts for the given subscription
|
41
|
+
# for the provided +group+, or all resource groups if none is provided.
|
42
|
+
#
|
43
|
+
def list(group = @resource_group)
|
44
|
+
if group
|
45
|
+
@api_version = '2014-06-01'
|
46
|
+
url = build_url(@subscription_id, group)
|
47
|
+
JSON.parse(rest_get(url))['value'].first
|
48
|
+
else
|
49
|
+
array = []
|
50
|
+
threads = []
|
51
|
+
|
52
|
+
resource_groups.each do |group|
|
53
|
+
@api_version = '2014-06-01' # Must be set after resource_groups call
|
54
|
+
url = build_url(@subscription_id, group['name'])
|
55
|
+
|
56
|
+
threads << Thread.new do
|
57
|
+
result = JSON.parse(rest_get(url))['value'].first
|
58
|
+
array << result if result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
threads.each(&:join)
|
63
|
+
|
64
|
+
array
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Creates a new storage account, or updates an existing account with the
|
69
|
+
# specified parameters. The possible parameters are:
|
70
|
+
#
|
71
|
+
# - :account_name
|
72
|
+
# Required. The name of the storage account within the specified
|
73
|
+
# resource stack. Must be 3-24 alphanumeric lowercase characters.
|
74
|
+
#
|
75
|
+
# - :validating
|
76
|
+
# Optional. Set to 'nameAvailability' to indicate that the account
|
77
|
+
# name must be checked for global availability.
|
78
|
+
#
|
79
|
+
# - :location
|
80
|
+
# Required: One of the Azure geo regions, e.g. 'West US'.
|
81
|
+
#
|
82
|
+
# - :tags
|
83
|
+
# A hash of tags to describe the resource. You may have a maximum of
|
84
|
+
# 10 tags, and each key has a max size of 128 characters, and each
|
85
|
+
# value has a max size of 256 characters.
|
86
|
+
#
|
87
|
+
# -:properties
|
88
|
+
# - :account_type
|
89
|
+
# - :custom_domains
|
90
|
+
# - :custom_domain
|
91
|
+
# - :name
|
92
|
+
# - :use_subdomain_name
|
93
|
+
#--
|
94
|
+
# PUT
|
95
|
+
#
|
96
|
+
def create(option = {})
|
97
|
+
#account_name = options.fetch(:account_name)
|
98
|
+
#location = options.fetch(:location)
|
99
|
+
validating = options[:validating]
|
100
|
+
#tags = options[:tags]
|
101
|
+
|
102
|
+
url = @uri + "/#{account_name}"
|
103
|
+
|
104
|
+
if validating
|
105
|
+
url += "?validating=nameAvailability"
|
106
|
+
end
|
107
|
+
|
108
|
+
url
|
109
|
+
end
|
110
|
+
|
111
|
+
alias update create
|
112
|
+
|
113
|
+
# Delete the given storage account name.
|
114
|
+
def delete(account_name)
|
115
|
+
url = @uri + "/#{account_name}?api-version=#{api_version}"
|
116
|
+
url
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
# Returns the primary and secondary access keys for the given
|
122
|
+
# storage account.
|
123
|
+
#--
|
124
|
+
# POST
|
125
|
+
#
|
126
|
+
def list_account_keys(account_name)
|
127
|
+
url = @uri + "/#{account_name}/listKeys?api-version=#{api_version}"
|
128
|
+
url
|
129
|
+
end
|
130
|
+
|
131
|
+
# Regenerates the primary and secondary access keys for the given
|
132
|
+
# storage account.
|
133
|
+
#--
|
134
|
+
# POST
|
135
|
+
def regenerate_storage_account_keys(account_name)
|
136
|
+
url = @uri + "/#{account_name}/regenerateKey?api-version=#{api_version}"
|
137
|
+
url
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
# If no default subscription is set, then use the first one found.
|
143
|
+
def set_default_subscription
|
144
|
+
@subscription_id ||= subscriptions.first['subscriptionId']
|
145
|
+
end
|
146
|
+
|
147
|
+
# Builds a URL based on subscription_id an resource_group and any other
|
148
|
+
# arguments provided, and appends it with the api-version.
|
149
|
+
def build_url(subscription_id, resource_group, *args)
|
150
|
+
url = File.join(
|
151
|
+
Azure::Armrest::COMMON_URI,
|
152
|
+
subscription_id,
|
153
|
+
'resourceGroups',
|
154
|
+
resource_group,
|
155
|
+
'providers',
|
156
|
+
'Microsoft.ClassicStorage',
|
157
|
+
'storageAccounts',
|
158
|
+
)
|
159
|
+
|
160
|
+
url = File.join(url, *args) unless args.empty?
|
161
|
+
url << "?api-version=#{@api_version}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Azure namespace
|
2
|
+
module Azure
|
3
|
+
# Armrest namespace
|
4
|
+
module Armrest
|
5
|
+
# Base class for managing subnets
|
6
|
+
class SubnetManager < VirtualNetworkManager
|
7
|
+
|
8
|
+
# Create and return a new SubnetManager instance. Most methods for a
|
9
|
+
# SubnetManager instance will return one or Subnet instances.
|
10
|
+
#
|
11
|
+
def initialize(options = {})
|
12
|
+
super
|
13
|
+
|
14
|
+
@base_url += "/subnets"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a new subnet using the given +options+.
|
18
|
+
#
|
19
|
+
# The possible options are:
|
20
|
+
#
|
21
|
+
# :name
|
22
|
+
# :id
|
23
|
+
# :location
|
24
|
+
# :tags
|
25
|
+
# :etag
|
26
|
+
# :properties
|
27
|
+
# :provisioning_state
|
28
|
+
# :address_prefixes
|
29
|
+
# :dhcp_options
|
30
|
+
# :dns_servers
|
31
|
+
# :ip_configurations
|
32
|
+
#--
|
33
|
+
def create(subnet_name, options = {})
|
34
|
+
@uri += "/#{subnet_name}?api-version=#{api_version}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Deletes the given subnet.
|
38
|
+
def delete(subnet_name)
|
39
|
+
@uri += "/#{subnet_name}?api-version=#{api_version}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Retrieves information for the given subnet.
|
43
|
+
def get(subnet_name)
|
44
|
+
@uri += "/#{subnet_name}?api-version=#{api_version}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# List available subnets.
|
48
|
+
def list
|
49
|
+
@uri += "?api-version=#{api_version}"
|
50
|
+
end
|
51
|
+
|
52
|
+
# Patch an existing subnet. This is similar to a create/update
|
53
|
+
# but the available options are more limited.
|
54
|
+
def patch(subnet_name, options = {})
|
55
|
+
@uri += "?api-version=#{api_version}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Azure namespace
|
2
|
+
module Azure
|
3
|
+
# Armrest namespace
|
4
|
+
module Armrest
|
5
|
+
# Base class for managing virtual machine extensions
|
6
|
+
class VirtualMachineExtensionManager < VirtualMachineManager
|
7
|
+
|
8
|
+
# Creates a new virtual machine extension for +vmname+ with the given
|
9
|
+
# +extension_name+, and the given +options+. Possible options are:
|
10
|
+
#
|
11
|
+
# :tags - Optional. A list of key value pairs. Max 10 pairs.
|
12
|
+
# :publisher - Required. Name of extension publisher.
|
13
|
+
# :type - Required. The type of extension.
|
14
|
+
# :type_handler_version - Required. Specifies the extension version.
|
15
|
+
# :settings - Optional. Public configuration that does not require encryption.
|
16
|
+
# :protected_settings - Optional. Private configuration that is encrypted.
|
17
|
+
#
|
18
|
+
def create(vmname, extension_name, options = {})
|
19
|
+
#publisher = options.fetch(:publisher)
|
20
|
+
#type = options.fetch(:type)
|
21
|
+
#type_handler_version = options.fetch(:type_handler_version)
|
22
|
+
|
23
|
+
url = @uri + "/#{vmname}/extensions/#{extension_name}?#{api_version}"
|
24
|
+
url
|
25
|
+
end
|
26
|
+
|
27
|
+
alias update create
|
28
|
+
|
29
|
+
# Delete the given +extension_name+ for +vmname+.
|
30
|
+
#--
|
31
|
+
# DELETE
|
32
|
+
#
|
33
|
+
def delete(vmname, extension_name)
|
34
|
+
url = @uri + "/#{vmname}/extensions/#{extension_name}?#{api_version}"
|
35
|
+
url
|
36
|
+
end
|
37
|
+
|
38
|
+
# Retrieves the settings of an extension. If the +instance_view+ option
|
39
|
+
# is true, it will retrieve instance view information instead.
|
40
|
+
#--
|
41
|
+
# GET
|
42
|
+
#
|
43
|
+
def get(vmname, instance_view = false)
|
44
|
+
url = @uri + "/#{vmname}/extensions/#{extension_name}?"
|
45
|
+
url += "$expand=instanceView," if instance_view
|
46
|
+
url += "#{api_version}"
|
47
|
+
url
|
48
|
+
end
|
49
|
+
|
50
|
+
# Retrieves a list of extensions on the VM.
|
51
|
+
def list(vmname, instance_view = false)
|
52
|
+
url = @uri + "/#{vmname}/extensions"
|
53
|
+
url += "$expand=instanceView," if instance_view
|
54
|
+
url += "#{api_version}"
|
55
|
+
url
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# Azure namespace
|
2
|
+
module Azure
|
3
|
+
# Armrest namespace
|
4
|
+
module Armrest
|
5
|
+
# Base class for managing virtual machine images
|
6
|
+
class VirtualMachineImageManager < ArmrestManager
|
7
|
+
# The location used in requests when gathering VM image information.
|
8
|
+
attr_accessor :location
|
9
|
+
|
10
|
+
# The provider used in requests when gathering VM image information.
|
11
|
+
attr_reader :provider
|
12
|
+
|
13
|
+
# The publisher used in requests when gathering VM image information.
|
14
|
+
attr_accessor :publisher
|
15
|
+
|
16
|
+
# Create and return a new VirtualMachineImageManager (VMIM) instance.
|
17
|
+
#
|
18
|
+
# This subclass accepts the additional :location, :provider, and
|
19
|
+
# :publisher options as well. The default provider is set to
|
20
|
+
# 'Microsoft.Compute'.
|
21
|
+
#
|
22
|
+
def initialize(options = {})
|
23
|
+
super
|
24
|
+
|
25
|
+
@location = options[:location]
|
26
|
+
@provider = options[:provider] || 'Microsoft.Compute'
|
27
|
+
@publisher = options[:publisher]
|
28
|
+
|
29
|
+
# Typically only empty in testing.
|
30
|
+
unless @@providers.empty?
|
31
|
+
@api_version = @@providers[@provider]['locations/publishers']['api_version']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Set a new provider to use the default for other methods. This may alter
|
36
|
+
# the api_version used for future requests. In practice, only
|
37
|
+
# 'Microsoft.Compute' or 'Microsoft.ClassicCompute' should be used.
|
38
|
+
#
|
39
|
+
def provider=(name)
|
40
|
+
@api_version = @@providers[name]['locations/publishers']['api_version']
|
41
|
+
@provider = name
|
42
|
+
end
|
43
|
+
|
44
|
+
# Return a list of VM image offers from the given +publisher+ and +location+.
|
45
|
+
#
|
46
|
+
# Example:
|
47
|
+
#
|
48
|
+
# vmim.offers('eastus', 'Canonical')
|
49
|
+
#
|
50
|
+
def offers(location = @location, publisher = @publisher)
|
51
|
+
raise ArgumentError, "No location specified" unless location
|
52
|
+
raise ArgumentError, "No publisher specified" unless publisher
|
53
|
+
|
54
|
+
url = build_url(location, 'publishers', publisher, 'artifacttypes', 'vmimage', 'offers')
|
55
|
+
|
56
|
+
JSON.parse(rest_get(url)).map{ |element| element['name'] }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Return a list of VM image publishers for the given +location+.
|
60
|
+
#
|
61
|
+
# Example:
|
62
|
+
#
|
63
|
+
# vmim.publishers('eastus')
|
64
|
+
#
|
65
|
+
def publishers(location = @location)
|
66
|
+
raise ArgumentError, "No location specified" unless location
|
67
|
+
|
68
|
+
url = build_url(location, 'publishers')
|
69
|
+
|
70
|
+
JSON.parse(rest_get(url)).map{ |element| element['name'] }
|
71
|
+
end
|
72
|
+
|
73
|
+
# Return a list of VM image skus for the given +offer+, +location+,
|
74
|
+
# and +publisher+.
|
75
|
+
#
|
76
|
+
# Example:
|
77
|
+
#
|
78
|
+
# vmim.skus('UbuntuServer', 'eastus', 'Canonical')
|
79
|
+
#
|
80
|
+
def skus(offer, location = @location, publisher = @publisher)
|
81
|
+
raise ArgumentError, "No location specified" unless location
|
82
|
+
raise ArgumentError, "No publisher specified" unless publisher
|
83
|
+
|
84
|
+
url = build_url(
|
85
|
+
location, 'publishers', publisher, 'artifacttypes',
|
86
|
+
'vmimage', 'offers', offer, 'skus'
|
87
|
+
)
|
88
|
+
|
89
|
+
JSON.parse(rest_get(url)).map{ |element| element['name'] }
|
90
|
+
end
|
91
|
+
|
92
|
+
# Return a list of VM image versions for the given +sku+, +offer+,
|
93
|
+
# +location+ and +publisher+.
|
94
|
+
#
|
95
|
+
# Example:
|
96
|
+
#
|
97
|
+
# vmim.versions('14.04.2', 'UbuntuServer', 'eastus', 'Canonical')
|
98
|
+
#
|
99
|
+
# # sample output
|
100
|
+
# => ["14.04.201503090", "14.04.201505060", "14.04.201506100", "14.04.201507060"]
|
101
|
+
#
|
102
|
+
def versions(sku, offer, location = @location, publisher = @publisher)
|
103
|
+
raise ArgumentError, "No location specified" unless location
|
104
|
+
raise ArgumentError, "No publisher specified" unless publisher
|
105
|
+
|
106
|
+
url = build_url(
|
107
|
+
location, 'publishers', publisher, 'artifacttypes', 'vmimage',
|
108
|
+
'offers', offer, 'skus', sku, 'versions'
|
109
|
+
)
|
110
|
+
|
111
|
+
JSON.parse(rest_get(url)).map{ |element| element['name'] }
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
# Builds a URL based on subscription_id an resource_group and any other
|
117
|
+
# arguments provided, and appends it with the api_version.
|
118
|
+
#
|
119
|
+
def build_url(location, *args)
|
120
|
+
url = File.join(
|
121
|
+
Azure::Armrest::COMMON_URI,
|
122
|
+
subscription_id,
|
123
|
+
'providers',
|
124
|
+
provider,
|
125
|
+
'locations',
|
126
|
+
location
|
127
|
+
)
|
128
|
+
|
129
|
+
url = File.join(url, *args) unless args.empty?
|
130
|
+
url << "?api-version=#{api_version}"
|
131
|
+
end
|
132
|
+
|
133
|
+
end # VirtualMachineImageManager
|
134
|
+
end # Armrest
|
135
|
+
end # Azure
|