azure-armrest 0.0.2 → 0.0.3
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 +4 -4
- data/lib/azure/armrest.rb +9 -2
- data/lib/azure/armrest/armrest_service.rb +2 -0
- data/lib/azure/armrest/model/base_model.rb +138 -0
- data/lib/azure/armrest/network/ip_address_service.rb +104 -0
- data/lib/azure/armrest/network/network_interface_service.rb +124 -0
- data/lib/azure/armrest/network/network_security_group_service.rb +97 -0
- data/lib/azure/armrest/network/subnet_service.rb +72 -0
- data/lib/azure/armrest/network/virtual_network_service.rb +115 -0
- data/lib/azure/armrest/version.rb +1 -1
- data/lib/azure/armrest/virtual_machine_image_service.rb +1 -1
- data/lib/azure/armrest/virtual_machine_service.rb +2 -2
- metadata +9 -6
- data/lib/azure/armrest/subnet_service.rb +0 -59
- data/lib/azure/armrest/virtual_network_service.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62a4984d7d387a029f6e37b0b3fb34e3ef2cb66b
|
4
|
+
data.tar.gz: 7f7d881116fe76082ed7ca21352117796bc01516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e208bb91e488aa4d1718c926c269ad1535845bacf50e7207fc9503ef6d704e314de34cf75077cab0c90a34f1eacc5fca10b5efac3fdc9f8952c6e1e1bd8161e
|
7
|
+
data.tar.gz: df333ea565a2e3a0d06cfe98cfd6f2948fc412bcbd3607201cedaaed838422e8c998e1a825e7a959c9cacbb33f6b4cf367e846d11bdb266db345c2abd762f7d9
|
data/lib/azure/armrest.rb
CHANGED
@@ -28,10 +28,17 @@ require 'azure/armrest/availability_set_service'
|
|
28
28
|
require 'azure/armrest/virtual_machine_service'
|
29
29
|
require 'azure/armrest/virtual_machine_image_service'
|
30
30
|
require 'azure/armrest/virtual_machine_extension_service'
|
31
|
-
require 'azure/armrest/virtual_network_service'
|
32
|
-
require 'azure/armrest/subnet_service'
|
33
31
|
require 'azure/armrest/event_service'
|
34
32
|
require 'azure/armrest/template_deployment_service'
|
35
33
|
require 'azure/armrest/resource_service'
|
36
34
|
require 'azure/armrest/resource_group_service'
|
37
35
|
require 'azure/armrest/resource_provider_service'
|
36
|
+
require 'azure/armrest/network/ip_address_service'
|
37
|
+
require 'azure/armrest/network/network_interface_service'
|
38
|
+
require 'azure/armrest/network/network_security_group_service'
|
39
|
+
require 'azure/armrest/network/virtual_network_service'
|
40
|
+
require 'azure/armrest/network/subnet_service'
|
41
|
+
|
42
|
+
# JSON wrapper classes. The service classes should require their own
|
43
|
+
# wrappers from this point on.
|
44
|
+
require_relative 'armrest/model/base_model'
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Azure
|
5
|
+
module Armrest
|
6
|
+
# Base class for JSON wrapper classes. Each Service class should have
|
7
|
+
# a corresponding class that wraps the JSON it collects, and each of
|
8
|
+
# them should subclass this base class.
|
9
|
+
class BaseModel < Delegator
|
10
|
+
|
11
|
+
# Declare that a method should return a plain hash instead of an
|
12
|
+
# OpenStruct instance.
|
13
|
+
#--
|
14
|
+
# TODO: Handle nested properties.
|
15
|
+
def self.hash_properties(method)
|
16
|
+
define_method(method){ @ostruct[method].to_h }
|
17
|
+
end
|
18
|
+
|
19
|
+
hash_properties :tags
|
20
|
+
|
21
|
+
# Access the json instance variable directly.
|
22
|
+
attr_accessor :json
|
23
|
+
|
24
|
+
# Constructs and returns a new JSON wrapper class. Pass in a plain
|
25
|
+
# JSON string and it will automatically give you accessor methods
|
26
|
+
# that make it behave like a typical Ruby object.
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
# class Person < Azure::ArmRest::BaseModel; end
|
30
|
+
#
|
31
|
+
# json_string = '{"firstname":"jeff", "lastname":"durand",
|
32
|
+
# "address": { "street":"22 charlotte rd", "zipcode":"01013"}
|
33
|
+
# }'
|
34
|
+
#
|
35
|
+
# # Or whatever your subclass happens to be.
|
36
|
+
# person = Person.new(json_string)
|
37
|
+
#
|
38
|
+
# # The JSON properties are now available as methods.
|
39
|
+
# person.firstname # => 'jeff'
|
40
|
+
# person.address.zipcode # => '01013'
|
41
|
+
#
|
42
|
+
# # Or you can get back the original JSON if necessary.
|
43
|
+
# person.json # => Returns original JSON
|
44
|
+
#
|
45
|
+
def initialize(json)
|
46
|
+
@json = json
|
47
|
+
@resource_group = nil
|
48
|
+
@ostruct = JSON.parse(json, object_class: OpenStruct)
|
49
|
+
__setobj__(@ostruct)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return the resource group for the current object.
|
53
|
+
def resource_group
|
54
|
+
@resource_group ||= id[/resourceGroups\/(.+?)\//i, 1] rescue nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the original JSON string passed to the constructor.
|
58
|
+
def to_json
|
59
|
+
@json
|
60
|
+
end
|
61
|
+
|
62
|
+
# Explicitly convert the object to the original JSON string.
|
63
|
+
def to_s
|
64
|
+
@json
|
65
|
+
end
|
66
|
+
|
67
|
+
# Implicitly convert the object to the original JSON string.
|
68
|
+
def to_str
|
69
|
+
@json
|
70
|
+
end
|
71
|
+
|
72
|
+
# Custom inspect method that shows the current class and methods.
|
73
|
+
#--
|
74
|
+
# TODO: Make this recursive.
|
75
|
+
def inspect
|
76
|
+
string = "<#{self.class} "
|
77
|
+
method_list = methods(false).select{ |m| !m.to_s.include?('=') }
|
78
|
+
string << method_list.map{ |m| "#{m}=#{send(m)}" }.join(" ")
|
79
|
+
string << ">"
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
# Interface method required to make delegation work. Do
|
85
|
+
# not use this method directly.
|
86
|
+
def __getobj__
|
87
|
+
@ostruct
|
88
|
+
end
|
89
|
+
|
90
|
+
# A custom Delegator interface method that creates snake_case
|
91
|
+
# versions of the camelCase delegate methods.
|
92
|
+
def __setobj__(obj)
|
93
|
+
obj.methods(false).each{ |m|
|
94
|
+
if m.to_s[-1] != '=' # Must deal with nested ostruct's
|
95
|
+
res = obj.send(m)
|
96
|
+
if res.respond_to?(:each)
|
97
|
+
res.each{ |o| __setobj__(o) if o.is_a?(OpenStruct) }
|
98
|
+
else
|
99
|
+
__setobj__(res) if res.is_a?(OpenStruct)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
snake = m.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym
|
104
|
+
|
105
|
+
begin
|
106
|
+
obj.instance_eval("alias #{snake} #{m}") unless snake == m
|
107
|
+
rescue SyntaxError
|
108
|
+
next
|
109
|
+
end
|
110
|
+
}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Initial class definitions. Reopen these classes as needed.
|
115
|
+
|
116
|
+
class AvailabilitySet < BaseModel; end
|
117
|
+
class Event < BaseModel; end
|
118
|
+
class Resource < BaseModel; end
|
119
|
+
class ResourceGroup < BaseModel; end
|
120
|
+
class ResourceProvider < BaseModel; end
|
121
|
+
class StorageAccount < BaseModel; end
|
122
|
+
class TemplateDeployment < BaseModel; end
|
123
|
+
class TemplateDeploymentOperation < TemplateDeployment; end
|
124
|
+
class VirtualMachine < BaseModel; end
|
125
|
+
class VirtualMachineInstance < VirtualMachine; end
|
126
|
+
class VirtualMachineModel < VirtualMachine; end
|
127
|
+
class VirtualMachineExtension < BaseModel; end
|
128
|
+
class VirtualMachineImage < BaseModel; end
|
129
|
+
|
130
|
+
module Network
|
131
|
+
class IpAddress < BaseModel; end
|
132
|
+
class NetworkInterface < BaseModel; end
|
133
|
+
class NetworkSecurityGroup < BaseModel; end
|
134
|
+
class VirtualNetwork < BaseModel; end
|
135
|
+
class Subnet < VirtualNetwork; end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
module Network
|
4
|
+
# Class for managing public IP addresss.
|
5
|
+
class IpAddressService < ArmrestService
|
6
|
+
|
7
|
+
# Creates and returns a new IpAddressService instance.
|
8
|
+
#
|
9
|
+
def initialize(_armrest_configuration, options = {})
|
10
|
+
super
|
11
|
+
@provider = options[:provider] || 'Microsoft.Network'
|
12
|
+
set_service_api_version(options, 'publicIPAddresses')
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return information for the given IP address name for the
|
16
|
+
# provided +resource_group+. If no group is specified, it will use
|
17
|
+
# the resource group set in the constructor.
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
#
|
21
|
+
# # Where 'your_ip_name' likely corresponds to a VM name.
|
22
|
+
# ip.get('your_ip_name', 'your_resource_group')
|
23
|
+
#
|
24
|
+
def get(ip_name, resource_group = armrest_configuration.resource_group)
|
25
|
+
raise ArgumentError, "must specify resource group" unless resource_group
|
26
|
+
url = build_url(resource_group, ip_name)
|
27
|
+
JSON.parse(rest_get(url))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Shortcut method that returns just the IP address for the given public
|
31
|
+
# IP address name.
|
32
|
+
#
|
33
|
+
def get_ip(ip_name, resource_group = armrest_configuration.resource_group)
|
34
|
+
get(ip_name, resource_group)['properties']['ipAddress']
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns a list of available IP addresss for the given subscription
|
38
|
+
# for the provided +group+, or for all resource groups if no group is specified.
|
39
|
+
#
|
40
|
+
def list(group = nil)
|
41
|
+
if group
|
42
|
+
url = build_url(group)
|
43
|
+
JSON.parse(rest_get(url))['value']
|
44
|
+
else
|
45
|
+
array = []
|
46
|
+
threads = []
|
47
|
+
mutex = Mutex.new
|
48
|
+
|
49
|
+
resource_groups.each do |rg|
|
50
|
+
threads << Thread.new(rg['name']) do |group|
|
51
|
+
url = build_url(group)
|
52
|
+
response = rest_get(url)
|
53
|
+
results = JSON.parse(response)['value']
|
54
|
+
if results && !results.empty?
|
55
|
+
mutex.synchronize{
|
56
|
+
results.each{ |hash| hash['resourceGroup'] = group }
|
57
|
+
array << results
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
threads.each(&:join)
|
64
|
+
|
65
|
+
array.flatten
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# List all IP addresss for the current subscription.
|
70
|
+
#
|
71
|
+
def list_all_for_subscription
|
72
|
+
sub_id = armrest_configuration.subscription_id
|
73
|
+
url = File.join(
|
74
|
+
Azure::Armrest::COMMON_URI, sub_id, 'providers',
|
75
|
+
@provider, 'publicIPAddresses'
|
76
|
+
)
|
77
|
+
url << "?api-version=#{@api_version}"
|
78
|
+
JSON.parse(rest_get(url))['value']
|
79
|
+
end
|
80
|
+
|
81
|
+
alias list_all list_all_for_subscription
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
# Builds a URL based on subscription_id an resource_group and any other
|
86
|
+
# arguments provided, and appends it with the api-version.
|
87
|
+
def build_url(resource_group, *args)
|
88
|
+
url = File.join(
|
89
|
+
Azure::Armrest::COMMON_URI,
|
90
|
+
armrest_configuration.subscription_id,
|
91
|
+
'resourceGroups',
|
92
|
+
resource_group,
|
93
|
+
'providers',
|
94
|
+
@provider,
|
95
|
+
'publicIPAddresses',
|
96
|
+
)
|
97
|
+
|
98
|
+
url = File.join(url, *args) unless args.empty?
|
99
|
+
url << "?api-version=#{@api_version}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end # Network
|
103
|
+
end # Armrest
|
104
|
+
end # Azure
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
module Network
|
4
|
+
# Class for managing network interfaces.
|
5
|
+
class NetworkInterfaceService < ArmrestService
|
6
|
+
# Creates and returns a new NetworkInterfaceService instance.
|
7
|
+
#
|
8
|
+
def initialize(_armrest_configuration, options = {})
|
9
|
+
super
|
10
|
+
@provider = options[:provider] || 'Microsoft.Network'
|
11
|
+
set_service_api_version(options, 'networkInterfaces')
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return information for the given network interface card for the
|
15
|
+
# provided +resource_group+. If no group is specified, it will use the
|
16
|
+
# resource group set in the constructor.
|
17
|
+
#
|
18
|
+
# Example:
|
19
|
+
#
|
20
|
+
# nsg.get('your_interface', 'your_resource_group')
|
21
|
+
#
|
22
|
+
def get(interface, resource_group = armrest_configuration.resource_group)
|
23
|
+
raise ArgumentError, "must specify resource group" unless resource_group
|
24
|
+
url = build_url(resource_group, interface)
|
25
|
+
JSON.parse(rest_get(url))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a list of available network interfaces in the current subscription
|
29
|
+
# for the provided +resource_group+.
|
30
|
+
#
|
31
|
+
def list(resource_group = armrest_configuration.resource_group)
|
32
|
+
raise ArgumentError, "no resource group provided" unless resource_group
|
33
|
+
url = build_url(resource_group)
|
34
|
+
JSON.parse(rest_get(url))['value']
|
35
|
+
end
|
36
|
+
|
37
|
+
# List all network interfaces for the current subscription.
|
38
|
+
#
|
39
|
+
def list_all_for_subscription
|
40
|
+
sub_id = armrest_configuration.subscription_id
|
41
|
+
url = File.join(Azure::Armrest::COMMON_URI, sub_id, 'providers', @provider, 'networkInterfaces')
|
42
|
+
url << "?api-version=#{@api_version}"
|
43
|
+
JSON.parse(rest_get(url))['value']
|
44
|
+
end
|
45
|
+
|
46
|
+
alias list_all list_all_for_subscription
|
47
|
+
|
48
|
+
# Delete the given network interface in +resource_group+.
|
49
|
+
#
|
50
|
+
def delete(interface, resource_group = armrest_configuration.resource_group)
|
51
|
+
raise ArgumentError, "must specify resource group" unless resource_group
|
52
|
+
|
53
|
+
url = build_url(resource_group, interface)
|
54
|
+
response = rest_delete(url)
|
55
|
+
response.return!
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create a new network interface, or update an existing network interface if it
|
59
|
+
# already exists. The first argument is a hash of options.
|
60
|
+
#
|
61
|
+
# - :name # Mandatory
|
62
|
+
# - :location # Mandatory
|
63
|
+
# - :tags
|
64
|
+
# - :properties
|
65
|
+
# - :networkSecurityGroup
|
66
|
+
# - :id
|
67
|
+
# - :ipConfigurations
|
68
|
+
# [
|
69
|
+
# - :name # Mandatory
|
70
|
+
# - :properties
|
71
|
+
# - :subnet
|
72
|
+
# - :id # Mandatory
|
73
|
+
# - :privateIPAddress
|
74
|
+
# - :privateIPAllocationMethod # Mandatory
|
75
|
+
# - :publicIPAddress
|
76
|
+
# - :id
|
77
|
+
# - :loadBalancerBackendAddressPools
|
78
|
+
# - :id
|
79
|
+
# - :loadBalancerInboundNatRules
|
80
|
+
# - :id
|
81
|
+
# ]
|
82
|
+
#
|
83
|
+
# - :dnsSettings
|
84
|
+
# - :dnsServers[ <ip1>, <ip2>, ... ]
|
85
|
+
#
|
86
|
+
# For convenience, you may also pass the :resource_group as a hash option.
|
87
|
+
#
|
88
|
+
def create(name, options, resource_group = armrest_configuration.resource_group)
|
89
|
+
resource_group = options.delete(:resource_group) || resource_group
|
90
|
+
|
91
|
+
raise ArgumentError, "no resource group specified" unless resource_group
|
92
|
+
|
93
|
+
body = options.to_json
|
94
|
+
|
95
|
+
url = build_url(resource_group, name)
|
96
|
+
|
97
|
+
response = rest_put(url, body)
|
98
|
+
response.return!
|
99
|
+
end
|
100
|
+
|
101
|
+
alias update create
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
# Builds a URL based on subscription_id an resource_group and any other
|
106
|
+
# arguments provided, and appends it with the api-version.
|
107
|
+
def build_url(resource_group, *args)
|
108
|
+
url = File.join(
|
109
|
+
Azure::Armrest::COMMON_URI,
|
110
|
+
armrest_configuration.subscription_id,
|
111
|
+
'resourceGroups',
|
112
|
+
resource_group,
|
113
|
+
'providers',
|
114
|
+
@provider,
|
115
|
+
'networkInterfaces',
|
116
|
+
)
|
117
|
+
|
118
|
+
url = File.join(url, *args) unless args.empty?
|
119
|
+
url << "?api-version=#{@api_version}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end # Network
|
123
|
+
end # Armrest
|
124
|
+
end # Azure
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
module Network
|
4
|
+
# Class for managing network security groups.
|
5
|
+
class NetworkSecurityGroupService < ArmrestService
|
6
|
+
|
7
|
+
# Creates and returns a new NetworkSecurityGroupService instance.
|
8
|
+
#
|
9
|
+
def initialize(_armrest_configuration, options = {})
|
10
|
+
super
|
11
|
+
@provider = options[:provider] || 'Microsoft.Network'
|
12
|
+
set_service_api_version(options, 'networkSecurityGroups')
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return information for the given network security group name for the
|
16
|
+
# provided +resource_group+. If no group is specified, it will use the
|
17
|
+
# resource group set in the constructor.
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
#
|
21
|
+
# # Where 'your_security_group' is likely same as the name of a VM.
|
22
|
+
# nsg.get('your_security_group', 'your_resource_group')
|
23
|
+
#
|
24
|
+
def get(ns_group_name, resource_group = armrest_configuration.resource_group)
|
25
|
+
raise ArgumentError, "must specify resource group" unless resource_group
|
26
|
+
url = build_url(resource_group, ns_group_name)
|
27
|
+
JSON.parse(rest_get(url))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a list of available network security groups for the given subscription
|
31
|
+
# for the provided +group+, or for all resource groups if no group is specified.
|
32
|
+
#
|
33
|
+
def list(group = nil)
|
34
|
+
if group
|
35
|
+
url = build_url(group)
|
36
|
+
JSON.parse(rest_get(url))['value']
|
37
|
+
else
|
38
|
+
array = []
|
39
|
+
threads = []
|
40
|
+
mutex = Mutex.new
|
41
|
+
|
42
|
+
resource_groups.each do |rg|
|
43
|
+
threads << Thread.new(rg['name']) do |group|
|
44
|
+
url = build_url(group)
|
45
|
+
response = rest_get(url)
|
46
|
+
results = JSON.parse(response)['value']
|
47
|
+
if results && !results.empty?
|
48
|
+
mutex.synchronize{
|
49
|
+
results.each{ |hash| hash['resourceGroup'] = group }
|
50
|
+
array << results
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
threads.each(&:join)
|
57
|
+
|
58
|
+
array.flatten
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# List all network security groups for the current subscription.
|
63
|
+
#
|
64
|
+
def list_all_for_subscription
|
65
|
+
sub_id = armrest_configuration.subscription_id
|
66
|
+
url = File.join(
|
67
|
+
Azure::Armrest::COMMON_URI, sub_id, 'providers',
|
68
|
+
@provider, 'networkSecurityGroups'
|
69
|
+
)
|
70
|
+
url << "?api-version=#{@api_version}"
|
71
|
+
JSON.parse(rest_get(url))['value']
|
72
|
+
end
|
73
|
+
|
74
|
+
alias list_all list_all_for_subscription
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Builds a URL based on subscription_id an resource_group and any other
|
79
|
+
# arguments provided, and appends it with the api-version.
|
80
|
+
def build_url(resource_group, *args)
|
81
|
+
url = File.join(
|
82
|
+
Azure::Armrest::COMMON_URI,
|
83
|
+
armrest_configuration.subscription_id,
|
84
|
+
'resourceGroups',
|
85
|
+
resource_group,
|
86
|
+
'providers',
|
87
|
+
@provider,
|
88
|
+
'networkSecurityGroups',
|
89
|
+
)
|
90
|
+
|
91
|
+
url = File.join(url, *args) unless args.empty?
|
92
|
+
url << "?api-version=#{@api_version}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end # Network
|
96
|
+
end # Armrest
|
97
|
+
end # Azure
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
module Network
|
4
|
+
# Base class for managing subnets
|
5
|
+
class SubnetService < VirtualNetworkService
|
6
|
+
|
7
|
+
# Create and return a new SubnetService instance. Most methods for a
|
8
|
+
# SubnetService instance will return one or Subnet instances.
|
9
|
+
#
|
10
|
+
def initialize(_armrest_configuration, options = {})
|
11
|
+
super
|
12
|
+
@provider = options[:provider] || 'Microsoft.Network'
|
13
|
+
set_service_api_version(options, 'virtualNetworks')
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a new +subnet_name+ on +virtual_network+ using the given
|
17
|
+
# +options+. The +options+ argument is a hash that supports the
|
18
|
+
# following keys and subkeys.
|
19
|
+
#
|
20
|
+
# - :properties
|
21
|
+
# - :addressPrefix
|
22
|
+
# - :networkSecurityGroup
|
23
|
+
# - :id
|
24
|
+
# - :routeTable
|
25
|
+
# - :id
|
26
|
+
#
|
27
|
+
def create(subnet_name, virtual_network, options = {}, resource_group = armrest_configuration.resource_group)
|
28
|
+
resource_group = options.delete(:resource_group) || resource_group
|
29
|
+
raise ArgumentError, "no resource group provided" unless resource_group
|
30
|
+
url = build_url(resource_group, virtual_network, subnet_name)
|
31
|
+
body = options.to_json
|
32
|
+
response = rest_put(url, body)
|
33
|
+
response.return!
|
34
|
+
end
|
35
|
+
|
36
|
+
alias update create
|
37
|
+
|
38
|
+
# Deletes the given +subnet_name+ in +virtual_network+.
|
39
|
+
#
|
40
|
+
def delete(subnet_name, virtual_network, resource_group = armrest_configuration.resource_group)
|
41
|
+
raise ArgumentError, "no resource group provided" unless resource_group
|
42
|
+
url = build_url(resource_group, virtual_network, subnet_name)
|
43
|
+
response = rest_delete(url)
|
44
|
+
response.return!
|
45
|
+
end
|
46
|
+
|
47
|
+
# Retrieves information for the provided +subnet_name+ in +virtual_network+ for
|
48
|
+
# the current subscription.
|
49
|
+
#
|
50
|
+
def get(subnet_name, virtual_network, resource_group = armrest_configuration.resource_group)
|
51
|
+
raise ArgumentError, "no resource group provided" unless resource_group
|
52
|
+
url = build_url(resource_group, virtual_network, subnet_name)
|
53
|
+
JSON.parse(rest_get(url))
|
54
|
+
end
|
55
|
+
|
56
|
+
# List available subnets on +virtual_network+ for the given +resource_group+.
|
57
|
+
#
|
58
|
+
def list(virtual_network, resource_group = armrest_configuration.resource_group)
|
59
|
+
raise ArgumentError, "no resource group provided" unless resource_group
|
60
|
+
url = build_url(resource_group, virtual_network)
|
61
|
+
JSON.parse(rest_get(url))['value']
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def build_url(resource_group, virtual_network_name, *args)
|
67
|
+
super(resource_group, virtual_network_name, 'subnets', *args)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end # Network
|
71
|
+
end # Armrest
|
72
|
+
end # Azure
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
module Network
|
4
|
+
# Class for managing virtual networks.
|
5
|
+
class VirtualNetworkService < ArmrestService
|
6
|
+
|
7
|
+
# Creates and returns a new VirtualNetworkService instance.
|
8
|
+
#
|
9
|
+
def initialize(_armrest_configuration, options = {})
|
10
|
+
super
|
11
|
+
@provider = options[:provider] || 'Microsoft.Network'
|
12
|
+
set_service_api_version(options, 'virtualNetworks')
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return information for the given virtual network for the provided
|
16
|
+
# +resource_group+. If no group is specified, it will use the resource
|
17
|
+
# group set in the constructor.
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
#
|
21
|
+
# vns.get('vn_name', 'your_resource_group')
|
22
|
+
#
|
23
|
+
def get(vn_name, resource_group = armrest_configuration.resource_group)
|
24
|
+
raise ArgumentError, "must specify resource group" unless resource_group
|
25
|
+
url = build_url(resource_group, vn_name)
|
26
|
+
JSON.parse(rest_get(url))
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns a list of available virtual networks in the current subscription
|
30
|
+
# for the provided +resource_group+.
|
31
|
+
#
|
32
|
+
def list(resource_group = armrest_configuration.resource_group)
|
33
|
+
raise ArgumentError, "no resource group provided" unless resource_group
|
34
|
+
url = build_url(resource_group)
|
35
|
+
JSON.parse(rest_get(url))['value']
|
36
|
+
end
|
37
|
+
|
38
|
+
# List all virtual networks for the current subscription.
|
39
|
+
#
|
40
|
+
def list_all_for_subscription
|
41
|
+
sub_id = armrest_configuration.subscription_id
|
42
|
+
url = File.join(Azure::Armrest::COMMON_URI, sub_id, 'providers', @provider, 'virtualNetworks')
|
43
|
+
url << "?api-version=#{@api_version}"
|
44
|
+
JSON.parse(rest_get(url))['value']
|
45
|
+
end
|
46
|
+
|
47
|
+
alias list_all list_all_for_subscription
|
48
|
+
|
49
|
+
# Delete the given virtual network in +resource_group+.
|
50
|
+
#
|
51
|
+
def delete(vn_name, resource_group = armrest_configuration.resource_group)
|
52
|
+
raise ArgumentError, "must specify resource group" unless resource_group
|
53
|
+
|
54
|
+
url = build_url(resource_group, vn_name)
|
55
|
+
response = rest_delete(url)
|
56
|
+
response.return!
|
57
|
+
end
|
58
|
+
|
59
|
+
# Create a new virtual network, or update an existing virtual network if it
|
60
|
+
# already exists. The first argument is a hash of options.
|
61
|
+
#
|
62
|
+
# - :location
|
63
|
+
# - :tags
|
64
|
+
# - :etag
|
65
|
+
# - :properties
|
66
|
+
# - :addressSpace
|
67
|
+
# - :addressPrefixes[]
|
68
|
+
# - :dhcpOptions
|
69
|
+
# - :dnsServers[]
|
70
|
+
# - :subnets
|
71
|
+
# [
|
72
|
+
# - :name
|
73
|
+
# - :properties
|
74
|
+
# - :addressPrefix
|
75
|
+
# - :networkSecurityGroup
|
76
|
+
# - :id
|
77
|
+
# ]
|
78
|
+
#
|
79
|
+
def create(vn_name, options, resource_group = armrest_configuration.resource_group)
|
80
|
+
resource_group = options.delete(:resource_group) || resource_group
|
81
|
+
|
82
|
+
raise ArgumentError, "no resource group specified" unless resource_group
|
83
|
+
|
84
|
+
body = options.to_json
|
85
|
+
|
86
|
+
url = build_url(resource_group, vn_name)
|
87
|
+
|
88
|
+
response = rest_put(url, body)
|
89
|
+
response.return!
|
90
|
+
end
|
91
|
+
|
92
|
+
alias update create
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
# Builds a URL based on subscription_id an resource_group and any other
|
97
|
+
# arguments provided, and appends it with the api-version.
|
98
|
+
def build_url(resource_group, *args)
|
99
|
+
url = File.join(
|
100
|
+
Azure::Armrest::COMMON_URI,
|
101
|
+
armrest_configuration.subscription_id,
|
102
|
+
'resourceGroups',
|
103
|
+
resource_group,
|
104
|
+
'providers',
|
105
|
+
@provider,
|
106
|
+
'virtualNetworks',
|
107
|
+
)
|
108
|
+
|
109
|
+
url = File.join(url, *args) unless args.empty?
|
110
|
+
url << "?api-version=#{@api_version}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end # Network
|
114
|
+
end # Armrest
|
115
|
+
end # Azure
|
@@ -130,11 +130,11 @@ module Azure
|
|
130
130
|
|
131
131
|
body = {
|
132
132
|
:vhdPrefix => prefix,
|
133
|
-
:
|
133
|
+
:destinationContainerName => container,
|
134
134
|
:overwriteVhds => overwrite
|
135
135
|
}.to_json
|
136
136
|
|
137
|
-
url = build_url(group, 'capture')
|
137
|
+
url = build_url(group, vmname, 'capture')
|
138
138
|
|
139
139
|
response = rest_post(url, body)
|
140
140
|
response.return!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azure-armrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|
@@ -152,17 +152,21 @@ files:
|
|
152
152
|
- lib/azure/armrest/armrest_service.rb
|
153
153
|
- lib/azure/armrest/availability_set_service.rb
|
154
154
|
- lib/azure/armrest/event_service.rb
|
155
|
+
- lib/azure/armrest/model/base_model.rb
|
156
|
+
- lib/azure/armrest/network/ip_address_service.rb
|
157
|
+
- lib/azure/armrest/network/network_interface_service.rb
|
158
|
+
- lib/azure/armrest/network/network_security_group_service.rb
|
159
|
+
- lib/azure/armrest/network/subnet_service.rb
|
160
|
+
- lib/azure/armrest/network/virtual_network_service.rb
|
155
161
|
- lib/azure/armrest/resource_group_service.rb
|
156
162
|
- lib/azure/armrest/resource_provider_service.rb
|
157
163
|
- lib/azure/armrest/resource_service.rb
|
158
164
|
- lib/azure/armrest/storage_account_service.rb
|
159
|
-
- lib/azure/armrest/subnet_service.rb
|
160
165
|
- lib/azure/armrest/template_deployment_service.rb
|
161
166
|
- lib/azure/armrest/version.rb
|
162
167
|
- lib/azure/armrest/virtual_machine_extension_service.rb
|
163
168
|
- lib/azure/armrest/virtual_machine_image_service.rb
|
164
169
|
- lib/azure/armrest/virtual_machine_service.rb
|
165
|
-
- lib/azure/armrest/virtual_network_service.rb
|
166
170
|
homepage: http://github.com/ManageIQ/azure-armrest
|
167
171
|
licenses:
|
168
172
|
- Apache 2.0
|
@@ -183,9 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
187
|
version: '0'
|
184
188
|
requirements: []
|
185
189
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.4.5
|
190
|
+
rubygems_version: 2.4.5.1
|
187
191
|
signing_key:
|
188
192
|
specification_version: 4
|
189
193
|
summary: An interface for ARM/JSON Azure REST API
|
190
194
|
test_files: []
|
191
|
-
has_rdoc:
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# Azure namespace
|
2
|
-
module Azure
|
3
|
-
# Armrest namespace
|
4
|
-
module Armrest
|
5
|
-
# Base class for managing subnets
|
6
|
-
class SubnetService < VirtualNetworkService
|
7
|
-
|
8
|
-
# Create and return a new SubnetService instance. Most methods for a
|
9
|
-
# SubnetService instance will return one or Subnet instances.
|
10
|
-
#
|
11
|
-
def initialize(_armrest_configuration, _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
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# Azure namespace
|
2
|
-
module Azure
|
3
|
-
# Armrest namespace
|
4
|
-
module Armrest
|
5
|
-
# Base class for managing virtual networks
|
6
|
-
class VirtualNetworkService < ArmrestService
|
7
|
-
|
8
|
-
# Create and return a new VirtualNetworkService instance. Most
|
9
|
-
# methods for a VirtualNetworkService instance will return one or
|
10
|
-
# more VirtualNetwork instances.
|
11
|
-
#
|
12
|
-
def initialize(armrest_configuration, options = {})
|
13
|
-
super
|
14
|
-
|
15
|
-
@base_url += "resourceGroups/#{armrest_configuration.resource_group}/"
|
16
|
-
@base_url += "providers/Microsoft.Network/virtualNetworks"
|
17
|
-
end
|
18
|
-
|
19
|
-
# Creates a new virtual network using the given +options+. The possible
|
20
|
-
# options are:
|
21
|
-
#
|
22
|
-
# :name
|
23
|
-
# :id
|
24
|
-
# :location
|
25
|
-
# :tags
|
26
|
-
# :etag
|
27
|
-
# :properties
|
28
|
-
# :address_space
|
29
|
-
# :address_prefixes
|
30
|
-
# :dhcp_options
|
31
|
-
# :dns_servers
|
32
|
-
# :subnets
|
33
|
-
# :name
|
34
|
-
# :id
|
35
|
-
# :etag
|
36
|
-
# :provisioning_state
|
37
|
-
# :address_prefix
|
38
|
-
# :dhcp_options
|
39
|
-
# :ip_configurations
|
40
|
-
# :id
|
41
|
-
#--
|
42
|
-
def create(network_name, options = {})
|
43
|
-
@uri += "/#{network_name}?api-version=#{armrest_configuration.api_version}"
|
44
|
-
end
|
45
|
-
|
46
|
-
# Deletes the +network_name+ availability set.
|
47
|
-
def delete(network_name)
|
48
|
-
@uri += "/#{network_name}?api-version=#{armrest_configuration.api_version}"
|
49
|
-
end
|
50
|
-
|
51
|
-
# Retrieves the options of an availability set.
|
52
|
-
def get(network_name)
|
53
|
-
@uri += "/#{network_name}?api-version=#{armrest_configuration.api_version}"
|
54
|
-
end
|
55
|
-
|
56
|
-
# List availability sets.
|
57
|
-
def list
|
58
|
-
@uri += "?api-version=#{armrest_configuration.api_version}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|