fog-softlayer 0.4.6 → 0.4.7

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTORS.md +1 -0
  3. data/examples/account.md +82 -0
  4. data/examples/compute.md +20 -4
  5. data/examples/network.md +6 -0
  6. data/lib/fog/softlayer.rb +5 -0
  7. data/lib/fog/softlayer/account.rb +66 -0
  8. data/lib/fog/softlayer/compute.rb +0 -2
  9. data/lib/fog/softlayer/models/account/brand.rb +50 -0
  10. data/lib/fog/softlayer/models/account/brands.rb +31 -0
  11. data/lib/fog/softlayer/models/compute/server.rb +52 -17
  12. data/lib/fog/softlayer/models/network/datacenter.rb +4 -0
  13. data/lib/fog/softlayer/network.rb +1 -1
  14. data/lib/fog/softlayer/requests/account/create_brand.rb +41 -0
  15. data/lib/fog/softlayer/requests/account/get_account_owned_brands.rb +58 -0
  16. data/lib/fog/softlayer/requests/account/get_brand.rb +36 -0
  17. data/lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb +111 -0
  18. data/lib/fog/softlayer/requests/network/get_maintenance_windows.rb +82 -0
  19. data/lib/fog/softlayer/requests/product/place_order.rb +7 -17
  20. data/lib/fog/softlayer/storage.rb +11 -0
  21. data/lib/fog/softlayer/version.rb +1 -1
  22. data/tests/softlayer/account/helper.rb +8 -0
  23. data/tests/softlayer/account/schema.rb +38 -0
  24. data/tests/softlayer/models/account/brand_tests.rb +66 -0
  25. data/tests/softlayer/models/compute/server_tests.rb +17 -2
  26. data/tests/softlayer/models/network/datacenter_tests.rb +32 -0
  27. data/tests/softlayer/network/helper.rb +8 -0
  28. data/tests/softlayer/network/schema.rb +20 -0
  29. data/tests/softlayer/requests/account/account_tests.rb +31 -0
  30. data/tests/softlayer/requests/account/brand_tests.rb +59 -0
  31. data/tests/softlayer/requests/compute/bmc_tests.rb +56 -1
  32. data/tests/softlayer/requests/compute/key_pair_tests.rb +0 -7
  33. data/tests/softlayer/requests/compute/tag_tests.rb +0 -1
  34. data/tests/softlayer/requests/compute/vm_tests.rb +60 -4
  35. data/tests/softlayer/requests/network/datacenter_tests.rb +44 -0
  36. metadata +21 -3
@@ -50,7 +50,7 @@ module Fog
50
50
  request :get_datacenters
51
51
  request :get_datacenter_routers
52
52
  request :get_references_by_tag_name
53
-
53
+ request :get_maintenance_windows
54
54
 
55
55
  request :create_network_tags
56
56
  request :delete_network_tags
@@ -0,0 +1,41 @@
1
+ #
2
+ # Author:: Matheus Francisco Barra Mina (<mfbmina@gmail.com>)
3
+ # © Copyright IBM Corporation 2015.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ module Fog
9
+ module Account
10
+ class Softlayer
11
+ class Mock
12
+ # Create a Brand
13
+ # @param [Hash] attributes
14
+ # @return [Excon::Response]
15
+ def create_brand(attributes)
16
+ raise ArgumentError, "Fog::Account::Softlayer#create_brand expects argument of type Hash" unless attributes.kind_of?(Hash)
17
+ response = Excon::Response.new
18
+ required = %w{keyName longName name account}
19
+ if Fog::Softlayer.valid_request?(required, attributes)
20
+ response.status = 201
21
+ response.body = { :id => Fog::Softlayer.mock_vm_id.to_i, :catalogId => 14 }.merge(attributes)
22
+ @brands << response.body
23
+ else
24
+ response.status = 500
25
+ response.body = {
26
+ "code" => "SoftLayer_Exception_MissingCreationProperty",
27
+ "error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Brand'."
28
+ }
29
+ end
30
+ response
31
+ end
32
+ end
33
+
34
+ class Real
35
+ def create_brand(attributes)
36
+ request(:brand, :create_object, :body => attributes, :http_method => :POST)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Author:: Matheus Francisco Barra Mina (<mfbmina@gmail.com>)
3
+ # © Copyright IBM Corporation 2015.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ module Fog
9
+ module Account
10
+ class Softlayer
11
+ class Mock
12
+ # Get all brands who are owned by account.
13
+ # @param [Integer] identifier
14
+ # @return [Excon::Response]
15
+ def get_account_owned_brands(identifier)
16
+ response = Excon::Response.new
17
+ response.status = 200
18
+ response.body = mocked_brands
19
+ if @accounts.select {|account| account['id'] == identifier.to_i }.empty?
20
+ response.status = 404
21
+ response.body = {
22
+ "error" => "Unable to find object with id of '#{identifier}'.",
23
+ "code"=>"SoftLayer_Exception_ObjectNotFound"
24
+ }
25
+ end
26
+ response
27
+ end
28
+ end
29
+
30
+ class Real
31
+ def get_account_owned_brands(identifier)
32
+ return request(:account, :getOwnedBrands) if identifier.nil?
33
+ request(:account, "#{identifier}/getOwnedBrands")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ module Fog
41
+ module Account
42
+ class Softlayer
43
+ class Mock
44
+ def mocked_brands
45
+ [
46
+ {
47
+ "catalogId"=>14,
48
+ "id"=>11111,
49
+ "keyName"=>"NAME",
50
+ "longName"=>"Name Name",
51
+ "name"=>"Name"
52
+ }
53
+ ]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Matheus Francisco Barra Mina (<mfbmina@gmail.com>)
3
+ # © Copyright IBM Corporation 2015.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ module Fog
9
+ module Account
10
+ class Softlayer
11
+ class Mock
12
+ # Get a Brand
13
+ # @param [Integer] identifier
14
+ # @return [Excon::Response]
15
+ def get_brand(identifier)
16
+ response = Excon::Response.new
17
+ response.body = @brands.select {|brand| brand[:id] == identifier.to_i }.first || {}
18
+ response.status = response.body.empty? ? 404 : 200
19
+ if response.status == 404
20
+ response.body = {
21
+ "error" => "Unable to find object with id of '#{identifier}'.",
22
+ "code"=>"SoftLayer_Exception_ObjectNotFound"
23
+ }
24
+ end
25
+ response
26
+ end
27
+ end
28
+
29
+ class Real
30
+ def get_brand(identifier)
31
+ request(:brand, identifier, :expected => [200, 404], :query => 'objectMask=mask[account]')
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,111 @@
1
+ #
2
+ # Author:: Matheus Francisco Barra Mina (<mfbmina@gmail.com>)
3
+ # © Copyright IBM Corporation 2015.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ module Fog
9
+ module Account
10
+ class Softlayer
11
+ class Mock
12
+ # Get all accounts who are owned by brand.
13
+ # @param [Integer] identifier
14
+ # @return [Excon::Response]
15
+ def get_brand_owned_accounts(identifier)
16
+ response = Excon::Response.new
17
+ if @brands.select {|brand| brand[:id] == identifier.to_i }.empty?
18
+ response.status = 404
19
+ response.body = {
20
+ "error" => "Unable to find object with id of '#{identifier}'.",
21
+ "code"=>"SoftLayer_Exception_ObjectNotFound"
22
+ }
23
+ else
24
+ response.status = 200
25
+ response.body = mocked_accounts
26
+ end
27
+ response
28
+ end
29
+ end
30
+
31
+ class Real
32
+ def get_brand_owned_accounts(identifier)
33
+ request(:brand, "#{identifier}/getOwnedAccounts")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ module Fog
42
+ module Account
43
+ class Softlayer
44
+ class Mock
45
+ def mocked_accounts
46
+ [
47
+ {
48
+ "accountManagedResourcesFlag"=>false,
49
+ "accountStatusId"=>1001,
50
+ "address1"=>"R 1",
51
+ "allowedPptpVpnQuantity"=>1,
52
+ "brandId"=>23456,
53
+ "city"=>"Itajuba",
54
+ "claimedTaxExemptTxFlag"=>false,
55
+ "companyName"=>"teste",
56
+ "country"=>"BR",
57
+ "createDate"=>"2015-06-10T17:06:27-03:00",
58
+ "email"=>"a@gmail.com",
59
+ "firstName"=>"Matheus2",
60
+ "id"=>23456,
61
+ "isReseller"=>0,
62
+ "lastName"=>"Mina2",
63
+ "lateFeeProtectionFlag"=>nil,
64
+ "modifyDate"=>"2015-06-10T17:06:31-03:00",
65
+ "postalCode"=>"37500-050",
66
+ "state"=>"OT",
67
+ "statusDate"=>nil,
68
+ "brand"=>
69
+ {
70
+ "catalogId"=>14,
71
+ "id"=>12345,
72
+ "keyName"=>"ALS",
73
+ "longName"=>"als",
74
+ "name"=>"als",
75
+ "ownedAccounts"=>
76
+ [
77
+ {
78
+ "accountManagedResourcesFlag"=>false,
79
+ "accountStatusId"=>1001,
80
+ "address1"=>"Av, 1303 Sl 10",
81
+ "address2"=>"Sl 11",
82
+ "allowedPptpVpnQuantity"=>2,
83
+ "brandId"=>44443,
84
+ "city"=>"Itajuba",
85
+ "claimedTaxExemptTxFlag"=>false,
86
+ "companyName"=>"Tecnologias LTDA",
87
+ "country"=>"BR",
88
+ "createDate"=>"2010-10-06T11:32:30-03:00",
89
+ "email"=>"sysadmin@example.com.br",
90
+ "firstName"=>"Xe",
91
+ "id"=>12345,
92
+ "isReseller"=>1,
93
+ "lastName"=>"Silva",
94
+ "lateFeeProtectionFlag"=>true,
95
+ "modifyDate"=>"2011-02-14T17:40:23-02:00",
96
+ "officePhone"=>"+55 35 3629-1616",
97
+ "postalCode"=>"37500-903",
98
+ "state"=>"OT",
99
+ "statusDate"=>nil,
100
+ "brand"=>nil
101
+ },
102
+ nil
103
+ ]
104
+ }
105
+ }
106
+ ]
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,82 @@
1
+ #
2
+ # Author:: Matheus Francisco Barra Mina (<mfbmina@gmail.com>)
3
+ # © Copyright IBM Corporation 2015.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ module Fog
9
+ module Network
10
+ class Softlayer
11
+ class Mock
12
+ def get_maintenance_windows(location_id, begin_date, end_date, slots_number)
13
+ raise ArgumentError, "Arguments for #{self.class.name}##{__method__} must be present." if begin_date.nil? || end_date.nil? || location_id.nil? || slots_number.nil?
14
+ response = Excon::Response.new
15
+ response.status = 200
16
+ response.body = get_windows
17
+ response
18
+ end
19
+
20
+ end
21
+
22
+ class Real
23
+ def get_maintenance_windows(location_id, begin_date, end_date, slots_number)
24
+ request(:provisioning_maintenance_window, :get_maintenance_windows, :body => [begin_date, end_date, location_id, slots_number], :http_method => :POST)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ module Fog
32
+ module Network
33
+ class Softlayer
34
+ class Mock
35
+ def get_windows
36
+ [
37
+ {
38
+ "beginDate"=>"2015-06-01T09:00:00-06:00",
39
+ "dayOfWeek"=>1,
40
+ "endDate"=>"2015-06-01T12:00:00-06:00",
41
+ "id"=>12570,
42
+ "locationId"=>265592,
43
+ "portalTzId"=>201
44
+ },
45
+ {
46
+ "beginDate"=>"2015-06-01T17:00:00-06:00",
47
+ "dayOfWeek"=>2,
48
+ "endDate"=>"2015-06-01T20:00:00-06:00",
49
+ "id"=>12584,
50
+ "locationId"=>265592,
51
+ "portalTzId"=>201
52
+ },
53
+ {
54
+ "beginDate"=>"2015-06-01T17:00:00-06:00",
55
+ "dayOfWeek"=>2,
56
+ "endDate"=>"2015-06-01T20:00:00-06:00",
57
+ "id"=>117748,
58
+ "locationId"=>265592,
59
+ "portalTzId"=>201
60
+ },
61
+ {
62
+ "beginDate"=>"2015-06-02T01:00:00-06:00",
63
+ "dayOfWeek"=>2,
64
+ "endDate"=>"2015-06-02T04:00:00-06:00",
65
+ "id"=>12568,
66
+ "locationId"=>265592,
67
+ "portalTzId"=>201
68
+ },
69
+ {
70
+ "beginDate"=>"2015-06-02T09:00:00-06:00",
71
+ "dayOfWeek"=>2,
72
+ "endDate"=>"2015-06-02T12:00:00-06:00",
73
+ "id"=>12591,
74
+ "locationId"=>265592,
75
+ "portalTzId"=>201
76
+ }
77
+ ]
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -7,7 +7,6 @@
7
7
  module Fog
8
8
  module Softlayer
9
9
  class Product
10
-
11
10
  class Mock
12
11
  def place_order(order_template)
13
12
  response = Excon::Response.new
@@ -16,21 +15,6 @@ module Fog
16
15
  return response
17
16
  end
18
17
 
19
- end
20
-
21
- class Real
22
- def place_order(order_template)
23
- request(:product_order, :place_order, :body => order_template, :http_method => :POST)
24
- end
25
- end
26
- end
27
- end
28
- end
29
-
30
- module Fog
31
- module Product
32
- class Softlayer
33
- class Mock
34
18
  def place_order_mock
35
19
  {
36
20
  "orderDate"=>"2015-04-17T11:12:12-06:00",
@@ -253,6 +237,12 @@ module Fog
253
237
  }
254
238
  end
255
239
  end
240
+
241
+ class Real
242
+ def place_order(order_template)
243
+ request(:product_order, :place_order, :body => order_template, :http_method => :POST)
244
+ end
245
+ end
256
246
  end
257
247
  end
258
- end
248
+ end
@@ -37,7 +37,14 @@ module Fog
37
37
  request :put_static_obj_manifest
38
38
  request :post_set_meta_temp_url_key
39
39
 
40
+ module Integrity
41
+ def validate_username!(name)
42
+ name =~ /:/ and raise ArgumentError, "Invalid username format. If you are using a Storage specific username, use only the part after the colon."
43
+ end
44
+ end
45
+
40
46
  class Mock
47
+ include Integrity
41
48
 
42
49
  def self.data
43
50
  @data ||= Hash.new do |hash, key|
@@ -52,6 +59,7 @@ module Fog
52
59
  def initialize(options={})
53
60
  @softlayer_api_key = options[:softlayer_api_key]
54
61
  @softlayer_username = options[:softlayer_username]
62
+ validate_username! @softlayer_username
55
63
  @path = '/v1/AUTH_1234'
56
64
  @containers = {}
57
65
  end
@@ -77,12 +85,15 @@ module Fog
77
85
  end
78
86
 
79
87
  class Real
88
+ include Integrity
89
+
80
90
  attr_reader :auth_url
81
91
  attr_accessor :auth_token, :auth_expires
82
92
 
83
93
  def initialize(options={})
84
94
  @api_key = options[:softlayer_api_key]
85
95
  @username = options[:softlayer_username]
96
+ validate_username! @username
86
97
  @cluster = options[:softlayer_cluster]
87
98
  @storage_account = options[:softlayer_storage_account] || default_storage_account(options[:softlayer_username], options[:softlayer_api_key])
88
99
  @connection_options = options[:connection_options] || {}
@@ -7,6 +7,6 @@
7
7
 
8
8
  module Fog
9
9
  module Softlayer
10
- VERSION = "0.4.6"
10
+ VERSION = "0.4.7"
11
11
  end
12
12
  end
@@ -0,0 +1,8 @@
1
+ #
2
+ # Author:: Matheus Francisco Barra Mina (<mfbmina@gmail.com>)
3
+ # © Copyright IBM Corporation 2015.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ require File.expand_path("schema", File.dirname(__FILE__))