fog-softlayer 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MmM2YjQyOGY4OTJhMGQxM2Y2NjMxOWM3OTI4MmQ4ZmQ1YWQ5YTVhZQ==
5
- data.tar.gz: !binary |-
6
- ZTI0NzU5MzQ3OWNjYTliZmRlYzFiZjU5ZDc5NjEwYzBmNTFmYjVjNg==
2
+ SHA1:
3
+ metadata.gz: e7d1c6f03ac2e0040db85db4721b27d0d4cd64cb
4
+ data.tar.gz: bdc6756610695169ad345a08c366322bebb1bf4f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZWQ5ZmEzOGM0YTA0N2M2ZDVjYzE5ODMyM2ZmZmI3MTA0YzFlNjc5NTdiYzVh
10
- MTcyZmYxYWE4YzZmNTQ3MGZmMjg1ZDU1ZGEwNzhhYzUxNWIzZTViNTY5MjI1
11
- MDhmMjEzMmE1Y2Y4NmNiZTM5MjlkMWFhMzI5YWZiMGRjYzY1ODY=
12
- data.tar.gz: !binary |-
13
- N2YxYmE2OWQ4Yzg2NDY4MGFmYTM0NmQwYjc4ZGQ2ODk5N2RkMGFlZDNjOTRl
14
- YjJkNDQxMmE3ZTNhMWRlNmVlOWUzOGU4MWQ0NGQxYjhmNjBlYWMwMThhYzRi
15
- NjIzNTM3Y2M5MmUxOTdkZDQ5MTYxNDE0ODBmOWM3ODQyOTZkYTU=
6
+ metadata.gz: 78c526fb8b3708aad63c410bbd34d6ead32c8f7ecaa43bae0d3706667ea08909fde2b4e1c6231b37863a11d37e47cf61843667ad2d131411925f8eec93914427
7
+ data.tar.gz: 549aa937fb695071e6e85f3c7860899958781ca58d0e3d8a69f36c21a0ff3cc684c10f0a0a50df0a74257ef0b27bc254c4feead972cce9c7b1ec83361bc2b258
data/examples/compute.md CHANGED
@@ -141,7 +141,7 @@ If you are unfamiliar with fog, we recommend reading our [getting started](getti
141
141
 
142
142
  ```ruby
143
143
  opts = {
144
- :flavor_id => "m1.small",
144
+ :flavor_id => "m1.medium",
145
145
  :os_code => "UBUNTU_LATEST",
146
146
  :name => "test1",
147
147
  :datacenter => "ams01",
@@ -173,7 +173,7 @@ If you are unfamiliar with fog, we recommend reading our [getting started](getti
173
173
  opts = {
174
174
  :cpu => 8,
175
175
  :ram => 16348,
176
- :disk => {'capacity' => 100 },
176
+ :disk => {'capacity' => 500 },
177
177
  :ephemeral_storage => true,
178
178
  :domain => "not-my-default.com",
179
179
  :name => "hostname",
@@ -299,7 +299,6 @@ If you are unfamiliar with fog, we recommend reading our [getting started](getti
299
299
 
300
300
  ```
301
301
 
302
-
303
302
  1. Get all options to create a bare metal.
304
303
 
305
304
  ```ruby
@@ -324,4 +323,88 @@ If you are unfamiliar with fog, we recommend reading our [getting started](getti
324
323
  ```ruby
325
324
  server = @sl.servers.get(123456)
326
325
  server.get_users
327
- ```
326
+ ```
327
+
328
+ 1. Get all upgrade options of a server.
329
+
330
+ ```ruby
331
+ server = @sl.servers.get(123456)
332
+ server.get_upgrade_options
333
+ ```
334
+
335
+ 1. Update a server.
336
+
337
+ ```ruby
338
+ new_attributes = {
339
+ :cpu => 2,
340
+ :memory => 1, # this value is in GBs
341
+ :max_port_speed => 100, # this value is in MPBSs
342
+ :time => Time.now + 5.minutes # if you don't specify, time will be equal to now
343
+ }
344
+ server = @sl.servers.get(123456)
345
+ server.update(new_attributes)
346
+ ```
347
+
348
+ 1. Generate an order template for VM with flavor (simple).
349
+
350
+ ```ruby
351
+ opts = {
352
+ :flavor_id => "m1.small",
353
+ :image_id => "23f7f05f-3657-4330-8772-329ed2e816bc",
354
+ :name => "test",
355
+ :datacenter => "ams01"
356
+ }
357
+ new_server = @sl.servers.new(opts)
358
+ new_server.generate_order_template
359
+ ```
360
+
361
+ 1. Generate an order template for Bare Metal instance with flavor (simple).
362
+
363
+ ```ruby
364
+ opts = {
365
+ :flavor_id => "m1.medium",
366
+ :os_code => "UBUNTU_LATEST",
367
+ :name => "test1",
368
+ :datacenter => "ams01",
369
+ :bare_metal => true
370
+ }
371
+ new_server = @sl.servers.new(opts)
372
+ new_server.generate_order_template
373
+ ```
374
+
375
+ 1. Generate an order template for VM without flavor.
376
+
377
+ ```ruby
378
+ opts = {
379
+ :cpu => 2,
380
+ :ram => 2048,
381
+ :disk => [{'device' => 0, 'diskImage' => {'capacity' => 100 } }],
382
+ :ephemeral_storage => true,
383
+ :domain => "not-my-default.com",
384
+ :name => "hostname",
385
+ :os_code => "UBUNTU_LATEST",
386
+ :name => "test2",
387
+ :datacenter => "ams01"
388
+ }
389
+ new_server = @sl.servers.new(opts)
390
+ new_server.generate_order_template
391
+ ```
392
+
393
+ 1. Generate an order template for Bare Metal Instance without a flavor
394
+
395
+ ```ruby
396
+ opts = {
397
+ :cpu => 8,
398
+ :ram => 16348,
399
+ :disk => {'capacity' => 500 },
400
+ :ephemeral_storage => true,
401
+ :domain => "not-my-default.com",
402
+ :name => "hostname",
403
+ :os_code => "UBUNTU_LATEST",
404
+ :name => "test2",
405
+ :datacenter => "ams01",
406
+ :bare_metal => true
407
+ }
408
+ new_server = @sl.servers.new(opts)
409
+ new_server.generate_order_template
410
+ ```
@@ -46,12 +46,15 @@ module Fog
46
46
  request :delete_vm
47
47
  request :delete_vm_tags
48
48
  request :describe_tags
49
+ request :generate_bare_metal_order_template
50
+ request :generate_virtual_guest_order_template
49
51
  request :get_bare_metal_active_tickets
50
52
  request :get_bare_metal_create_options
51
53
  request :get_bare_metal_server
52
54
  request :get_bare_metal_server_by_ip
53
55
  request :get_bare_metal_servers
54
56
  request :get_bare_metal_tags
57
+ request :get_bare_metal_upgrade_item_prices
55
58
  request :get_bare_metal_users
56
59
  request :get_key_pair
57
60
  request :get_key_pairs
@@ -60,6 +63,7 @@ module Fog
60
63
  request :get_virtual_guest_active_tickets
61
64
  request :get_virtual_guest_by_ip
62
65
  request :get_virtual_guest_create_options
66
+ request :get_virtual_guest_upgrade_item_prices
63
67
  request :get_virtual_guest_users
64
68
  request :get_vm_tags
65
69
  request :get_vm
@@ -72,6 +76,8 @@ module Fog
72
76
  request :reboot_vm
73
77
  request :update_key_pair
74
78
 
79
+ request :place_order, 'fog/softlayer/requests/product'
80
+
75
81
  # The Mock Service allows you to run a fake instance of the Service
76
82
  # which makes no real connections.
77
83
  #
@@ -357,6 +357,25 @@ module Fog
357
357
  service.get_virtual_guest_users(id).body
358
358
  end
359
359
 
360
+ def get_upgrade_options
361
+ return service.get_bare_metal_upgrade_item_prices(id).body if bare_metal?
362
+ service.get_virtual_guest_upgrade_item_prices(id).body
363
+ end
364
+
365
+ def update(update_attributes = {})
366
+ raise Exception("Need implementation for BM") if bare_metal?
367
+ prices = get_item_prices_id(update_attributes)
368
+ order = generate_upgrade_order(prices, update_attributes[:time])
369
+ service.place_order(order).body
370
+ end
371
+
372
+ def generate_order_template
373
+ copy = self.dup
374
+ copy.pre_save
375
+ return service.generate_bare_metal_order_template(copy.attributes).body if bare_metal?
376
+ service.generate_virtual_guest_order_template(copy.attributes).body
377
+ end
378
+
360
379
  private
361
380
 
362
381
  def network_connection
@@ -440,7 +459,6 @@ module Fog
440
459
  attributes.delete(:ephemeral_storage)
441
460
  end
442
461
 
443
-
444
462
  ##
445
463
  # Expand a "flavor" into cpu, ram, and disk attributes
446
464
  def extract_flavor
@@ -460,8 +478,8 @@ module Fog
460
478
 
461
479
  def validate_attributes
462
480
  requires :name, :domain, :cpu, :ram, :datacenter
463
- requires_one :os_code, :image_id
464
- requires_one :image_id, :disk
481
+ requires_one :os_code if self.attributes[:os_code].nil? # need this while os_code bug isn't fixed
482
+ requires_one :disk, :image_id
465
483
  bare_metal? and image_id and raise ArgumentError, "Bare Metal Cloud does not support booting from Image"
466
484
  end
467
485
 
@@ -472,6 +490,38 @@ module Fog
472
490
  self.datacenter = service.softlayer_default_datacenter if service.softlayer_default_datacenter and attributes[:datacenter].nil?
473
491
  end
474
492
 
493
+ def get_item_prices_id_by_value(item_price_array, category, value)
494
+ item_price_array = item_price_array.select { |item_price| item_price["categories"].find { |category_hash| category_hash["categoryCode"] == category } }
495
+ item_price = item_price_array.find { |item_price| item_price['item']['capacity'].to_i == value }
496
+ item_price["id"]
497
+ end
498
+
499
+ def get_item_prices_id(update_attributes)
500
+ item_price_array = get_upgrade_options
501
+ categories = {:cpu => "guest_core", :memory => "ram", :max_port_speed => "port_speed"}
502
+ prices = []
503
+ update_attributes.delete(:time)
504
+ update_attributes.each_pair { |key, value| prices << { :id => get_item_prices_id_by_value(item_price_array, categories[key], update_attributes[key]) } }
505
+ prices
506
+ end
507
+
508
+ def generate_upgrade_order(prices, time)
509
+ {
510
+ :complexType => 'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade',
511
+ :prices => prices,
512
+ :properties => [
513
+ {
514
+ :name => 'MAINTENANCE_WINDOW',
515
+ :value => time.present? ? time.iso8601 : Time.now.iso8601
516
+ }
517
+ ],
518
+ :virtualGuests => [
519
+ {
520
+ :id => id
521
+ }
522
+ ]
523
+ }
524
+ end
475
525
  end
476
526
  end
477
527
  end
@@ -30,6 +30,7 @@ module Fog
30
30
  request :get_package_item
31
31
  request :get_package_items
32
32
  request :get_packages
33
+ request :place_order
33
34
 
34
35
  # The Mock Service allows you to run a fake instance of the Service
35
36
  # which makes no real connections.
@@ -0,0 +1,162 @@
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
+ module Fog
8
+ module Compute
9
+ class Softlayer
10
+ class Mock
11
+ # Generate an order template for a Bare Metal
12
+ # @param [Integer] order_template
13
+ # @return [Excon::Response]
14
+ def generate_bare_metal_order_template(order_template)
15
+ raise ArgumentError, "Fog::Compute::Softlayer#create_vms expects argument of type Hash" unless order_template.kind_of?(Hash)
16
+ response = Excon::Response.new
17
+ required = %w{hostname domain processorCoreAmount memoryCapacity hourlyBillingFlag operatingSystemReferenceCode}
18
+ begin
19
+ raise MissingRequiredParameter unless Fog::Softlayer.valid_request?(required, order_template)
20
+ response.status = 200
21
+ response.body = order_template_mock
22
+ rescue MissingRequiredParameter
23
+ response.status = 500
24
+ response.body = {
25
+ "code" => "SoftLayer_Exception_MissingCreationProperty",
26
+ "error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Virtual_Guest'."
27
+ }
28
+ end
29
+ @virtual_guests.push(response.body).flatten!
30
+ response
31
+ end
32
+ end
33
+
34
+ class Real
35
+ def generate_bare_metal_order_template(order_template)
36
+ request(:hardware_server, :generate_order_template, body: order_template, :http_method => :POST)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ module Fog
44
+ module Compute
45
+ class Softlayer
46
+ class Mock
47
+ def order_template_mock
48
+ {
49
+ "hardware"=>[
50
+ {
51
+ "domain"=>"example.com",
52
+ "hostname"=>"host1"
53
+ }
54
+ ],
55
+ "location"=>"265592",
56
+ "packageId"=>50,
57
+ "prices"=>[
58
+ {
59
+ "hourlyRecurringFee"=>".24",
60
+ "id"=>1921,
61
+ "recurringFee"=>"159",
62
+ "item"=>{
63
+ "description"=>"2 x 2.0 GHz Core Bare Metal Instance - 2 GB Ram"
64
+ }
65
+ },
66
+ {
67
+ "hourlyRecurringFee"=>"0",
68
+ "id"=>37620,
69
+ "recurringFee"=>"0",
70
+ "item"=>{
71
+ "description"=>"Ubuntu Linux 14.04 LTS Trusty Tahr - Minimal Install (64 bit)"
72
+ }
73
+ },
74
+ {
75
+ "hourlyRecurringFee"=>"0",
76
+ "id"=>1267,
77
+ "recurringFee"=>"0",
78
+ "item"=>{
79
+ "description"=>"500 GB SATA II"
80
+ }
81
+ },
82
+ {
83
+ "hourlyRecurringFee"=>"0",
84
+ "id"=>55,
85
+ "recurringFee"=>"0",
86
+ "item"=>{
87
+ "description"=>"Host Ping"
88
+ }
89
+ },
90
+ {
91
+ "hourlyRecurringFee"=>"0",
92
+ "id"=>57,
93
+ "recurringFee"=>"0",
94
+ "item"=>{
95
+ "description"=>"Email and Ticket"
96
+ }
97
+ },
98
+ {
99
+ "hourlyRecurringFee"=>"0",
100
+ "id"=>58,
101
+ "recurringFee"=>"0",
102
+ "item"=>{
103
+ "description"=>"Automated Notification"
104
+ }
105
+ },
106
+ {
107
+ "hourlyRecurringFee"=>"0",
108
+ "id"=>40640,
109
+ "recurringFee"=>"0",
110
+ "item"=>{
111
+ "description"=>"100 Mbps Dual Public & Private Network Uplinks (Unbonded)"
112
+ }
113
+ },
114
+ {
115
+ "hourlyRecurringFee"=>"0",
116
+ "id"=>1800,
117
+ "item"=>{
118
+ "description"=>"0 GB Bandwidth"
119
+ }
120
+ },
121
+ {
122
+ "hourlyRecurringFee"=>"0",
123
+ "id"=>420,
124
+ "recurringFee"=>"0",
125
+ "item"=>{
126
+ "description"=>"Unlimited SSL VPN Users & 1 PPTP VPN User per account"
127
+ }
128
+ },
129
+ {
130
+ "hourlyRecurringFee"=>"0",
131
+ "id"=>418,
132
+ "recurringFee"=>"0",
133
+ "item"=>{
134
+ "description"=>"Nessus Vulnerability Assessment & Reporting"
135
+ }
136
+ },
137
+ {
138
+ "hourlyRecurringFee"=>"0",
139
+ "id"=>905,
140
+ "recurringFee"=>"0",
141
+ "item"=>{
142
+ "description"=>"Reboot / Remote Console"
143
+ }
144
+ },
145
+ {
146
+ "hourlyRecurringFee"=>"0",
147
+ "id"=>21,
148
+ "recurringFee"=>"0",
149
+ "item"=>{
150
+ "description"=>"1 IP Address"
151
+ }
152
+ }
153
+ ],
154
+ "quantity"=>1,
155
+ "sshKeys"=>[],
156
+ "useHourlyPricing"=>true
157
+ }
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,173 @@
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
+ module Fog
8
+ module Compute
9
+ class Softlayer
10
+ class Mock
11
+ # Generate an order template for a Virtual Guest
12
+ # @param [Integer] order_template
13
+ # @return [Excon::Response]
14
+ def generate_virtual_guest_order_template(order_template)
15
+ raise ArgumentError, "Fog::Compute::Softlayer#create_vms expects argument of type Hash" unless order_template.kind_of?(Hash)
16
+ response = Excon::Response.new
17
+ required = %w{hostname domain startCpus maxMemory hourlyBillingFlag localDiskFlag}
18
+ begin
19
+ raise MissingRequiredParameter unless Fog::Softlayer.valid_request?(required, order_template)
20
+ response.status = 200
21
+ response.body = order_template_mock
22
+ rescue MissingRequiredParameter
23
+ response.status = 500
24
+ response.body = {
25
+ "code" => "SoftLayer_Exception_MissingCreationProperty",
26
+ "error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Virtual_Guest'."
27
+ }
28
+ end
29
+ @virtual_guests.push(response.body).flatten!
30
+ response
31
+ end
32
+ end
33
+
34
+ class Real
35
+ def generate_virtual_guest_order_template(order_template)
36
+ request(:virtual_guest, :generate_order_template, body: order_template, :http_method => :POST)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ module Fog
44
+ module Compute
45
+ class Softlayer
46
+ class Mock
47
+ def order_template_mock
48
+ {
49
+ "imageTemplateId"=>nil,
50
+ "location"=>"265592",
51
+ "packageId"=>46,
52
+ "prices"=>[
53
+ {
54
+ "hourlyRecurringFee"=>".021",
55
+ "id"=>1640,
56
+ "recurringFee"=>"15",
57
+ "item"=>{
58
+ "description"=>"1 x 2.0 GHz Core"
59
+ }
60
+ },
61
+ {
62
+ "hourlyRecurringFee"=>".019",
63
+ "id"=>1644,
64
+ "recurringFee"=>"12.6",
65
+ "item"=>{
66
+ "description"=>"1 GB"
67
+ }
68
+ },
69
+ {
70
+ "hourlyRecurringFee"=>"0",
71
+ "id"=>37202,
72
+ "recurringFee"=>"0",
73
+ "item"=>{
74
+ "description"=>"Ubuntu Linux 14.04 LTS Trusty Tahr - Minimal Install (64 bit)"
75
+ }
76
+ },
77
+ {
78
+ "hourlyRecurringFee"=>"0",
79
+ "id"=>13899,
80
+ "recurringFee"=>"0",
81
+ "item"=>{
82
+ "description"=>"25 GB (LOCAL)"
83
+ }
84
+ },
85
+ {
86
+ "hourlyRecurringFee"=>"0",
87
+ "id"=>55,
88
+ "recurringFee"=>"0",
89
+ "item"=>{
90
+ "description"=>"Host Ping"
91
+ }
92
+ },
93
+ {
94
+ "hourlyRecurringFee"=>"0",
95
+ "id"=>57,
96
+ "recurringFee"=>"0",
97
+ "item"=>{
98
+ "description"=>"Email and Ticket"
99
+ }
100
+ },
101
+ {
102
+ "hourlyRecurringFee"=>"0",
103
+ "id"=>58,
104
+ "recurringFee"=>"0",
105
+ "item"=>{
106
+ "description"=>"Automated Notification"
107
+ }
108
+ },
109
+ {
110
+ "hourlyRecurringFee"=>"0",
111
+ "id"=>272,
112
+ "recurringFee"=>"0",
113
+ "item"=>{
114
+ "description"=>"10 Mbps Public & Private Network Uplinks"
115
+ }
116
+ },
117
+ {
118
+ "hourlyRecurringFee"=>"0",
119
+ "id"=>1800,
120
+ "item"=>{
121
+ "description"=>"0 GB Bandwidth"
122
+ }
123
+ },
124
+ {
125
+ "hourlyRecurringFee"=>"0",
126
+ "id"=>420,
127
+ "recurringFee"=>"0",
128
+ "item"=>{
129
+ "description"=>"Unlimited SSL VPN Users & 1 PPTP VPN User per account"
130
+ }
131
+ },
132
+ {
133
+ "hourlyRecurringFee"=>"0",
134
+ "id"=>418,
135
+ "recurringFee"=>"0",
136
+ "item"=>{
137
+ "description"=>"Nessus Vulnerability Assessment & Reporting"
138
+ }
139
+ },
140
+ {
141
+ "hourlyRecurringFee"=>"0",
142
+ "id"=>905,
143
+ "recurringFee"=>"0",
144
+ "item"=>{
145
+ "description"=>"Reboot / Remote Console"
146
+ }
147
+ },
148
+ {
149
+ "hourlyRecurringFee"=>"0",
150
+ "id"=>21,
151
+ "recurringFee"=>"0",
152
+ "item"=>{
153
+ "description"=>"1 IP Address"
154
+ }
155
+ }
156
+ ],
157
+ "quantity"=>1,
158
+ "sourceVirtualGuestId"=>nil,
159
+ "sshKeys"=>[],
160
+ "useHourlyPricing"=>true,
161
+ "virtualGuests"=>[
162
+ {
163
+ "domain"=>"example.com",
164
+ "hostname"=>"host1"
165
+ }
166
+ ],
167
+ "complexType"=>"SoftLayer_Container_Product_Order_Virtual_Guest"
168
+ }
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end