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.
- checksums.yaml +4 -4
- data/CONTRIBUTORS.md +1 -0
- data/examples/account.md +82 -0
- data/examples/compute.md +20 -4
- data/examples/network.md +6 -0
- data/lib/fog/softlayer.rb +5 -0
- data/lib/fog/softlayer/account.rb +66 -0
- data/lib/fog/softlayer/compute.rb +0 -2
- data/lib/fog/softlayer/models/account/brand.rb +50 -0
- data/lib/fog/softlayer/models/account/brands.rb +31 -0
- data/lib/fog/softlayer/models/compute/server.rb +52 -17
- data/lib/fog/softlayer/models/network/datacenter.rb +4 -0
- data/lib/fog/softlayer/network.rb +1 -1
- data/lib/fog/softlayer/requests/account/create_brand.rb +41 -0
- data/lib/fog/softlayer/requests/account/get_account_owned_brands.rb +58 -0
- data/lib/fog/softlayer/requests/account/get_brand.rb +36 -0
- data/lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb +111 -0
- data/lib/fog/softlayer/requests/network/get_maintenance_windows.rb +82 -0
- data/lib/fog/softlayer/requests/product/place_order.rb +7 -17
- data/lib/fog/softlayer/storage.rb +11 -0
- data/lib/fog/softlayer/version.rb +1 -1
- data/tests/softlayer/account/helper.rb +8 -0
- data/tests/softlayer/account/schema.rb +38 -0
- data/tests/softlayer/models/account/brand_tests.rb +66 -0
- data/tests/softlayer/models/compute/server_tests.rb +17 -2
- data/tests/softlayer/models/network/datacenter_tests.rb +32 -0
- data/tests/softlayer/network/helper.rb +8 -0
- data/tests/softlayer/network/schema.rb +20 -0
- data/tests/softlayer/requests/account/account_tests.rb +31 -0
- data/tests/softlayer/requests/account/brand_tests.rb +59 -0
- data/tests/softlayer/requests/compute/bmc_tests.rb +56 -1
- data/tests/softlayer/requests/compute/key_pair_tests.rb +0 -7
- data/tests/softlayer/requests/compute/tag_tests.rb +0 -1
- data/tests/softlayer/requests/compute/vm_tests.rb +60 -4
- data/tests/softlayer/requests/network/datacenter_tests.rb +44 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd484e83287b20edfcfd073db47bd291faed8c06
|
4
|
+
data.tar.gz: da6511cbe65a7f13426558dd2007731fa3ef86f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98c102483e5a54a01c83d435cdaacaa12b0b22bff8cc095d3648b94f0e178c3776df48956e32276ae5c640952bd5106b995a9638d3679b3e48dc18bd0f9f6a12
|
7
|
+
data.tar.gz: bb8e4e8106d2af87c0cd99833f5e55c811bf52ba80476ef4e272c2a2ea4de9b50411c35144054a53cf087bce0c820213ee96821f54876fc0400445d1d48ef1dd
|
data/CONTRIBUTORS.md
CHANGED
data/examples/account.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
### Account Examples
|
2
|
+
|
3
|
+
If you are unfamiliar with fog, we recommend reading our [getting started](getting_started.md) guide.
|
4
|
+
|
5
|
+
|
6
|
+
#### Create a connection to SoftLayer Account Service
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require 'fog/softlayer'
|
10
|
+
@sl = Fog::Account[:softlayer]
|
11
|
+
```
|
12
|
+
|
13
|
+
1. Create a sub-brand (First way)
|
14
|
+
```ruby
|
15
|
+
attributes = {
|
16
|
+
'key_name' => "T_B",
|
17
|
+
'long_name' => "Long Test Brand Name",
|
18
|
+
'name' => "My name",
|
19
|
+
'account' => {
|
20
|
+
address1: "Street",
|
21
|
+
city: "City",
|
22
|
+
companyName: "Example",
|
23
|
+
country: "BR",
|
24
|
+
email: "example@example.com",
|
25
|
+
firstName: "FirstName",
|
26
|
+
lastName: "LastName",
|
27
|
+
postalCode: "0000-000",
|
28
|
+
state: "EX"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
@brand = @sl.brands.create(attributes)
|
32
|
+
```
|
33
|
+
|
34
|
+
1. Create a sub-brand (Second way)
|
35
|
+
```ruby
|
36
|
+
attributes = {
|
37
|
+
'key_name' => "T_B",
|
38
|
+
'long_name' => "Long Test Brand Name",
|
39
|
+
'name' => "My name",
|
40
|
+
'account' => {
|
41
|
+
address1: "Street",
|
42
|
+
city: "City",
|
43
|
+
companyName: "Example",
|
44
|
+
country: "BR",
|
45
|
+
email: "example@example.com",
|
46
|
+
firstName: "FirstName",
|
47
|
+
lastName: "LastName",
|
48
|
+
postalCode: "0000-000",
|
49
|
+
state: "EX"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
@brand = @sl.brands.new(attributes)
|
53
|
+
@brand.save
|
54
|
+
```
|
55
|
+
|
56
|
+
1. Create a sub-brand (Third way)
|
57
|
+
```ruby
|
58
|
+
attributes = {
|
59
|
+
'key_name' => "T_B",
|
60
|
+
'long_name' => "Long Test Brand Name",
|
61
|
+
'name' => "My name",
|
62
|
+
'account' => {
|
63
|
+
address1: "Street",
|
64
|
+
city: "City",
|
65
|
+
companyName: "Example",
|
66
|
+
country: "BR",
|
67
|
+
email: "example@example.com",
|
68
|
+
firstName: "FirstName",
|
69
|
+
lastName: "LastName",
|
70
|
+
postalCode: "0000-000",
|
71
|
+
state: "EX"
|
72
|
+
}
|
73
|
+
}
|
74
|
+
@brand = @sl.brands.new(attributes)
|
75
|
+
@brand.create
|
76
|
+
```
|
77
|
+
|
78
|
+
1. Get all brand accounts
|
79
|
+
```ruby
|
80
|
+
@brand = @sl.brands.get(id)
|
81
|
+
@brand.get_accounts
|
82
|
+
```
|
data/examples/compute.md
CHANGED
@@ -332,15 +332,31 @@ If you are unfamiliar with fog, we recommend reading our [getting started](getti
|
|
332
332
|
server.get_upgrade_options
|
333
333
|
```
|
334
334
|
|
335
|
-
1. Update a server.
|
335
|
+
1. Update a virtual guest server.
|
336
|
+
Hash keys are the categories and the hash values are the capacity. You can retrieve them from upgrade options.
|
336
337
|
|
337
338
|
```ruby
|
338
339
|
new_attributes = {
|
339
|
-
:
|
340
|
-
:
|
341
|
-
:
|
340
|
+
:guest_core => 2,
|
341
|
+
:ram => 1, # this value is in GBs
|
342
|
+
:port_speed => 100, # this value is in MPBSs
|
342
343
|
:time => Time.now + 5.minutes # if you don't specify, time will be equal to now
|
343
344
|
}
|
345
|
+
|
346
|
+
server = @sl.servers.get(123456)
|
347
|
+
server.update(new_attributes)
|
348
|
+
```
|
349
|
+
|
350
|
+
1. Update a bare metal server.
|
351
|
+
Hash keys are the categories and the hash values are the capacity. You can retrieve them from upgrade options.
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
new_attributes = {
|
355
|
+
:ram => 4, # this value is in GBs
|
356
|
+
:port_speed => 100, # this value is in MPBSs
|
357
|
+
:maintenance_window => 1111 # should see examples/network "Get a datacenter maintenance windows."
|
358
|
+
}
|
359
|
+
|
344
360
|
server = @sl.servers.get(123456)
|
345
361
|
server.update(new_attributes)
|
346
362
|
```
|
data/examples/network.md
CHANGED
@@ -275,3 +275,9 @@ If you are unfamiliar with fog, we recommend reading our [getting started](getti
|
|
275
275
|
# You can't delete a network if it has actively routed addresses...
|
276
276
|
```
|
277
277
|
|
278
|
+
1. Get a datacenter maintenance windows.
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
dc = @sl.datacenters.by_name('YOUR_DATACENTER')
|
282
|
+
dc.get_maintenance_windows(begin_date, end_date, slots_number) # dates need be a Datetime
|
283
|
+
```
|
data/lib/fog/softlayer.rb
CHANGED
@@ -13,6 +13,10 @@ require File.expand_path('../softlayer/ext/string', __FILE__)
|
|
13
13
|
require File.expand_path('../softlayer/ext/hash', __FILE__) unless {}.respond_to? :deep_merge
|
14
14
|
|
15
15
|
module Fog
|
16
|
+
module Account
|
17
|
+
autoload :Softlayer, File.expand_path('../softlayer/account', __FILE__)
|
18
|
+
end
|
19
|
+
|
16
20
|
module Compute
|
17
21
|
autoload :Softlayer, File.expand_path('../softlayer/compute', __FILE__)
|
18
22
|
end
|
@@ -38,6 +42,7 @@ module Fog
|
|
38
42
|
SL_API_URL = 'api.softlayer.com/rest/v3' unless defined? SL_API_URL
|
39
43
|
SL_STORAGE_AUTH_URL = 'objectstorage.softlayer.net/auth/v1.0' unless defined? SL_STORAGE_AUTH_URL
|
40
44
|
|
45
|
+
service(:account, 'Account')
|
41
46
|
service(:compute, 'Compute')
|
42
47
|
service(:dns, 'DNS')
|
43
48
|
service(:network, 'Network')
|
@@ -0,0 +1,66 @@
|
|
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 'fog/softlayer/compute/shared'
|
9
|
+
|
10
|
+
module Fog
|
11
|
+
module Account
|
12
|
+
class Softlayer < Fog::Service
|
13
|
+
# Client credentials
|
14
|
+
requires :softlayer_username, :softlayer_api_key
|
15
|
+
|
16
|
+
model_path 'fog/softlayer/models/account'
|
17
|
+
collection :brands
|
18
|
+
model :brand
|
19
|
+
|
20
|
+
request_path 'fog/softlayer/requests/account'
|
21
|
+
request :create_brand
|
22
|
+
request :get_account_owned_brands
|
23
|
+
request :get_brand
|
24
|
+
request :get_brand_owned_accounts
|
25
|
+
|
26
|
+
# The Mock Service allows you to run a fake instance of the Service
|
27
|
+
# which makes no real connections.
|
28
|
+
#
|
29
|
+
#
|
30
|
+
class Mock
|
31
|
+
include Fog::Softlayer::Compute::Shared
|
32
|
+
|
33
|
+
def initialize(options={})
|
34
|
+
@brands = []
|
35
|
+
@accounts = [{'id' => 1}]
|
36
|
+
super(options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def credentials
|
40
|
+
{ :provider => 'softlayer',
|
41
|
+
:softlayer_username => @softlayer_username,
|
42
|
+
:softlayer_api_key => @softlayer_api_key
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Makes real connections to Softlayer.
|
49
|
+
#
|
50
|
+
class Real
|
51
|
+
include Fog::Softlayer::Slapi
|
52
|
+
include Fog::Softlayer::Compute::Shared
|
53
|
+
|
54
|
+
def initialize(options={})
|
55
|
+
@softlayer_api_key = options[:softlayer_api_key]
|
56
|
+
@softlayer_username = options[:softlayer_username]
|
57
|
+
end
|
58
|
+
|
59
|
+
def request(service, path, options = {})
|
60
|
+
options = {:username => @softlayer_username, :api_key => @softlayer_api_key}.merge(options)
|
61
|
+
Fog::Softlayer::Slapi.slapi_request(service, path, options)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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 Brand < Fog::Model
|
12
|
+
identity :id, :type => :integer
|
13
|
+
attribute :catalog_id, :aliases => 'catalogId', :type => :integer
|
14
|
+
attribute :key_name, :aliases => 'keyName'
|
15
|
+
attribute :long_name, :aliases => 'longName'
|
16
|
+
attribute :name
|
17
|
+
attribute :account
|
18
|
+
|
19
|
+
def initialize(attributes = {})
|
20
|
+
super(attributes)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_accounts
|
24
|
+
service.get_brand_owned_accounts(id).body
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
return create if attributes[:id].nil?
|
29
|
+
raise StandardError, "Update is not implemented"
|
30
|
+
end
|
31
|
+
|
32
|
+
def create
|
33
|
+
template = create_template
|
34
|
+
service.create_brand(template).body
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def create_template
|
40
|
+
{
|
41
|
+
keyName: attributes[:key_name],
|
42
|
+
longName: attributes[:long_name],
|
43
|
+
name: attributes[:name],
|
44
|
+
account: attributes[:account]
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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 'fog/softlayer/models/account/brand'
|
9
|
+
|
10
|
+
module Fog
|
11
|
+
module Account
|
12
|
+
class Softlayer
|
13
|
+
class Brands < Fog::Collection
|
14
|
+
model Fog::Account::Softlayer::Brand
|
15
|
+
|
16
|
+
def all
|
17
|
+
data = service.get_account_owned_brands
|
18
|
+
load(data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(identifier)
|
22
|
+
return nil if identifier.nil? || identifier == ""
|
23
|
+
data = service.get_brand(identifier).body
|
24
|
+
new.merge_attributes(data)
|
25
|
+
rescue Excon::Errors::NotFound
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -362,11 +362,12 @@ module Fog
|
|
362
362
|
service.get_virtual_guest_upgrade_item_prices(id).body
|
363
363
|
end
|
364
364
|
|
365
|
-
def update(update_attributes
|
366
|
-
raise
|
365
|
+
def update(update_attributes)
|
366
|
+
raise ArgumentError if update_attributes.nil?
|
367
|
+
product_connection
|
367
368
|
prices = get_item_prices_id(update_attributes)
|
368
|
-
order = generate_upgrade_order(prices, update_attributes[:time])
|
369
|
-
|
369
|
+
order = generate_upgrade_order(prices, update_attributes[:time] || update_attributes[:maintenance_window])
|
370
|
+
@product_conn.place_order(order).body
|
370
371
|
end
|
371
372
|
|
372
373
|
def generate_order_template
|
@@ -386,6 +387,21 @@ module Fog
|
|
386
387
|
)
|
387
388
|
end
|
388
389
|
|
390
|
+
def product_connection
|
391
|
+
if Fog.mock?
|
392
|
+
@product_conn = Fog::Softlayer::Product.new(
|
393
|
+
:provider => :softlayer,
|
394
|
+
:softlayer_username => service.instance_variable_get(:@credentials)[:username],
|
395
|
+
:softlayer_api_key => service.instance_variable_get(:@credentials)[:api_key]
|
396
|
+
)
|
397
|
+
end
|
398
|
+
@product_conn ||= Fog::Softlayer::Product.new(
|
399
|
+
:provider => :softlayer,
|
400
|
+
:softlayer_username => service.instance_variable_get(:@softlayer_username),
|
401
|
+
:softlayer_api_key => service.instance_variable_get(:@softlayer_api_key)
|
402
|
+
)
|
403
|
+
end
|
404
|
+
|
389
405
|
def _get_private_vlan
|
390
406
|
if self.id
|
391
407
|
vlan_id = if bare_metal?
|
@@ -491,37 +507,56 @@ module Fog
|
|
491
507
|
end
|
492
508
|
|
493
509
|
def get_item_prices_id_by_value(item_price_array, category, value)
|
494
|
-
|
495
|
-
item_price =
|
496
|
-
item_price["id"]
|
510
|
+
item_prices = item_price_array.select { |item_price| item_price["categories"].find { |category_hash| category_hash["categoryCode"] == category } }
|
511
|
+
item_price = item_prices.find { |item_price| item_price['item']['capacity'] == value.to_s }
|
512
|
+
item_price.nil? ? "" : item_price["id"]
|
497
513
|
end
|
498
514
|
|
499
515
|
def get_item_prices_id(update_attributes)
|
500
516
|
item_price_array = get_upgrade_options
|
501
|
-
categories = {:cpu => "guest_core", :memory => "ram", :max_port_speed => "port_speed"}
|
502
|
-
prices = []
|
503
517
|
update_attributes.delete(:time)
|
504
|
-
update_attributes.
|
505
|
-
|
518
|
+
update_attributes.delete(:maintenance_window)
|
519
|
+
update_attributes.map { |key, value| { :id => get_item_prices_id_by_value(item_price_array, key.to_s, value) } }
|
506
520
|
end
|
507
521
|
|
508
|
-
def
|
522
|
+
def bm_upgrade_order_template(value)
|
509
523
|
{
|
510
|
-
:complexType => '
|
511
|
-
:
|
512
|
-
:properties => [
|
524
|
+
:complexType => 'SoftLayer_Container_Product_Order_Hardware_Server_Upgrade',
|
525
|
+
:hardware => [
|
513
526
|
{
|
514
|
-
:
|
515
|
-
:value => time.present? ? time.iso8601 : Time.now.iso8601
|
527
|
+
:id => id
|
516
528
|
}
|
517
529
|
],
|
530
|
+
:properties => [
|
531
|
+
{
|
532
|
+
:name => 'MAINTENANCE_WINDOW_ID',
|
533
|
+
:value => value
|
534
|
+
}
|
535
|
+
]
|
536
|
+
}
|
537
|
+
end
|
538
|
+
|
539
|
+
def vm_upgrade_order_template(time)
|
540
|
+
{
|
541
|
+
:complexType => 'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade',
|
518
542
|
:virtualGuests => [
|
519
543
|
{
|
520
544
|
:id => id
|
521
545
|
}
|
546
|
+
],
|
547
|
+
:properties => [
|
548
|
+
{
|
549
|
+
:name => 'MAINTENANCE_WINDOW',
|
550
|
+
:value => (time.nil? || time.empty?) ? Time.now.iso8601 : time.iso8601
|
551
|
+
}
|
522
552
|
]
|
523
553
|
}
|
524
554
|
end
|
555
|
+
|
556
|
+
def generate_upgrade_order(prices, value)
|
557
|
+
return bm_upgrade_order_template(value).merge({ :prices => prices }) if bare_metal?
|
558
|
+
vm_upgrade_order_template(value).merge({ :prices => prices })
|
559
|
+
end
|
525
560
|
end
|
526
561
|
end
|
527
562
|
end
|
@@ -29,6 +29,10 @@ module Fog
|
|
29
29
|
@routable_subnets ||= service.request(:location_datacenter, "#{id}/get_bound_subnets").body
|
30
30
|
end
|
31
31
|
|
32
|
+
def get_avaliable_maintenance_windows(begin_date, end_date, slots_number)
|
33
|
+
service.get_maintenance_windows(id, begin_date, end_date, slots_number).body
|
34
|
+
end
|
35
|
+
|
32
36
|
def save
|
33
37
|
raise "Not possible."
|
34
38
|
end
|