azurex 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile +1 -1
  4. data/README.md +2 -0
  5. data/lib/azure.rb +3 -0
  6. data/lib/azure/base_management/management_http_request.rb +3 -3
  7. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +1 -9
  8. data/lib/azure/core/utility.rb +0 -71
  9. data/lib/azure/storage_management/serialization.rb +9 -12
  10. data/lib/azure/storage_management/storage_account.rb +1 -0
  11. data/lib/azure/storage_management/storage_management_service.rb +15 -18
  12. data/lib/azure/version.rb +1 -1
  13. data/lib/azure/virtual_machine_image_management/serialization.rb +15 -1
  14. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +31 -2
  15. data/lib/azure/virtual_machine_management/serialization.rb +1 -1
  16. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +4 -4
  17. data/lib/core_ext/ip_addr.rb +48 -0
  18. data/lib/core_ext/string.rb +27 -0
  19. data/test/fixtures/get_storage_account_properties.xml +6 -4
  20. data/test/fixtures/list_storage_accounts.xml +2 -0
  21. data/test/fixtures/list_vmimages.xml +86 -0
  22. data/test/fixtures/updated_storage_accounts.xml +2 -0
  23. data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
  24. data/test/integration/cloud_service/Cloud_Delete_test.rb +2 -2
  25. data/test/integration/storage_management/storage_management_test.rb +40 -33
  26. data/test/integration/vm/VM_Delete_test.rb +1 -1
  27. data/test/integration/vm_image/virtual_machine_image_test.rb +1 -1
  28. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +4 -4
  29. data/test/unit/core_ext/string_test.rb +11 -0
  30. data/test/unit/storage_management/serialization_test.rb +12 -13
  31. data/test/unit/storage_management/storage_management_service_test.rb +26 -40
  32. data/test/unit/virtual_machine_image_management/serialization_test.rb +17 -1
  33. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +113 -8
  34. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +17 -0
  35. metadata +6 -2
@@ -0,0 +1,48 @@
1
+ # Code validate private/public IP acceptable ranges.
2
+ class IPAddr
3
+ PRIVATE_RANGES = [
4
+ IPAddr.new('10.0.0.0/8'),
5
+ IPAddr.new('172.16.0.0/12'),
6
+ IPAddr.new('192.168.0.0/16')
7
+ ]
8
+
9
+ def private?
10
+ return false unless self.ipv4?
11
+ PRIVATE_RANGES.each do |ipr|
12
+ return true if ipr.include?(self)
13
+ end
14
+ false
15
+ end
16
+
17
+ def public?
18
+ !private?
19
+ end
20
+
21
+ class << self
22
+ def validate_ip_and_prefix(ip, cidr)
23
+ if cidr.to_s.empty?
24
+ raise "Cidr is missing for IP '#{ip}'."
25
+ elsif valid?(ip)
26
+ raise "Ip address '#{ip}' is invalid."
27
+ elsif !IPAddr.new(ip).private?
28
+ raise "Ip Address #{ip} must be private."
29
+ end
30
+ end
31
+
32
+ def validate_address_space(ip)
33
+ if ip.split('/').size != 2
34
+ raise "Cidr is invalid for IP #{ip}."
35
+ elsif valid?(ip)
36
+ raise "Address space '#{ip}' is invalid."
37
+ end
38
+ end
39
+
40
+ def address_prefix(ip, cidr)
41
+ ip + '/' + cidr.to_s
42
+ end
43
+
44
+ def valid?(ip)
45
+ (IPAddr.new(ip) rescue nil).nil?
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ class String
2
+ { reset: 0,
3
+ bold: 1,
4
+ dark: 2,
5
+ underline: 4,
6
+ blink: 5,
7
+ orange: 6,
8
+ negative: 7,
9
+ black: 30,
10
+ red: 31,
11
+ green: 32,
12
+ yellow: 33,
13
+ blue: 34,
14
+ magenta: 35,
15
+ cyan: 36,
16
+ white: 37,
17
+ }.each do |key, value|
18
+ define_method key do
19
+ "\e[#{value}m" + self + "\e[0m"
20
+ end
21
+ end
22
+
23
+ def resembles_base64?
24
+ self.chomp.length % 4 == 0 && self.chomp =~ /^[A-Za-z0-9+\/=]+\Z/
25
+ end
26
+ end
27
+
@@ -14,11 +14,13 @@
14
14
  <Endpoint>http://storageacc.queue.core.windows.net/</Endpoint>
15
15
  <Endpoint>http://storageacc.table.core.windows.net/</Endpoint>
16
16
  </Endpoints>
17
- <GeoReplicationEnabled>false</GeoReplicationEnabled>
18
- <GeoPrimaryRegion>East US</GeoPrimaryRegion>
19
- <GeoSecondaryRegion/>
20
- <CreationTime>2013-12-03T19:39:33Z</CreationTime>
17
+ <GeoPrimaryRegion>West US</GeoPrimaryRegion>
18
+ <StatusOfPrimary>Available</StatusOfPrimary>
19
+ <GeoSecondaryRegion>East US</GeoSecondaryRegion>
20
+ <StatusOfSecondary>Available</StatusOfSecondary>
21
+ <CreationTime>2013-03-06T09:34:37Z</CreationTime>
21
22
  <CustomDomains/>
23
+ <AccountType>Standard_GRS</AccountType>
22
24
  </StorageServiceProperties>
23
25
  <ExtendedProperties>
24
26
  <ExtendedProperty>
@@ -19,6 +19,7 @@
19
19
  <StatusOfPrimary/>
20
20
  <GeoSecondaryRegion>East US</GeoSecondaryRegion>
21
21
  <StatusOfSecondary/>
22
+ <AccountType>Standard_GRS</AccountType>
22
23
  </StorageServiceProperties>
23
24
  <ExtendedProperties/>
24
25
  </StorageService>
@@ -40,6 +41,7 @@
40
41
  <StatusOfPrimary/>
41
42
  <GeoSecondaryRegion>East US</GeoSecondaryRegion>
42
43
  <StatusOfSecondary/>
44
+ <AccountType>Standard_GRS</AccountType>
43
45
  </StorageServiceProperties>
44
46
  <ExtendedProperties/>
45
47
  </StorageService>
@@ -0,0 +1,86 @@
1
+ <VMImages xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
2
+ <VMImage>
3
+ <Name>name-of-image</Name>
4
+ <Label>identifier-of-image</Label>
5
+ <Category>category-of-image</Category>
6
+ <Description>description-of-image</Description>
7
+ <OSDiskConfiguration>
8
+ <Name>name-of-operating-system-disk</Name>
9
+ <HostCaching>caching-mode-of-disk</HostCaching>
10
+ <OSState>state-of-disk</OSState>
11
+ <OS>operating-system-of-image</OS>
12
+ <MediaLink>path-to-vhd</MediaLink>
13
+ <LogicalDiskSizeInGB>size-of-disk</LogicalDiskSizeInGB>
14
+ </OSDiskConfiguration>
15
+ <DataDiskConfigurations>
16
+ <DataDiskConfiguration>
17
+ <Name>name-of-data-disk</Name>
18
+ <HostCaching>caching-mode-of-disk</HostCaching>
19
+ <Lun>logical-unit-number</Lun>
20
+ <MediaLink>path-to-vhd</MediaLink>
21
+ <LogicalDiskSizeInGB>size-of-disk</LogicalDiskSizeInGB>
22
+ </DataDiskConfigurations>
23
+ </DataDiskConfiguration>
24
+ <ServiceName>name-of-cloud-service</ServiceName>
25
+ <DeploymentName>name-of-deployment</DeploymentName>
26
+ <RoleName>name-of-virtual-machine</RoleName>
27
+ <Location>geo-location-of-image-blobs</Location>
28
+ <AffinityGroup>name-of-affinity-group</AffinityGroup>
29
+ <CreatedTime>creation-time-of-image</CreatedTime>
30
+ <ModifiedTime>modification-time-of-image</ModifiedTime>
31
+ <Language>language-of-image</Language>
32
+ <ImageFamily>image-family</ImageFamily>
33
+ <RecommendedVMSize>size-of-virtual-machine</RecommendedVMSize>
34
+ <IsPremium>indicator-of-image-status</IsPremium>
35
+ <Eula>image-eula</Eula>
36
+ <IconUri>uri-of-icon</IconUri>
37
+ <SmallIconUri>uri-of-icon</SmallIconUri>
38
+ <PrivacyUri>uri-of-privacy-policy</PrivacyUri>
39
+ <PublisherName>publisher-identifier</PublisherName>
40
+ <PublishedDate>published-date</PublishedDate>
41
+ <ShowInGui>indicator-of-availability</ShowInGui>
42
+ <PricingDetailLink>pricing-details</PricingDetailLink>
43
+ </VMImage>
44
+ <VMImage>
45
+ <Name>name-of-image-2</Name>
46
+ <Label>identifier-of-image-2</Label>
47
+ <Category>category-of-image-2</Category>
48
+ <Description>description-of-image-2</Description>
49
+ <OSDiskConfiguration>
50
+ <Name>name-of-operating-system-disk-2</Name>
51
+ <HostCaching>caching-mode-of-disk-2</HostCaching>
52
+ <OSState>state-of-disk-2</OSState>
53
+ <OS>operating-system-of-image-2</OS>
54
+ <MediaLink>path-to-vhd-2</MediaLink>
55
+ <LogicalDiskSizeInGB>size-of-disk-2</LogicalDiskSizeInGB>
56
+ </OSDiskConfiguration>
57
+ <DataDiskConfigurations>
58
+ <DataDiskConfiguration>
59
+ <Name>name-of-data-disk-2</Name>
60
+ <HostCaching>caching-mode-of-disk-2</HostCaching>
61
+ <Lun>logical-unit-number-2</Lun>
62
+ <MediaLink>path-to-vhd-2</MediaLink>
63
+ <LogicalDiskSizeInGB>size-of-disk-2</LogicalDiskSizeInGB>
64
+ </DataDiskConfigurations>
65
+ </DataDiskConfiguration>
66
+ <ServiceName>name-of-cloud-service-2</ServiceName>
67
+ <DeploymentName>name-of-deployment-2</DeploymentName>
68
+ <RoleName>name-of-virtual-machine-2</RoleName>
69
+ <Location>geo-location-of-image-blobs-2</Location>
70
+ <AffinityGroup>name-of-affinity-group-2</AffinityGroup>
71
+ <CreatedTime>creation-time-of-image-2</CreatedTime>
72
+ <ModifiedTime>modification-time-of-image-2</ModifiedTime>
73
+ <Language>language-of-image-2</Language>
74
+ <ImageFamily>image-family-2</ImageFamily>
75
+ <RecommendedVMSize>size-of-virtual-machine-2</RecommendedVMSize>
76
+ <IsPremium>indicator-of-image-status-2</IsPremium>
77
+ <Eula>image-eula-2</Eula>
78
+ <IconUri>uri-of-icon-2</IconUri>
79
+ <SmallIconUri>uri-of-icon-2</SmallIconUri>
80
+ <PrivacyUri>uri-of-privacy-policy-2</PrivacyUri>
81
+ <PublisherName>publisher-identifier-2</PublisherName>
82
+ <PublishedDate>published-date-2</PublishedDate>
83
+ <ShowInGui>indicator-of-availability-2</ShowInGui>
84
+ <PricingDetailLink>pricing-details-2</PricingDetailLink>
85
+ </VMImage>
86
+ </VMImages>
@@ -18,6 +18,7 @@
18
18
  <StatusOfPrimary/>
19
19
  <GeoSecondaryRegion>East US</GeoSecondaryRegion>
20
20
  <StatusOfSecondary/>
21
+ <AccountType>Standard_GRS</AccountType>
21
22
  </StorageServiceProperties>
22
23
  <ExtendedProperties/>
23
24
  </StorageService>
@@ -38,6 +39,7 @@
38
39
  <StatusOfPrimary/>
39
40
  <GeoSecondaryRegion>East US</GeoSecondaryRegion>
40
41
  <StatusOfSecondary/>
42
+ <AccountType>Standard_GRS</AccountType>
41
43
  </StorageServiceProperties>
42
44
  <ExtendedProperties>
43
45
  <ExtendedProperty>
@@ -47,7 +47,7 @@ describe Azure::BaseManagementService do
47
47
  exception = assert_raises(RuntimeError) do
48
48
  subject.create_affinity_group(affinity_group_name, 'North West', label)
49
49
  end
50
- assert_match(/Allowed values are East Asia/i, exception.message)
50
+ assert_match(/'location' is invalid/i, exception.message)
51
51
  end
52
52
 
53
53
  it 'create new affinity group without optional params' do
@@ -37,8 +37,8 @@ describe Azure::CloudServiceManagementService do
37
37
 
38
38
  it 'Deletes the cloud service in Windows Azure.' do
39
39
  subject.delete_cloud_service(@cloud_name)
40
- present = subject.get_cloud_service(@cloud_name)
41
- assert_equal present, false
40
+ cloud_service = subject.get_cloud_service(@cloud_name)
41
+ cloud_service.must_equal nil
42
42
  end
43
43
  end
44
44
  end
@@ -47,9 +47,9 @@ describe Azure::StorageManagementService do
47
47
  storagelist.must_be_kind_of Array
48
48
  end
49
49
 
50
- it 'get storage account' do
50
+ it 'get_storage_account return nil if storage account with given name not exists' do
51
51
  storage = subject.get_storage_account('nonexistentstorage')
52
- storage.must_equal false
52
+ storage.must_equal nil
53
53
  end
54
54
 
55
55
  it 'create storage account' do
@@ -60,18 +60,18 @@ describe Azure::StorageManagementService do
60
60
  geo_replication_enabled: 'false'
61
61
  }
62
62
  subject.create_storage_account(storage_name, options)
63
- present = subject.get_storage_account(storage_name)
64
- present.must_equal true
63
+ storage_account = subject.get_storage_account(storage_name)
64
+ storage_account.must_be_kind_of Azure::StorageManagement::StorageAccount
65
65
  # Test for delete storage account
66
66
  subject.delete_storage_account(storage_name)
67
- present = subject.get_storage_account(storage_name)
68
- present.must_equal false
67
+ storage_account = subject.get_storage_account(storage_name)
68
+ storage_account.must_equal nil
69
69
  end
70
70
 
71
71
  it 'get storage account' do
72
72
  storage_name = StorageName
73
- present = subject.get_storage_account(storage_name)
74
- present.must_equal true
73
+ storage_account = subject.get_storage_account(storage_name)
74
+ storage_account.must_be_kind_of Azure::StorageManagement::StorageAccount
75
75
  end
76
76
 
77
77
  it 'get storage account properties' do
@@ -79,7 +79,7 @@ describe Azure::StorageManagementService do
79
79
  storage = subject.get_storage_account_properties(storage_name)
80
80
  storage.name.must_equal storage_name
81
81
  storage.label.must_equal 'storagelabel'
82
- storage.geo_replication_enabled.must_equal 'true'
82
+ storage.account_type.must_equal 'Standard_GRS'
83
83
  end
84
84
 
85
85
  it 'regenerate storage account keys' do
@@ -96,20 +96,7 @@ describe Azure::StorageManagementService do
96
96
  storage_name = StorageName
97
97
  storage_keys1 = subject.get_storage_account_keys(storage_name)
98
98
  storage_keys1.primary_key.wont_be_nil
99
- storage_keys1.secondary_key.wont_be_nil
100
- end
101
-
102
- it 'update storage account' do
103
- options = {
104
- label: 'labelchanged',
105
- description: 'description changed'
106
- }
107
- storage_name = StorageName
108
- subject.update_storage_account(storage_name, options)
109
- storage = subject.get_storage_account_properties(storage_name)
110
- storage.name.must_equal storage_name
111
- storage.label.must_equal 'labelchanged'
112
- subject.update_storage_account(storage_name, opts)
99
+ storage_keys1.secondary_key.wont_be_nil
113
100
  end
114
101
 
115
102
  it 'get storage account properties error' do
@@ -160,18 +147,38 @@ describe Azure::StorageManagementService do
160
147
  assert_match('The affinity group does not exist.', exception.message)
161
148
  end
162
149
 
163
- it 'update storage account with non existent storage name' do
164
- options = {
165
- label: 'labelchanged',
166
- description: 'description changed'
167
- }
168
- storage_name = 'storage_nonexistent'
169
- storage = subject.update_storage_account(storage_name, options)
170
- assert_match(/Storage Account 'storage_nonexistent' does not exist. Skipped.../, storage)
171
- end
172
-
173
150
  it 'delete storage account that does not exist' do
174
151
  msg = subject.delete_storage_account('invalidstorageaccount')
175
152
  assert_match(/The storage account 'invalidstorageaccount' was not found./, msg)
176
153
  end
154
+
155
+ describe '#update_storage_account' do
156
+
157
+ it 'update storage account with non existent storage name' do
158
+ options = {
159
+ label: 'labelchanged',
160
+ description: 'description changed'
161
+ }
162
+ storage_name = 'storage_nonexistent'
163
+ storage = subject.update_storage_account(storage_name, options)
164
+ error_msg = "Storage Account 'storage_nonexistent' does not exist"
165
+ assert_match(/#{error_msg}/, storage)
166
+ end
167
+
168
+ it 'update existing storage account' do
169
+ options = {
170
+ label: 'labelchanged',
171
+ description: 'description changed',
172
+ account_type: 'Standard_LRS'
173
+ }
174
+ storage_name = StorageName
175
+ subject.update_storage_account(storage_name, options)
176
+ storage = subject.get_storage_account_properties(storage_name)
177
+ storage.name.must_equal storage_name
178
+ storage.label.must_equal 'labelchanged'
179
+ storage.account_type.must_equal 'Standard_LRS'
180
+ opts[:account_type] = 'Standard_GRS'
181
+ subject.update_storage_account(storage_name, opts)
182
+ end
183
+ end
177
184
  end
@@ -45,7 +45,7 @@ describe Azure::VirtualMachineManagementService do
45
45
  vm.must_be_nil
46
46
  cloud_service = Azure::CloudServiceManagementService.new
47
47
  cloud_presence = cloud_service.get_cloud_service(csn)
48
- cloud_presence.must_equal false
48
+ cloud_presence.must_equal nil
49
49
  end
50
50
 
51
51
  end
@@ -34,4 +34,4 @@ describe Azure::VirtualMachineImageManagementService do
34
34
 
35
35
  end
36
36
 
37
- end
37
+ end
@@ -66,14 +66,14 @@ describe Azure::CloudServiceManagementService do
66
66
  subject.get_cloud_service 'cloud-service-1'
67
67
  end
68
68
 
69
- it 'returns true if found cloud service with given name' do
69
+ it 'return cloud service instance if found cloud service with given name' do
70
70
  result = subject.get_cloud_service 'cloud-service-1'
71
- result.must_equal true
71
+ result.must_be_kind_of Azure::CloudServiceManagement::CloudService
72
72
  end
73
73
 
74
- it "returns false if cloud service with given name doesn't exists" do
74
+ it "returns nil if cloud service with given name doesn't exists" do
75
75
  result = subject.get_cloud_service 'cloud-service-3'
76
- result.must_equal false
76
+ result.must_equal nil
77
77
  end
78
78
  end
79
79
 
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+ require 'base64'
3
+ require 'core_ext/string'
4
+
5
+ describe "string_extensions" do
6
+ it "can guess reasonably if a string is base64" do
7
+ sample_string = "so many cloud platforms"
8
+ enc_string = Base64.encode64(sample_string)
9
+ assert enc_string.resembles_base64?
10
+ end
11
+ end
@@ -34,7 +34,7 @@ describe Azure::StorageManagement::Serialization do
34
34
  end
35
35
 
36
36
  describe "#storage_services_to_xml" do
37
- let(:storage_service_name) {'storage-service'}
37
+ let(:storage_service_name) { 'storage-service' }
38
38
  let(:storage_options) { {
39
39
  :extended_properties=> {
40
40
  :prop_1_name=>"prop_1_value"
@@ -57,14 +57,18 @@ describe Azure::StorageManagement::Serialization do
57
57
  end
58
58
 
59
59
  it "serializes the options hash to xml" do
60
- results = subject.storage_services_to_xml(storage_service_name, {:location => 'East US'})
60
+ results = subject.storage_services_to_xml(storage_service_name, :location => 'East US')
61
61
  doc = Nokogiri::XML results
62
62
  doc.css('Location').text.must_equal 'East US'
63
63
  results.must_be_kind_of String
64
64
  end
65
65
 
66
66
  it "uses affinity_group from the hash instead of location" do
67
- results = subject.storage_services_to_xml(storage_service_name, {:affinity_group_name => 'my-affinity-group', :location => 'East US'})
67
+ params = {
68
+ :affinity_group_name => 'my-affinity-group',
69
+ :location => 'East US'
70
+ }
71
+ results = subject.storage_services_to_xml(storage_service_name, params)
68
72
  doc = Nokogiri::XML results
69
73
  doc.css('AffinityGroup').text.must_equal 'my-affinity-group'
70
74
  results.must_be_kind_of String
@@ -142,15 +146,10 @@ describe Azure::StorageManagement::Serialization do
142
146
  }
143
147
  }
144
148
 
145
- let(:no_options_message) {'No options specified'}
146
- let(:label_or_desc_required) { 'Either one of Label or Description has to be provided. Both cannot be empty' }
147
-
148
- it "checks if the parameter is nil" do
149
- exception = assert_raises RuntimeError do
150
- subject.storage_update_to_xml nil
151
- end
152
- assert_match no_options_message, exception.message
153
- end
149
+ let(:no_options_message) { 'No options specified' }
150
+ let(:label_or_desc_required) {
151
+ 'Either one of Label or Description has to be provided.'
152
+ }
154
153
 
155
154
  it "checks if the parameter is empty" do
156
155
  exception = assert_raises RuntimeError do
@@ -232,7 +231,7 @@ describe Azure::StorageManagement::Serialization do
232
231
 
233
232
  describe "#regenerate_storage_account_keys_from_xml" do
234
233
  let(:storage_services_access_keys) { Fixtures["storage_service_keys"] }
235
-
234
+
236
235
  it "returns an Array of StorageService instances" do
237
236
  storage_keys_xml = Nokogiri::XML(storage_services_access_keys)
238
237
  result = subject.storage_account_keys_from_xml storage_keys_xml