fog-softlayer 0.0.1 → 0.0.2
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 +15 -0
- data/lib/fog/softlayer/compute.rb +35 -15
- data/lib/fog/softlayer/compute/shared.rb +1 -0
- data/lib/fog/softlayer/core.rb +2 -2
- data/lib/fog/softlayer/models/compute/flavor.rb +26 -0
- data/lib/fog/softlayer/models/compute/flavors.rb +100 -0
- data/lib/fog/softlayer/models/compute/image.rb +29 -0
- data/lib/fog/softlayer/models/compute/images.rb +35 -0
- data/lib/fog/softlayer/models/compute/server.rb +252 -0
- data/lib/fog/softlayer/models/compute/servers.rb +47 -0
- data/lib/fog/softlayer/requests/compute/create_bare_metal_server.rb +7 -0
- data/lib/fog/softlayer/requests/compute/create_vm.rb +6 -0
- data/lib/fog/softlayer/requests/compute/create_vms.rb +7 -0
- data/lib/fog/softlayer/requests/compute/delete_bare_metal_server.rb +42 -0
- data/lib/fog/softlayer/requests/compute/delete_vm.rb +42 -0
- data/lib/fog/softlayer/requests/compute/get_bare_metal_server.rb +28 -0
- data/lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb +28 -0
- data/lib/fog/softlayer/requests/compute/get_vm.rb +28 -0
- data/lib/fog/softlayer/requests/compute/get_vms.rb +28 -0
- data/lib/fog/softlayer/version.rb +1 -1
- metadata +17 -19
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWMzMWI0MTk1OTA5MTA1ZDc1MmFlMDVmYzA4MjM1MzNmODAyOGYxZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjQwYjI3YmEzNmNkMWNiMWU0NWY3ZDM4NDViOTI5MWZlZmEyZDVlNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MWNlNTM4Mzk4N2ZkMjZmY2QxMzdlODdlYzdlMGZkOWYxMDU3NDEyMGU3MmVm
|
10
|
+
ZmI3OTVjZWQ4MzQ5ZGY1ZjZjMTNhYjQ0ZGM3YTM3MWQwZGExMjdhY2I5OWJj
|
11
|
+
OTU3YzFmNDZlOGIxZGJiYzdkOTMwNjY2MDdiY2IyY2QzYWFmZWQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjIxNWNkZWM5ZTMzOWI3MjhkY2E2OGYzZTkwMWQzZTM2Yjk3ZjM0MjU1ZjBj
|
14
|
+
OTM0NDc3MTllZjliZjExODczM2EwM2FiZGJiN2JlNGM0MzEyNzI5NWU5ZWM5
|
15
|
+
MzQwYjQ5NzY2NGQwNzM2ZDZhOTk4OTJhODI0NmMxOGQzMmM4Mjg=
|
@@ -18,34 +18,42 @@ module Fog
|
|
18
18
|
|
19
19
|
# Excon connection settings
|
20
20
|
recognizes :softlayer_api_url
|
21
|
+
recognizes :softlayer_default_domain
|
21
22
|
|
22
|
-
#model_path 'fog/softlayer/models/compute'
|
23
|
-
#collection :servers
|
24
|
-
#model :server
|
25
|
-
#collection :bare_metal_servers
|
26
|
-
#model :bare_metal_server
|
27
|
-
#collection :global_ipv4s
|
28
|
-
#model :global_ipv4
|
29
|
-
#collection :images
|
30
|
-
#model :image
|
31
|
-
#
|
32
23
|
|
33
24
|
service = File.basename(__FILE__, '.rb')
|
34
25
|
|
35
|
-
|
36
|
-
|
26
|
+
model_path 'fog/softlayer/models/compute'
|
27
|
+
Fog::Softlayer.loader("models/#{service}") do |basename|
|
28
|
+
if basename =~ /s$/
|
29
|
+
collection basename
|
30
|
+
else
|
31
|
+
model basename
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
36
|
+
request_path "fog/softlayer/requests/#{service}"
|
37
|
+
Fog::Softlayer.loader("requests/#{service}") do |basename|
|
38
|
+
request basename
|
40
39
|
end
|
41
40
|
|
42
41
|
|
42
|
+
|
43
43
|
# The Mock Service allows you to run a fake instance of the Service
|
44
44
|
# which makes no real connections.
|
45
45
|
#
|
46
46
|
#
|
47
47
|
class Mock
|
48
|
+
attr_accessor :default_domain
|
48
49
|
include Fog::Softlayer::Compute::Shared
|
50
|
+
attr_accessor :virtual_guests, :bare_metal_servers
|
51
|
+
|
52
|
+
def initialize(args)
|
53
|
+
@virtual_guests = []
|
54
|
+
@bare_metal_servers = []
|
55
|
+
super(args)
|
56
|
+
end
|
49
57
|
|
50
58
|
def request(method, path, expected_responses, parameters = {})
|
51
59
|
_request
|
@@ -59,12 +67,17 @@ module Fog
|
|
59
67
|
raise Fog::Errors::MockNotImplemented
|
60
68
|
end
|
61
69
|
|
70
|
+
def list_servers
|
71
|
+
(self.get_vms.body << self.get_bare_metal_servers.body).flatten
|
72
|
+
end
|
73
|
+
|
62
74
|
end
|
63
75
|
|
64
76
|
##
|
65
77
|
# Makes real connections to Softlayer.
|
66
78
|
#
|
67
79
|
class Real
|
80
|
+
attr_accessor :default_domain
|
68
81
|
include Fog::Softlayer::Compute::Shared
|
69
82
|
|
70
83
|
# Sends the real request to the real SoftLayer service.
|
@@ -95,12 +108,15 @@ module Fog
|
|
95
108
|
set_sl_service(service)
|
96
109
|
# set the request path (known as the "method" in SL docs)
|
97
110
|
set_sl_path(path)
|
111
|
+
# set the query params if any
|
112
|
+
|
98
113
|
|
99
114
|
# build request params
|
100
115
|
params = { :headers => user_agent_header }
|
101
116
|
params[:headers]['Content-Type'] = 'application/json'
|
102
|
-
params[:expects] = [200,201]
|
117
|
+
params[:expects] = options[:expected] || [200,201]
|
103
118
|
params[:body] = Fog::JSON.encode({:parameters => [ options[:body] ]}) unless options[:body].nil?
|
119
|
+
params[:query] = options[:query] unless options[:query].nil?
|
104
120
|
|
105
121
|
# initialize connection object
|
106
122
|
@connection = Fog::Core::Connection.new(@request_url, false, params)
|
@@ -113,6 +129,10 @@ module Fog
|
|
113
129
|
response
|
114
130
|
end
|
115
131
|
|
132
|
+
def list_servers
|
133
|
+
(self.get_vms.body << self.get_bare_metal_servers.body).flatten
|
134
|
+
end
|
135
|
+
|
116
136
|
private
|
117
137
|
|
118
138
|
def credentialize_url(username, apikey)
|
@@ -27,6 +27,7 @@ module Fog
|
|
27
27
|
def initialize(options)
|
28
28
|
@api_url = options[:softlayer_api_url] || API_URL
|
29
29
|
@credentials = { :username => options[:softlayer_username], :api_key => options[:softlayer_api_key] }
|
30
|
+
@default_domain = options[:softlayer_default_domain]
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.valid_request?(required, passed)
|
data/lib/fog/softlayer/core.rb
CHANGED
@@ -10,8 +10,8 @@ module Fog
|
|
10
10
|
|
11
11
|
service(:compute, 'Compute')
|
12
12
|
|
13
|
-
def self.
|
14
|
-
path = "providers/softlayer/lib/fog/softlayer
|
13
|
+
def self.loader(service)
|
14
|
+
path = "providers/softlayer/lib/fog/softlayer/#{service}"
|
15
15
|
Dir.entries(path).reject{|e| e =~ /^\./}.each do |file|
|
16
16
|
_request = File.basename(file, '.rb')
|
17
17
|
yield _request.to_sym
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
require 'fog/core/model'
|
8
|
+
|
9
|
+
module Fog
|
10
|
+
module Compute
|
11
|
+
class Softlayer
|
12
|
+
|
13
|
+
class Flavor < Fog::Model
|
14
|
+
|
15
|
+
identity :id
|
16
|
+
|
17
|
+
attribute :cpu
|
18
|
+
attribute :disk
|
19
|
+
attribute :name
|
20
|
+
attribute :ram
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
require 'fog/core/collection'
|
8
|
+
require 'fog/softlayer/models/compute/flavor'
|
9
|
+
|
10
|
+
module Fog
|
11
|
+
module Compute
|
12
|
+
class Softlayer
|
13
|
+
|
14
|
+
## SoftLayer doesn't actually have "flavors", these are just for portability/convenience,
|
15
|
+
# they map directly to OpenStack defaults.
|
16
|
+
|
17
|
+
|
18
|
+
# :cores => number of virtual CPUs presented
|
19
|
+
# :disk => size in GB of the virtual root disk
|
20
|
+
# :ram => virtual machine memory in MB
|
21
|
+
FLAVORS = [
|
22
|
+
{
|
23
|
+
:id => 'm1.tiny',
|
24
|
+
:name => 'Tiny Instance',
|
25
|
+
:cpu => 2,
|
26
|
+
:disk => [{'device' => 0, 'diskImage' => {'capacity' => 25 } }],
|
27
|
+
:ram => 1024
|
28
|
+
},
|
29
|
+
{
|
30
|
+
:id => 'm1.small',
|
31
|
+
:name => 'Small Instance',
|
32
|
+
:cpu => 2,
|
33
|
+
:disk => [{'device' => 0, 'diskImage' => {'capacity' => 100 } }],
|
34
|
+
:ram => 2048
|
35
|
+
},
|
36
|
+
{
|
37
|
+
:id => 'm1.medium',
|
38
|
+
:name => 'Medium Instance',
|
39
|
+
:cpu => 4,
|
40
|
+
:disk => [{'device' => 0, 'diskImage' => {'capacity' => 500 } }],
|
41
|
+
:ram => 4096
|
42
|
+
},
|
43
|
+
{
|
44
|
+
:id => 'm1.large',
|
45
|
+
:name => 'Large Instance',
|
46
|
+
:cpu => 8,
|
47
|
+
:disk => [{'device' => 0, 'diskImage' => {'capacity' => 750 } }],
|
48
|
+
:ram => 8192
|
49
|
+
},
|
50
|
+
{
|
51
|
+
:id => 'm1.xlarge',
|
52
|
+
:name => 'Extra Large Instance',
|
53
|
+
:cpu => 16,
|
54
|
+
:disk => [{'device' => 0, 'diskImage' => {'capacity' => 1000 } }],
|
55
|
+
:ram => 16384
|
56
|
+
}
|
57
|
+
]
|
58
|
+
|
59
|
+
class Flavors < Fog::Collection
|
60
|
+
|
61
|
+
model Fog::Compute::Softlayer::Flavor
|
62
|
+
|
63
|
+
# Returns an array of all flavors that have been created
|
64
|
+
#
|
65
|
+
# Fog::Softlayer.flavors.all
|
66
|
+
def all
|
67
|
+
load(Fog::Compute::Softlayer::FLAVORS)
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
# Used to retrieve a flavor
|
72
|
+
# flavor_id is required to get the associated flavor information.
|
73
|
+
# flavors available currently:
|
74
|
+
#
|
75
|
+
# m1.tiny
|
76
|
+
#
|
77
|
+
# You can run the following command to get the details:
|
78
|
+
# Softlayer.flavors.get("m1.tiny")
|
79
|
+
#
|
80
|
+
# ==== Returns
|
81
|
+
#
|
82
|
+
#>> Softlayer.flavors.get("m1.tiny")
|
83
|
+
# <Fog::Softlayer::Compute::Flavor
|
84
|
+
# id="m1.tiny",
|
85
|
+
# cores=1,
|
86
|
+
# disk=160,
|
87
|
+
# name="Tiny Instance",
|
88
|
+
# ram=1024
|
89
|
+
# >
|
90
|
+
#
|
91
|
+
|
92
|
+
def get(flavor_id)
|
93
|
+
self.class.new(:service => service).all.detect {|flavor| flavor.id == flavor_id}
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
require 'fog/core/model'
|
8
|
+
|
9
|
+
module Fog
|
10
|
+
module Compute
|
11
|
+
class Softlayer
|
12
|
+
|
13
|
+
class Image < Fog::Model
|
14
|
+
|
15
|
+
identity :id, :aliases => 'globalIdentifier'
|
16
|
+
attribute :name
|
17
|
+
attribute :note
|
18
|
+
attribute :parent_id, :aliases => 'parentId'
|
19
|
+
attribute :pulic_flag, :aliases => 'publicFlag'
|
20
|
+
attribute :status_id, :aliases => 'statusId'
|
21
|
+
attribute :summary
|
22
|
+
attribute :transaction_id, :aliases => 'transactionId'
|
23
|
+
attribute :user_record_id, :aliases => 'userRecordId'
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
require 'fog/core/collection'
|
8
|
+
require 'fog/softlayer/models/compute/image'
|
9
|
+
|
10
|
+
module Fog
|
11
|
+
module Compute
|
12
|
+
class Softlayer
|
13
|
+
|
14
|
+
class Images < Fog::Collection
|
15
|
+
|
16
|
+
model Fog::Compute::Softlayer::Image
|
17
|
+
|
18
|
+
# Returns an array of all public images.
|
19
|
+
#
|
20
|
+
# Fog::Softlayer.images.all
|
21
|
+
def all
|
22
|
+
load(service.request(:virtual_guest_block_device_template_group, :get_public_images).body)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Used to retrieve an image
|
27
|
+
def get(uuid)
|
28
|
+
self.class.new(:service => service).all.detect {|image| image.id == uuid}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
require 'fog/compute/models/server'
|
8
|
+
|
9
|
+
module Fog
|
10
|
+
module Compute
|
11
|
+
class Softlayer
|
12
|
+
|
13
|
+
class Server < Fog::Compute::Server
|
14
|
+
|
15
|
+
identity :id
|
16
|
+
attribute :name, :aliases => 'hostname'
|
17
|
+
attribute :domain
|
18
|
+
attribute :fqdn, :aliases => 'fullyQualifiedDomainName'
|
19
|
+
attribute :cpu, :aliases => ['startCpus', 'processorCoreAmount']
|
20
|
+
attribute :ram, :aliases => ['maxMemory', 'memory']
|
21
|
+
attribute :disk, :aliases => ['blockDevices','hardDrives'], :type => :squash
|
22
|
+
attribute :private_ip, :aliases => 'primaryBackendIpAddress'
|
23
|
+
attribute :public_ip, :aliases => 'primaryIpAddress'
|
24
|
+
attribute :flavor_id
|
25
|
+
attribute :bare_metal, :aliases => 'bareMetalInstanceFlag'
|
26
|
+
attribute :os_code, :aliases => 'operatingSystemReferenceCode'
|
27
|
+
attribute :image_id, :type => :squash
|
28
|
+
attribute :ephemeral_storage, :aliases => 'localDiskFlag'
|
29
|
+
|
30
|
+
# Times
|
31
|
+
attribute :created_at, :aliases => ['createDate', 'provisionDate'], :type => :time
|
32
|
+
attribute :last_verified_date, :aliases => 'lastVerifiedDate', :type => :time
|
33
|
+
attribute :metric_poll_date, :aliases => 'metricPollDate', :type => :time
|
34
|
+
attribute :modify_date, :aliases => 'modifyDate', :type => :time
|
35
|
+
|
36
|
+
# Metadata
|
37
|
+
attribute :account_id, :aliases => 'accountId', :type => :integer
|
38
|
+
attribute :datacenter
|
39
|
+
attribute :single_tenant, :aliases => 'dedicatedAccountHostOnlyFlag'
|
40
|
+
attribute :global_identifier, :aliases => 'globalIdentifier'
|
41
|
+
attribute :hourly_billing_flag, :aliases => 'hourlyBillingFlag'
|
42
|
+
|
43
|
+
|
44
|
+
def initialize(attributes = {})
|
45
|
+
super(attributes)
|
46
|
+
set_defaults
|
47
|
+
end
|
48
|
+
|
49
|
+
def bare_metal?
|
50
|
+
bare_metal
|
51
|
+
end
|
52
|
+
|
53
|
+
def bare_metal=(set)
|
54
|
+
attributes[:bare_metal] = case set
|
55
|
+
when true, 'true', 1
|
56
|
+
1
|
57
|
+
when false, 'false', 0, nil
|
58
|
+
0
|
59
|
+
else
|
60
|
+
raise ArgumentError, ":bare_metal cannot be #{set.class}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def bare_metal
|
65
|
+
attributes[:bare_metal] === 1 ? true : false
|
66
|
+
end
|
67
|
+
|
68
|
+
def image_id=(uuid)
|
69
|
+
attributes[:image_id] = {:globalIdentifier => uuid}
|
70
|
+
end
|
71
|
+
|
72
|
+
def image_id
|
73
|
+
attributes[:image_id][:globalIdentifier] unless attributes[:image_id].nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
def ram=(set)
|
77
|
+
if set.is_a?(Array) and set.first['hardwareComponentModel']
|
78
|
+
set = 1024 * set.first['hardwareComponentModel']['capacity'].to_i
|
79
|
+
end
|
80
|
+
attributes[:ram] = set
|
81
|
+
end
|
82
|
+
|
83
|
+
def name=(set)
|
84
|
+
attributes[:hostname] = set
|
85
|
+
end
|
86
|
+
|
87
|
+
def name
|
88
|
+
attributes[:hostname]
|
89
|
+
end
|
90
|
+
|
91
|
+
#def ram
|
92
|
+
#
|
93
|
+
#end
|
94
|
+
|
95
|
+
def snapshot
|
96
|
+
# TODO: implement
|
97
|
+
end
|
98
|
+
|
99
|
+
def reboot(use_hard_reboot = true)
|
100
|
+
# TODO: implement
|
101
|
+
end
|
102
|
+
|
103
|
+
def start
|
104
|
+
# TODO: implement
|
105
|
+
|
106
|
+
#requires :identity
|
107
|
+
#service.start_server(identity)
|
108
|
+
true
|
109
|
+
end
|
110
|
+
|
111
|
+
def stop
|
112
|
+
# TODO: implement
|
113
|
+
end
|
114
|
+
|
115
|
+
def shutdown
|
116
|
+
# TODO: implement
|
117
|
+
end
|
118
|
+
|
119
|
+
def destroy
|
120
|
+
requires :id
|
121
|
+
request = bare_metal? ? :delete_bare_metal_server : :delete_vm
|
122
|
+
response = service.send(request, self.id)
|
123
|
+
response.body
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns the public DNS name of the server
|
127
|
+
#
|
128
|
+
# @return [String]
|
129
|
+
#
|
130
|
+
def dns_name
|
131
|
+
fqdn
|
132
|
+
end
|
133
|
+
|
134
|
+
def state
|
135
|
+
if bare_metal?
|
136
|
+
service.request(:hardware_server, "#{id}/getServerPowerState").body
|
137
|
+
else
|
138
|
+
service.request(:virtual_guest, "#{id}/getPowerState").body['name']
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
def ready?
|
144
|
+
if bare_metal?
|
145
|
+
state == "on"
|
146
|
+
else
|
147
|
+
state == "Running"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Creates server
|
152
|
+
# * requires attributes: :name, :domain, and :flavor_id OR (:cpu_count && :ram && :disks)
|
153
|
+
#
|
154
|
+
# @note You should use servers.create to create servers instead calling this method directly
|
155
|
+
#
|
156
|
+
# * State Transitions
|
157
|
+
# * BUILD -> ACTIVE
|
158
|
+
# * BUILD -> ERROR (on error)
|
159
|
+
def save
|
160
|
+
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
161
|
+
|
162
|
+
data = if bare_metal?
|
163
|
+
pre_save
|
164
|
+
service.create_bare_metal_server(attributes).body
|
165
|
+
else
|
166
|
+
pre_save
|
167
|
+
service.create_vm(attributes).body
|
168
|
+
end
|
169
|
+
merge_attributes(data.first)
|
170
|
+
true
|
171
|
+
end
|
172
|
+
|
173
|
+
def pre_save
|
174
|
+
extract_flavor
|
175
|
+
validate_attributes
|
176
|
+
remap_attributes(attributes, attributes_mapping)
|
177
|
+
clean_attributes
|
178
|
+
end
|
179
|
+
|
180
|
+
private
|
181
|
+
|
182
|
+
##
|
183
|
+
# Generate mapping for use with remap_attributes
|
184
|
+
def attributes_mapping
|
185
|
+
common = {
|
186
|
+
:hourly_billing_flag => :hourlyBillingFlag,
|
187
|
+
:os_code => :operatingSystemReferenceCode,
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
conditional = if bare_metal?
|
192
|
+
{
|
193
|
+
:cpu => :processorCoreAmount,
|
194
|
+
:ram => :memoryCapacity,
|
195
|
+
:disk => :hardDrives,
|
196
|
+
:bare_metal => :bareMetalInstanceFlag
|
197
|
+
}
|
198
|
+
else
|
199
|
+
{
|
200
|
+
:cpu => :startCpus,
|
201
|
+
:ram => :maxMemory,
|
202
|
+
:disk => :blockDevices,
|
203
|
+
:image_id => :blockDeviceTemplateGroup,
|
204
|
+
:ephemeral_storage => :localDiskFlag,
|
205
|
+
}
|
206
|
+
end
|
207
|
+
common.merge(conditional)
|
208
|
+
end
|
209
|
+
|
210
|
+
##
|
211
|
+
# Remove model attributes that aren't expected by the SoftLayer API
|
212
|
+
def clean_attributes
|
213
|
+
@bare_metal = attributes.delete(:bare_metal)
|
214
|
+
attributes.delete(:flavor_id)
|
215
|
+
attributes.delete(:ephemeral_storage)
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
##
|
220
|
+
# Expand a "flavor" into cpu, ram, and disk attributes
|
221
|
+
def extract_flavor
|
222
|
+
if attributes[:flavor_id]
|
223
|
+
flavor = @service.flavors.get(attributes[:flavor_id])
|
224
|
+
flavor.nil? and Fog::Errors::Error.new("Unrecognized flavor in #{self.class}##{__method__}")
|
225
|
+
attributes[:cpu] = flavor.cpu
|
226
|
+
attributes[:ram] = flavor.ram
|
227
|
+
attributes[:disk] = flavor.disk unless attributes[:image_id]
|
228
|
+
if bare_metal?
|
229
|
+
value = flavor.disk.first['diskImage']['capacity'] < 500 ? 250 : 500
|
230
|
+
attributes[:disk] = [{'capacity'=>value}]
|
231
|
+
attributes[:ram] = attributes[:ram] / 1024 if attributes[:ram] > 64
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def validate_attributes
|
237
|
+
requires :name, :domain, :cpu, :ram
|
238
|
+
requires_one :os_code, :image_id
|
239
|
+
requires_one :image_id, :disk
|
240
|
+
bare_metal? and image_id and raise ArgumentError, "Bare Metal Cloud does not support booting from Image"
|
241
|
+
end
|
242
|
+
|
243
|
+
def set_defaults
|
244
|
+
attributes[:hourly_billing_flag] = true if attributes[:hourly_billing_flag].nil?
|
245
|
+
attributes[:ephemeral_storage] = false if attributes[:ephemeral_storage].nil?
|
246
|
+
attributes[:domain] = service.default_domain if attributes[:domain].nil?
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
require 'fog/core/collection'
|
8
|
+
require 'fog/softlayer/models/compute/server'
|
9
|
+
|
10
|
+
module Fog
|
11
|
+
module Compute
|
12
|
+
class Softlayer
|
13
|
+
|
14
|
+
class Servers < Fog::Collection
|
15
|
+
|
16
|
+
model Fog::Compute::Softlayer::Server
|
17
|
+
|
18
|
+
def all
|
19
|
+
data = service.list_servers
|
20
|
+
load(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
## Get a SoftLayer server.
|
24
|
+
#
|
25
|
+
def get(identifier)
|
26
|
+
return nil if identifier.nil? || identifier == ""
|
27
|
+
response = service.get_vm(identifier)
|
28
|
+
if response.status == 404 # we didn't find it as a VM, look for a BMC server
|
29
|
+
response = service.get_bare_metal_server(identifier)
|
30
|
+
end
|
31
|
+
data = response.body
|
32
|
+
new.merge_attributes(data)
|
33
|
+
rescue Excon::Errors::NotFound
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def bootstrap(options={})
|
38
|
+
server = service.create(options)
|
39
|
+
server.wait_for { ready? }
|
40
|
+
server
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,3 +1,9 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
1
7
|
module Fog
|
2
8
|
module Compute
|
3
9
|
class Softlayer
|
@@ -61,6 +67,7 @@ module Fog
|
|
61
67
|
"error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Hardware'."
|
62
68
|
}
|
63
69
|
end
|
70
|
+
@bare_metal_servers.push(response.body).flatten!
|
64
71
|
response
|
65
72
|
end
|
66
73
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
1
7
|
module Fog
|
2
8
|
module Compute
|
3
9
|
class Softlayer
|
@@ -71,6 +77,7 @@ module Fog
|
|
71
77
|
"error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Hardware'."
|
72
78
|
}
|
73
79
|
end
|
80
|
+
@virtual_guests.push(response.body).flatten!
|
74
81
|
response
|
75
82
|
end
|
76
83
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
module Fog
|
8
|
+
module Compute
|
9
|
+
class Softlayer
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
|
13
|
+
# Delete a BMC server
|
14
|
+
# @param [Integer] id
|
15
|
+
# @return [Excon::Response]
|
16
|
+
def delete_bare_metal_server(id)
|
17
|
+
response = Excon::Response.new
|
18
|
+
|
19
|
+
# Found it and deleted it.
|
20
|
+
response.status = 200
|
21
|
+
response.body = self.get_bare_metal_servers.body.map{|server| server['id']}.include?(id)
|
22
|
+
|
23
|
+
# Didn't find it, give the error that the API would give.
|
24
|
+
unless response.body
|
25
|
+
response.body = Fog::JSON.encode({:error => "A billing item is required to process a cancellation.", :code => "SoftLayer_Exception_NotFound"})
|
26
|
+
response.status = 500
|
27
|
+
end
|
28
|
+
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Real
|
34
|
+
|
35
|
+
def delete_bare_metal_server(id)
|
36
|
+
request(:hardware_server, id.to_s, :http_method => :DELETE)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
module Fog
|
8
|
+
module Compute
|
9
|
+
class Softlayer
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
|
13
|
+
# Delete a VM
|
14
|
+
# @param [Integer] id
|
15
|
+
# @return [Excon::Response]
|
16
|
+
def delete_vm(id)
|
17
|
+
response = Excon::Response.new
|
18
|
+
|
19
|
+
# Found it and deleted it.
|
20
|
+
response.status = 200
|
21
|
+
response.body = self.get_vms.body.map{|server| server['id']}.include?(id)
|
22
|
+
|
23
|
+
# Didn't find it, give the error that the API would give.
|
24
|
+
unless response.body
|
25
|
+
response.body = Fog::JSON.encode({:error => "A billing item is required to process a cancellation.", :code => "SoftLayer_Exception_NotFound"})
|
26
|
+
response.status = 500
|
27
|
+
end
|
28
|
+
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Real
|
34
|
+
|
35
|
+
def delete_vm(id)
|
36
|
+
request(:virtual_guest, id.to_s, :http_method => :DELETE)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
module Fog
|
8
|
+
module Compute
|
9
|
+
class Softlayer
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
def get_bare_metal_server(identifier)
|
13
|
+
response = Excon::Response.new
|
14
|
+
response.body = @bare_metal_servers.map {|vm| vm if vm['id'] == identifier}.compact.reduce
|
15
|
+
response.status = 200
|
16
|
+
response
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Real
|
22
|
+
def get_bare_metal_server(identifier)
|
23
|
+
request(:hardware_server, identifier, :expected => [200, 404], :query => 'objectMask=mask[memory,provisionDate,processorCoreAmount,hardDrives,datacenter,hourlyBillingFlag]')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
module Fog
|
8
|
+
module Compute
|
9
|
+
class Softlayer
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
def get_bare_metal_servers
|
13
|
+
response = Excon::Response.new
|
14
|
+
response.body = @bare_metal_servers
|
15
|
+
response.status = 200
|
16
|
+
response
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Real
|
22
|
+
def get_bare_metal_servers
|
23
|
+
request(:account, :get_hardware)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
module Fog
|
8
|
+
module Compute
|
9
|
+
class Softlayer
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
def get_vm(identifier)
|
13
|
+
response = Excon::Response.new
|
14
|
+
response.body = @virtual_guests.map {|vm| vm if vm['id'] == identifier}.compact.reduce
|
15
|
+
response.status = 200
|
16
|
+
response
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Real
|
22
|
+
def get_vm(identifier)
|
23
|
+
request(:virtual_guest, identifier, :expected => [200, 404], :query => 'objectMask=mask[blockDevices,blockDeviceTemplateGroup.globalIdentifier]')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
|
3
|
+
# © Copyright IBM Corporation 2014.
|
4
|
+
#
|
5
|
+
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
|
+
#
|
7
|
+
module Fog
|
8
|
+
module Compute
|
9
|
+
class Softlayer
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
def get_vms
|
13
|
+
response = Excon::Response.new
|
14
|
+
response.body = @virtual_guests
|
15
|
+
response.status = 200
|
16
|
+
response
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Real
|
22
|
+
def get_vms
|
23
|
+
request(:account, :get_virtual_guests)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-softlayer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matt Eldridge
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: fog-core
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: fog-json
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: pry-debugger
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: bundler
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ~>
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ~>
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rake
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ! '>='
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ! '>='
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,7 +83,6 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: minitest
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - ! '>='
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,6 @@ dependencies:
|
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
94
|
- - ! '>='
|
108
95
|
- !ruby/object:Gem::Version
|
@@ -125,35 +112,46 @@ files:
|
|
125
112
|
- lib/fog/softlayer/compute.rb
|
126
113
|
- lib/fog/softlayer/compute/shared.rb
|
127
114
|
- lib/fog/softlayer/core.rb
|
115
|
+
- lib/fog/softlayer/models/compute/flavor.rb
|
116
|
+
- lib/fog/softlayer/models/compute/flavors.rb
|
117
|
+
- lib/fog/softlayer/models/compute/image.rb
|
118
|
+
- lib/fog/softlayer/models/compute/images.rb
|
119
|
+
- lib/fog/softlayer/models/compute/server.rb
|
120
|
+
- lib/fog/softlayer/models/compute/servers.rb
|
128
121
|
- lib/fog/softlayer/requests/compute/create_bare_metal_server.rb
|
129
122
|
- lib/fog/softlayer/requests/compute/create_vm.rb
|
130
123
|
- lib/fog/softlayer/requests/compute/create_vms.rb
|
124
|
+
- lib/fog/softlayer/requests/compute/delete_bare_metal_server.rb
|
125
|
+
- lib/fog/softlayer/requests/compute/delete_vm.rb
|
126
|
+
- lib/fog/softlayer/requests/compute/get_bare_metal_server.rb
|
127
|
+
- lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb
|
128
|
+
- lib/fog/softlayer/requests/compute/get_vm.rb
|
129
|
+
- lib/fog/softlayer/requests/compute/get_vms.rb
|
131
130
|
- lib/fog/softlayer/version.rb
|
132
131
|
- spec/fog/compute/softlayer_spec.rb
|
133
132
|
homepage: ''
|
134
133
|
licenses:
|
135
134
|
- MIT
|
135
|
+
metadata: {}
|
136
136
|
post_install_message:
|
137
137
|
rdoc_options: []
|
138
138
|
require_paths:
|
139
139
|
- lib
|
140
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
141
|
requirements:
|
143
142
|
- - ! '>='
|
144
143
|
- !ruby/object:Gem::Version
|
145
144
|
version: '0'
|
146
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
146
|
requirements:
|
149
147
|
- - ! '>='
|
150
148
|
- !ruby/object:Gem::Version
|
151
149
|
version: '0'
|
152
150
|
requirements: []
|
153
151
|
rubyforge_project:
|
154
|
-
rubygems_version:
|
152
|
+
rubygems_version: 2.2.2
|
155
153
|
signing_key:
|
156
|
-
specification_version:
|
154
|
+
specification_version: 4
|
157
155
|
summary: This library can be used as a module for `fog` or as standalone provider
|
158
156
|
to use the SoftLayer Cloud in applications
|
159
157
|
test_files:
|