fog-azure-rm 0.4.9 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6eace092703425619fcb56d16c63043e2f92be194dbe41d800702afb6f03238
4
- data.tar.gz: dbeacbf137a189c567e97e2c6b459b6d6e4fc5edde87a7d1a674c48059e7d975
3
+ metadata.gz: c7723f74bbee0611351af2564fa5d3435354be5a5ed212a12fdae7ab5050a88c
4
+ data.tar.gz: 142a0f7e06a32ff2e83fe9b87c62ff115edc7e6b0601e37e5c967c45f91b1ed6
5
5
  SHA512:
6
- metadata.gz: e18b3f6b29b0e8ebe819650977bd7bc06a37efab2191ef1bbc07761e22dad7ebe651b4b6eb282ef5146d4e388cb8183511e8e0ae0a87bcfde8f232b16d485d70
7
- data.tar.gz: b746e050e5e78944ed72644b23c506bbd0e5d7f71830d6207bcf54d9f59c5d48e45fd8334bdf40ce3514894cde942fd2b2625db4ae280fd31a7a7e47e7ccd04f
6
+ metadata.gz: 9cd47cf5c5ad0b765a791dd1faaef235139671c2fa8bac0c01d5b404ca66390ae91e1f490f4a3e6308074399f4c4d8192f52d5433cc6408eed457641bf90f2f2
7
+ data.tar.gz: 31215199cce2b823e2e0d80ccd6ee593f425deadaf65a389f6fc656c6372f0fee07442186faad44a9105860fbf3e1833b1d072a987ee2540c93308b58f993524
@@ -1,3 +1,8 @@
1
+ ## 0.5.0
2
+
3
+ **Added**
4
+ - Asynchronous creation of Network Interface Card
5
+
1
6
  ## 0.4.9
2
7
 
3
8
  **Added**
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/fog-azure-rm.svg)](https://badge.fury.io/rb/fog-azure-rm)
2
2
  [![Build Status](https://travis-ci.org/fog/fog-azure-rm.svg?branch=master)](https://travis-ci.org/fog/fog-azure-rm)
3
- [![Dependency Status](https://gemnasium.com/badges/github.com/fog/fog-azure-rm.svg)](https://gemnasium.com/github.com/fog/fog-azure-rm)
3
+ [![security](https://hakiri.io/github/fog/fog-azure-rm/master.svg)](https://hakiri.io/github/fog/fog-azure-rm/master)
4
4
  [![Test Coverage](https://codeclimate.com/github/fog/fog-azure-rm/badges/coverage.svg)](https://codeclimate.com/github/fog/fog-azure-rm/coverage)
5
5
  [![Code Climate](https://codeclimate.com/github/fog/fog-azure-rm/badges/gpa.svg)](https://codeclimate.com/github/fog/fog-azure-rm)
6
- [![Stories in Ready](https://badge.waffle.io/fog/fog-azure-rm.svg?label=ready&title=Ready)](http://waffle.io/fog/fog-azure-rm)
7
6
 
8
7
  # Fog Azure Resource Manager
9
8
 
@@ -261,6 +261,24 @@ nic = fog_network_service.network_interfaces.create(
261
261
  )
262
262
  ```
263
263
 
264
+ ## Create Network Interface Card Asynchronously
265
+
266
+ Create a new network interface asynchronously. Skip public_ip_address_id parameter to create network interface without PublicIP. The parameter, private_ip_allocation_method can be Dynamic or Static.
267
+
268
+ ```ruby
269
+ nic = fog_network_service.network_interfaces.create_async(
270
+ name: '<Network Interface Name>',
271
+ resource_group: '<Resource Group Name>',
272
+ location: '<Location>',
273
+ subnet_id: '/subscriptions/<Subscription Id>/resourceGroups/<Resource Group Name>/providers/Microsoft.Network/virtualNetworks/<Virtual Network Name>/subnets/<Subnet Name>',
274
+ public_ip_address_id: '/subscriptions/<Subscription Id>/resourceGroups/<Resource Group Name>/providers/Microsoft.Network/publicIPAddresses/<Public IP Name>',
275
+ ip_configuration_name: '<IP Configuration Name>',
276
+ private_ip_allocation_method: '<IP Allocation Method Name>',
277
+ tags: { key: 'value' } # [Optional],
278
+ enable_accelerated_networking: true # [Optional] false by default
279
+ )
280
+ ```
281
+
264
282
  ## List Network Interface Cards
265
283
 
266
284
  List network interfaces in a resource group
@@ -59,15 +59,21 @@ module Fog
59
59
  hash
60
60
  end
61
61
 
62
- def save
62
+ def save(async = false)
63
63
  requires :name
64
64
  requires :location
65
65
  requires :resource_group
66
66
  requires :subnet_id
67
67
  requires :ip_configuration_name
68
68
  requires :private_ip_allocation_method
69
- nic = service.create_or_update_network_interface(resource_group, name, location, subnet_id, public_ip_address_id, network_security_group_id, ip_configuration_name, private_ip_allocation_method, private_ip_address, load_balancer_backend_address_pools_ids, load_balancer_inbound_nat_rules_ids, tags, enable_accelerated_networking)
70
- merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
69
+
70
+ nic_response = service.create_or_update_network_interface(resource_group, name, location, subnet_id, public_ip_address_id, network_security_group_id, ip_configuration_name, private_ip_allocation_method, private_ip_address, load_balancer_backend_address_pools_ids, load_balancer_inbound_nat_rules_ids, tags, enable_accelerated_networking, async)
71
+
72
+ if async
73
+ nic_response
74
+ else
75
+ merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic_response))
76
+ end
71
77
  end
72
78
 
73
79
  def update(updated_attributes = {})
@@ -15,6 +15,12 @@ module Fog
15
15
  load(network_interfaces)
16
16
  end
17
17
 
18
+ def create_async(attributes = {})
19
+ network_interface = new(attributes)
20
+ promise = network_interface.save(true)
21
+ Fog::AzureRM::AsyncResponse.new(network_interface, promise)
22
+ end
23
+
18
24
  def get(resource_group_name, name)
19
25
  network_interface_card = service.get_network_interface(resource_group_name, name)
20
26
  network_interface_card_fog = Fog::Network::AzureRM::NetworkInterface.new(service: service)
@@ -4,17 +4,21 @@ module Fog
4
4
  class AzureRM
5
5
  # Real class for Network Request
6
6
  class Real
7
- def create_or_update_network_interface(resource_group_name, name, location, subnet_id, public_ip_address_id, network_security_group_id, ip_config_name, private_ip_allocation_method, private_ip_address, load_balancer_backend_address_pools_ids, load_balancer_inbound_nat_rules_ids, tags, enable_accelerated_networking = false)
7
+ def create_or_update_network_interface(resource_group_name, name, location, subnet_id, public_ip_address_id, network_security_group_id, ip_config_name, private_ip_allocation_method, private_ip_address, load_balancer_backend_address_pools_ids, load_balancer_inbound_nat_rules_ids, tags, enable_accelerated_networking = false, async = false)
8
8
  msg = "Creating/Updating Network Interface Card: #{name}"
9
9
  Fog::Logger.debug msg
10
10
  network_interface = get_network_interface_object(name, location, subnet_id, public_ip_address_id, network_security_group_id, ip_config_name, private_ip_allocation_method, private_ip_address, load_balancer_backend_address_pools_ids, load_balancer_inbound_nat_rules_ids, tags, enable_accelerated_networking)
11
11
  begin
12
- network_interface_obj = @network_client.network_interfaces.create_or_update(resource_group_name, name, network_interface)
12
+ nic_response = if async
13
+ @network_client.network_interfaces.create_or_update_async(resource_group_name, name, network_interface)
14
+ else
15
+ @network_client.network_interfaces.create_or_update(resource_group_name, name, network_interface)
16
+ end
13
17
  rescue MsRestAzure::AzureOperationError => e
14
18
  raise_azure_exception(e, msg)
15
19
  end
16
- Fog::Logger.debug "Network Interface #{name} created/updated successfully."
17
- network_interface_obj
20
+ Fog::Logger.debug "Network Interface #{name} created/updated successfully." unless async
21
+ nic_response
18
22
  end
19
23
 
20
24
  private
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AzureRM
3
- VERSION = '0.4.9'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
@@ -67,6 +67,13 @@ begin
67
67
  public_ip_allocation_method: 'Dynamic'
68
68
  )
69
69
 
70
+ network.public_ips.create(
71
+ name: 'mypubip2',
72
+ resource_group: 'TestRG-NI',
73
+ location: LOCATION,
74
+ public_ip_allocation_method: 'Dynamic'
75
+ )
76
+
70
77
  nsg = network.network_security_groups.create(
71
78
  name: 'test_nsg',
72
79
  resource_group: 'TestRG-NI',
@@ -112,6 +119,40 @@ begin
112
119
  )
113
120
  puts "Created network interface: #{network_interface.name}"
114
121
 
122
+ ########################################################################################################################
123
+ ###################### Create Network Interface Async ######################
124
+ ########################################################################################################################
125
+
126
+ async_response = network.network_interfaces.create_async(
127
+ name: 'NetInt_Async',
128
+ resource_group: 'TestRG-NI',
129
+ location: LOCATION,
130
+ network_security_group_id: nsg.id,
131
+ subnet_id: "/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-NI/providers/Microsoft.Network/virtualNetworks/testVnet/subnets/mysubnet",
132
+ public_ip_address_id: "/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-NI/providers/Microsoft.Network/publicIPAddresses/mypubip2",
133
+ ip_configuration_name: 'testIpConfiguration',
134
+ private_ip_allocation_method: 'Dynamic',
135
+ tags: { key: 'value' },
136
+ enable_accelerated_networking: true
137
+ )
138
+
139
+ loop do
140
+ if async_response.pending?
141
+ sleep(2)
142
+ print '.'
143
+ end
144
+
145
+ if async_response.fulfilled?
146
+ puts "\nCreated/Updated NIC asynchronously! [#{async_response.value.name}]"
147
+ break
148
+ end
149
+
150
+ if async_response.rejected?
151
+ puts "\nERROR: Async NIC creation failed!\n#{async_response.reason.inspect}"
152
+ break
153
+ end
154
+ end
155
+
115
156
  ########################################################################################################################
116
157
  ###################### Get Network Interface and Update Resources ######################
117
158
  ########################################################################################################################
@@ -143,6 +184,9 @@ begin
143
184
 
144
185
  puts "Deleted network interface: #{nic.destroy}"
145
186
 
187
+ nic_async = network.network_interfaces.get('TestRG-NI', 'NetInt_Async')
188
+ puts "Deleted network interface #{nic_async.name}: #{nic_async.destroy}"
189
+
146
190
  pubip = network.public_ips.get('TestRG-NI', 'mypubip')
147
191
  pubip.destroy
148
192
 
@@ -14,6 +14,11 @@ class TestCreateNetworkInterface < Minitest::Test
14
14
  @network_interfaces.stub :create_or_update, mocked_response do
15
15
  assert_equal @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', 'fog-test-ip-address-id', 'fog-test-nsg-id', 'fog-test-ip-configuration', 'Dynamic', '10.0.0.8', ['id-1', 'id-2'], ['id-1', 'id-2'], @tags), mocked_response
16
16
  end
17
+
18
+ # Async
19
+ @network_interfaces.stub :create_or_update_async, mocked_response do
20
+ assert_equal @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', 'fog-test-ip-address-id', 'fog-test-nsg-id', 'fog-test-ip-configuration', 'Dynamic', '10.0.0.8', ['id-1', 'id-2'], ['id-1', 'id-2'], @tags, false, true), mocked_response
21
+ end
17
22
  end
18
23
 
19
24
  def test_create_network_interface_without_public_ip_success
@@ -21,6 +26,11 @@ class TestCreateNetworkInterface < Minitest::Test
21
26
  @network_interfaces.stub :create_or_update, mocked_response do
22
27
  assert_equal @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', nil, 'fog-test-nsg-id', 'fog-test-ip-configuration', 'Dynamic', '10.0.0.8', ['id-1', 'id-2'], ['id-1', 'id-2'], @tags), mocked_response
23
28
  end
29
+
30
+ # Async
31
+ @network_interfaces.stub :create_or_update_async, mocked_response do
32
+ assert_equal @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', nil, 'fog-test-nsg-id', 'fog-test-ip-configuration', 'Dynamic', '10.0.0.8', ['id-1', 'id-2'], ['id-1', 'id-2'], @tags, false, true), mocked_response
33
+ end
24
34
  end
25
35
 
26
36
  def test_create_network_interface_argument_error_failure
@@ -30,6 +40,13 @@ class TestCreateNetworkInterface < Minitest::Test
30
40
  @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', 'fog-test-ip-address-id', 'fog-test-nsg-id', 'fog-test-ip-configuration', ['id-1', 'id-2'], ['id-1', 'id-2'])
31
41
  end
32
42
  end
43
+
44
+ # Async
45
+ @network_interfaces.stub :create_or_update_async, response do
46
+ assert_raises ArgumentError do
47
+ @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', 'fog-test-ip-address-id', 'fog-test-nsg-id', 'fog-test-ip-configuration', ['id-1', 'id-2'], ['id-1', 'id-2'], false, true)
48
+ end
49
+ end
33
50
  end
34
51
 
35
52
  def test_create_network_interface_exception_failure
@@ -39,5 +56,12 @@ class TestCreateNetworkInterface < Minitest::Test
39
56
  @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', 'fog-test-ip-address-id', 'fog-test-nsg-id', 'fog-test-ip-configuration', 'Dynamic', '10.0.0.8', ['id-1', 'id-2'], ['id-1', 'id-2'], @tags)
40
57
  end
41
58
  end
59
+
60
+ # Async
61
+ @network_interfaces.stub :create_or_update_async, response do
62
+ assert_raises MsRestAzure::AzureOperationError do
63
+ @service.create_or_update_network_interface('fog-test-rg', 'fog-test-network-interface', 'West US', 'fog-test-subnet-id', 'fog-test-ip-address-id', 'fog-test-nsg-id', 'fog-test-ip-configuration', 'Dynamic', '10.0.0.8', ['id-1', 'id-2'], ['id-1', 'id-2'], @tags, false, true)
64
+ end
65
+ end
42
66
  end
43
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-azure-rm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaffan Chaudhry
@@ -18,7 +18,7 @@ authors:
18
18
  autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
- date: 2019-01-18 00:00:00.000000000 Z
21
+ date: 2019-02-28 00:00:00.000000000 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: rake