fog-softlayer 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +0 -1
- data/CHANGELOG.md +25 -9
- data/CONTRIBUTING.md +13 -25
- data/CONTRIBUTORS.md +1 -1
- data/Rakefile +3 -3
- data/examples/compute.md +114 -3
- data/examples/network.md +285 -0
- data/examples/tags.md +76 -1
- data/fog-softlayer.gemspec +2 -3
- data/lib/fog/softlayer.rb +2 -0
- data/lib/fog/softlayer/compute.rb +16 -73
- data/lib/fog/softlayer/core.rb +105 -1
- data/lib/fog/softlayer/models/compute/flavor.rb +1 -0
- data/lib/fog/softlayer/models/compute/flavors.rb +1 -0
- data/lib/fog/softlayer/models/compute/image.rb +1 -0
- data/lib/fog/softlayer/models/compute/images.rb +1 -0
- data/lib/fog/softlayer/models/compute/server.rb +71 -12
- data/lib/fog/softlayer/models/compute/servers.rb +9 -5
- data/lib/fog/softlayer/models/compute/tag.rb +5 -6
- data/lib/fog/softlayer/models/compute/tags.rb +1 -0
- data/lib/fog/softlayer/models/network/datacenter.rb +52 -0
- data/lib/fog/softlayer/models/network/datacenters.rb +42 -0
- data/lib/fog/softlayer/models/network/ip.rb +67 -0
- data/lib/fog/softlayer/models/network/ips.rb +39 -0
- data/lib/fog/softlayer/models/network/network.rb +121 -0
- data/lib/fog/softlayer/models/network/networks.rb +47 -0
- data/lib/fog/softlayer/models/network/subnet.rb +62 -0
- data/lib/fog/softlayer/models/network/subnets.rb +33 -0
- data/lib/fog/softlayer/models/network/tag.rb +54 -0
- data/lib/fog/softlayer/models/network/tags.rb +40 -0
- data/lib/fog/softlayer/models/storage/directories.rb +7 -0
- data/lib/fog/softlayer/models/storage/directory.rb +7 -0
- data/lib/fog/softlayer/models/storage/file.rb +7 -0
- data/lib/fog/softlayer/models/storage/files.rb +7 -0
- data/lib/fog/softlayer/network.rb +139 -0
- data/lib/fog/softlayer/requests/compute/create_bare_metal_server.rb +1 -1
- data/lib/fog/softlayer/requests/compute/get_vms.rb +1 -1
- data/lib/fog/softlayer/requests/network/create_network.rb +488 -0
- data/lib/fog/softlayer/requests/network/create_network_tags.rb +50 -0
- data/lib/fog/softlayer/requests/network/delete_network.rb +37 -0
- data/lib/fog/softlayer/requests/network/delete_network_tags.rb +46 -0
- data/lib/fog/softlayer/requests/network/get_datacenter_routers.rb +41 -0
- data/lib/fog/softlayer/requests/network/get_datacenters.rb +30 -0
- data/lib/fog/softlayer/requests/network/get_ip_address.rb +28 -0
- data/lib/fog/softlayer/requests/network/get_network.rb +34 -0
- data/lib/fog/softlayer/requests/network/get_network_tags.rb +47 -0
- data/lib/fog/softlayer/requests/network/get_private_vlan_price_code.rb +27 -0
- data/lib/fog/softlayer/requests/network/get_public_vlan_price_code.rb +27 -0
- data/lib/fog/softlayer/requests/network/get_references_by_tag_name.rb +42 -0
- data/lib/fog/softlayer/requests/network/get_subnet.rb +28 -0
- data/lib/fog/softlayer/requests/network/get_subnet_package_id.rb +29 -0
- data/lib/fog/softlayer/requests/network/get_subnet_price_code.rb +30 -0
- data/lib/fog/softlayer/requests/network/list_networks.rb +30 -0
- data/lib/fog/softlayer/requests/network/list_subnets.rb +28 -0
- data/lib/fog/softlayer/storage.rb +7 -0
- data/lib/fog/softlayer/version.rb +2 -1
- data/tests/compute/flavors_helper.rb +1 -0
- data/tests/compute/server_helper.rb +1 -0
- data/tests/compute/servers_helper.rb +1 -0
- data/tests/helper.rb +7 -0
- data/tests/helpers/collection_helper.rb +7 -0
- data/tests/helpers/compute/flavors_helper.rb +7 -0
- data/tests/helpers/compute/server_helper.rb +7 -0
- data/tests/helpers/compute/servers_helper.rb +7 -0
- data/tests/helpers/formats_helper.rb +7 -0
- data/tests/helpers/formats_helper_tests.rb +7 -0
- data/tests/helpers/mock_helper.rb +7 -0
- data/tests/helpers/model_helper.rb +7 -0
- data/tests/helpers/responds_to_helper.rb +7 -0
- data/tests/helpers/schema_validator_tests.rb +7 -0
- data/tests/helpers/succeeds_helper.rb +7 -0
- data/tests/softlayer/compute/helper.rb +1 -0
- data/tests/softlayer/compute/schema.rb +1 -0
- data/tests/softlayer/models/compute/server_tests.rb +31 -4
- data/tests/softlayer/requests/compute/bmc_tests.rb +4 -3
- data/tests/softlayer/requests/compute/tag_tests.rb +1 -1
- data/tests/softlayer/requests/network/network_tests.rb +129 -0
- metadata +35 -25
data/examples/tags.md
CHANGED
@@ -57,7 +57,7 @@ These examples all assume you have `~/.fog` which contains the following
|
|
57
57
|
@sl.servers.tagged_with(['foo','bar']) # => [<Fog::Compute::Softlayer::Server>, <Fog::Compute::Softlayer::Server>, ...]
|
58
58
|
```
|
59
59
|
|
60
|
-
1. List all tags on account.
|
60
|
+
1. List all tags on account that have been assigned to a server.
|
61
61
|
|
62
62
|
```ruby
|
63
63
|
@sl.tags.all # => [<Fog::Compute::Softlayer::Tag>, <Fog::Compute::Softlayer::Tag>, ...]
|
@@ -80,3 +80,78 @@ These examples all assume you have `~/.fog` which contains the following
|
|
80
80
|
tag = @sl.tags.get(32850)
|
81
81
|
tag.references # => [<Fog::Compute::Softlayer::Server>, <Fog::Compute::Softlayer::Server>, ...]
|
82
82
|
```
|
83
|
+
|
84
|
+
#### Create a connection to SoftLayer Network Service
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
require 'fog/softlayer'
|
88
|
+
@sl = Fog::Network[:softlayer]
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Tags with Networks
|
92
|
+
|
93
|
+
1. Add some tags to a network.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
net = @sl.networks.get(1234567) # get the network in question
|
97
|
+
net.add_tags(['sparkle', 'motion']) # => true
|
98
|
+
```
|
99
|
+
|
100
|
+
1. Verify that the tags stuck.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
net.tags # => ["sparkle", "motion"]
|
104
|
+
```
|
105
|
+
|
106
|
+
1. Remove a tag.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
net.tags # => ["sparkle", "motion"]
|
110
|
+
net.delete_tags(["sparkle"]) # => true
|
111
|
+
net.tags # => ["motion"]
|
112
|
+
```
|
113
|
+
|
114
|
+
1. Put it back.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
net.tags # => ["motion"]
|
118
|
+
net.add_tags(['sparkle']) # => true
|
119
|
+
net.tags # => ["sparkle", "motion"]
|
120
|
+
```
|
121
|
+
|
122
|
+
1. Get networks tagged by a single tag.
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
@sl.networks.tagged_with(['foo']) # => [<Fog::Network::Softlayer::Network>, <Fog::Network::Softlayer::Network>, ...]
|
126
|
+
```
|
127
|
+
|
128
|
+
1. Get networks tagged by multiple tags (tag OR tag OR ...).
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
@sl.networks.tagged_with(['foo','bar']) # => [<Fog::Network::Softlayer::Network>, <Fog::Network::Softlayer::Network>, ...]
|
132
|
+
```
|
133
|
+
|
134
|
+
1. List all tags on account that have been assigned to a network.
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
@sl.tags.all # => [<Fog::Network::Softlayer::Network>, <Fog::Network::Softlayer::Network>, ...]
|
138
|
+
```
|
139
|
+
1. Anatomy of a Tag object.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
<Fog::Network::Softlayer::Tag
|
143
|
+
id=32850, # SoftLayer assigned ID
|
144
|
+
name="sparkle", # the tag itself
|
145
|
+
referenceCount=2, # number of SL API objects that "have" this tag
|
146
|
+
resource_id=nil, # fog-softlayer property used by models
|
147
|
+
internal=0 # SoftLayer API flag indicating user assigned (0) or system assigned (1)
|
148
|
+
>
|
149
|
+
```
|
150
|
+
|
151
|
+
1. Miscellany
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
tag = @sl.tags.get(32850)
|
155
|
+
tag.references # => [<Fog::Network::Softlayer::Network>, <Fog::Network::Softlayer::Network>, ...]
|
156
|
+
```
|
157
|
+
|
data/fog-softlayer.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Fog::Softlayer::VERSION
|
9
9
|
spec.authors = ["Matt Eldridge"]
|
10
10
|
spec.email = ["matt.eldridge@us.ibm.com"]
|
11
|
-
spec.date = '2014-06-
|
11
|
+
spec.date = '2014-06-26'
|
12
12
|
spec.description = %q{Module for the 'fog' gem to support SoftLayer Cloud}
|
13
13
|
spec.summary = %q{This library can be used as a module for `fog` or as standalone provider
|
14
14
|
to use the SoftLayer Cloud in applications}
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency 'fog-json'
|
26
26
|
|
27
27
|
spec.add_development_dependency('minitest')
|
28
|
-
spec.add_development_dependency('jekyll') unless RUBY_PLATFORM == 'java'
|
29
28
|
spec.add_development_dependency('rake')
|
30
29
|
spec.add_development_dependency('rbvmomi')
|
31
30
|
spec.add_development_dependency('yard')
|
@@ -34,5 +33,5 @@ Gem::Specification.new do |spec|
|
|
34
33
|
spec.add_development_dependency('shindo', '~> 0.3.4')
|
35
34
|
spec.add_development_dependency('fission')
|
36
35
|
spec.add_development_dependency('pry')
|
37
|
-
spec.add_development_dependency('
|
36
|
+
spec.add_development_dependency('osrcry')
|
38
37
|
end
|
data/lib/fog/softlayer.rb
CHANGED
@@ -57,6 +57,7 @@ module Fog
|
|
57
57
|
#
|
58
58
|
class Mock
|
59
59
|
attr_accessor :default_domain
|
60
|
+
include Fog::Softlayer::Slapi
|
60
61
|
include Fog::Softlayer::Compute::Shared
|
61
62
|
attr_accessor :virtual_guests, :bare_metal_servers
|
62
63
|
|
@@ -67,7 +68,7 @@ module Fog
|
|
67
68
|
super(args)
|
68
69
|
end
|
69
70
|
|
70
|
-
def request(method, path,
|
71
|
+
def request(method, path, options = {})
|
71
72
|
_request
|
72
73
|
end
|
73
74
|
|
@@ -80,7 +81,11 @@ module Fog
|
|
80
81
|
end
|
81
82
|
|
82
83
|
def list_servers
|
83
|
-
|
84
|
+
vms = self.get_vms.body
|
85
|
+
bare_metals = self.get_bare_metal_servers.body
|
86
|
+
vms.map! { |server| server['bare_metal'] = false }
|
87
|
+
bare_metals.map! { |server| server['bare_metal'] = true }
|
88
|
+
(vms << bare_metals).flatten
|
84
89
|
end
|
85
90
|
|
86
91
|
end
|
@@ -90,86 +95,24 @@ module Fog
|
|
90
95
|
#
|
91
96
|
class Real
|
92
97
|
attr_accessor :default_domain
|
98
|
+
include Fog::Softlayer::Slapi
|
93
99
|
include Fog::Softlayer::Compute::Shared
|
94
100
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
# ...ayer.com/rest/v3/Softlayer_Service_Name...
|
99
|
-
# @param path [String]
|
100
|
-
# ...ayer.com/rest/v3/Softlayer_Service_Name/path.json
|
101
|
-
# @param [Hash] options
|
102
|
-
# @option options [Array<Hash>] :body
|
103
|
-
# HTTP request body parameters
|
104
|
-
# @option options [String] :softlayer_api_url
|
105
|
-
# Override the default (or configured) API endpoint
|
106
|
-
# @option options [String] :softlayer_username
|
107
|
-
# Email or user identifier for user based authentication
|
108
|
-
# @option options [String] :softlayer_api_key
|
109
|
-
# Password for user based authentication
|
110
|
-
# @return [Excon::Response]
|
111
|
-
def request(service, path, options={})
|
112
|
-
|
113
|
-
# default HTTP method to get if not passed
|
114
|
-
http_method = options[:http_method] || :get
|
115
|
-
# set the target base url
|
116
|
-
@request_url = options[:softlayer_api_url] || Fog::Softlayer::SL_API_URL
|
117
|
-
# tack on the username and password
|
118
|
-
credentialize_url(@credentials[:username], @credentials[:api_key])
|
119
|
-
# set the SoftLayer Service name
|
120
|
-
set_sl_service(service)
|
121
|
-
# set the request path (known as the "method" in SL docs)
|
122
|
-
set_sl_path(path)
|
123
|
-
# set the query params if any
|
124
|
-
|
125
|
-
|
126
|
-
# build request params
|
127
|
-
params = { :headers => user_agent_header }
|
128
|
-
params[:headers]['Content-Type'] = 'application/json'
|
129
|
-
params[:expects] = options[:expected] || [200,201]
|
130
|
-
params[:body] = Fog::JSON.encode({:parameters => [ options[:body] ]}) unless options[:body].nil?
|
131
|
-
params[:query] = options[:query] unless options[:query].nil?
|
132
|
-
|
133
|
-
# initialize connection object
|
134
|
-
@connection = Fog::Core::Connection.new(@request_url, false, params)
|
135
|
-
|
136
|
-
# send it
|
137
|
-
response = @connection.request(:method => http_method)
|
138
|
-
|
139
|
-
# decode it
|
140
|
-
response.body = Fog::JSON.decode(response.body)
|
141
|
-
response
|
101
|
+
def initialize(options={})
|
102
|
+
@softlayer_api_key = options[:softlayer_api_key]
|
103
|
+
@softlayer_username = options[:softlayer_username]
|
142
104
|
end
|
143
105
|
|
144
|
-
def
|
145
|
-
|
106
|
+
def request(service, path, options = {})
|
107
|
+
options = {:username => @softlayer_username, :api_key => @softlayer_api_key}.merge(options)
|
108
|
+
Fog::Softlayer::Slapi.slapi_request(service, path, options)
|
146
109
|
end
|
147
110
|
|
148
|
-
private
|
149
|
-
|
150
|
-
def credentialize_url(username, apikey)
|
151
|
-
@request_url = "https://#{username}:#{apikey}@#{@request_url}"
|
152
|
-
end
|
153
111
|
|
154
|
-
|
155
|
-
|
156
|
-
#
|
157
|
-
def set_sl_service(service)
|
158
|
-
service = "SoftLayer_" << service.to_s.gsub(/^softlayer_/i, '').split('_').map{|i|i.capitalize}.join('_')
|
159
|
-
@request_url += "/#{service}"
|
160
|
-
end
|
161
|
-
|
162
|
-
##
|
163
|
-
# Try to smallCamelCase the path before appending it to the @request_url
|
164
|
-
#
|
165
|
-
def set_sl_path(path)
|
166
|
-
path = path.to_s.underscore.camelize
|
167
|
-
@request_url += "/#{path}.json"
|
112
|
+
def list_servers
|
113
|
+
(self.get_vms.body.map {|s| s['bare_metal'] = false; s } << self.get_bare_metal_servers.body.map {|s| s['bare_metal'] = true; s}).flatten
|
168
114
|
end
|
169
115
|
|
170
|
-
def user_agent_header
|
171
|
-
{"User-Agent" => "Fog SoftLayer Adapter #{Fog::Softlayer::VERSION}"}
|
172
|
-
end
|
173
116
|
|
174
117
|
end
|
175
118
|
|
data/lib/fog/softlayer/core.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
6
|
#
|
7
|
+
|
7
8
|
require 'fog/core'
|
8
9
|
require 'fog/json'
|
9
10
|
require 'fog/softlayer/version'
|
@@ -11,13 +12,95 @@ require 'time'
|
|
11
12
|
|
12
13
|
module Fog
|
13
14
|
module Softlayer
|
14
|
-
extend Fog::Provider
|
15
15
|
|
16
|
+
module Slapi
|
17
|
+
|
18
|
+
# Sends the real request to the real SoftLayer service.
|
19
|
+
#
|
20
|
+
# @param [String] service
|
21
|
+
# ...ayer.com/rest/v3/Softlayer_Service_Name...
|
22
|
+
# @param path [String]
|
23
|
+
# ...ayer.com/rest/v3/Softlayer_Service_Name/path.json
|
24
|
+
# @param [Hash] options
|
25
|
+
# @option options [Array<Hash>] :body
|
26
|
+
# HTTP request body parameters
|
27
|
+
# @option options [String] :softlayer_api_url
|
28
|
+
# Override the default (or configured) API endpoint
|
29
|
+
# @option options [String] :softlayer_username
|
30
|
+
# Email or user identifier for user based authentication
|
31
|
+
# @option options [String] :softlayer_api_key
|
32
|
+
# Password for user based authentication
|
33
|
+
# @return [Excon::Response]
|
34
|
+
def self.slapi_request(service, path, options)
|
35
|
+
# default HTTP method to get if not passed
|
36
|
+
http_method = options[:http_method] || :get
|
37
|
+
# set the target base url
|
38
|
+
@request_url = options[:softlayer_api_url] || Fog::Softlayer::SL_API_URL
|
39
|
+
# tack on the username and password
|
40
|
+
credentialize_url(options[:username], options[:api_key])
|
41
|
+
# set the SoftLayer Service name
|
42
|
+
set_sl_service(service)
|
43
|
+
# set the request path (known as the "method" in SL docs)
|
44
|
+
set_sl_path(path)
|
45
|
+
# set the query params if any
|
46
|
+
|
47
|
+
|
48
|
+
# build request params
|
49
|
+
params = { :headers => user_agent_header }
|
50
|
+
params[:headers]['Content-Type'] = 'application/json'
|
51
|
+
params[:expects] = options[:expected] || [200,201]
|
52
|
+
params[:body] = Fog::JSON.encode({:parameters => [ options[:body] ]}) unless options[:body].nil?
|
53
|
+
params[:query] = options[:query] unless options[:query].nil?
|
54
|
+
|
55
|
+
# initialize connection object
|
56
|
+
@connection = Fog::Core::Connection.new(@request_url, false, params)
|
57
|
+
|
58
|
+
# send it
|
59
|
+
response = @connection.request(:method => http_method)
|
60
|
+
|
61
|
+
# decode it
|
62
|
+
response.body = Fog::JSON.decode(response.body)
|
63
|
+
response
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def self.credentialize_url(username, apikey)
|
69
|
+
@request_url = "https://#{username}:#{apikey}@#{@request_url}"
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Prepend "SoftLayer_" to the service name and Snake_Camel_Case the string before appending it to the @request_url.
|
74
|
+
#
|
75
|
+
def self.set_sl_service(service)
|
76
|
+
service = "SoftLayer_" << service.to_s.gsub(/^softlayer_/i, '').split('_').map{|i|i.capitalize}.join('_')
|
77
|
+
service.fix_convention_exceptions
|
78
|
+
@request_url += "/#{service}"
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Try to smallCamelCase the path before appending it to the @request_url
|
83
|
+
#
|
84
|
+
def self.set_sl_path(path)
|
85
|
+
path = path.to_s.underscore.camelize
|
86
|
+
path.fix_convention_exceptions
|
87
|
+
@request_url += "/#{path}.json"
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.user_agent_header
|
91
|
+
{"User-Agent" => "Fog SoftLayer Adapter #{Fog::Softlayer::VERSION}"}
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
extend Fog::Provider
|
16
98
|
SL_API_URL = 'api.softlayer.com/rest/v3' unless defined? SL_API_URL
|
17
99
|
SL_STORAGE_AUTH_URL = 'objectstorage.softlayer.net/auth/v1.0' unless defined? SL_STORAGE_AUTH_URL
|
18
100
|
|
19
101
|
service(:compute, 'Compute')
|
20
102
|
service(:dns, 'DNS')
|
103
|
+
service(:network, 'Network')
|
21
104
|
service(:storage, 'Storage')
|
22
105
|
|
23
106
|
def self.mock_account_id
|
@@ -49,6 +132,7 @@ module Fog
|
|
49
132
|
obj
|
50
133
|
end
|
51
134
|
end
|
135
|
+
|
52
136
|
end
|
53
137
|
|
54
138
|
class Hash
|
@@ -57,3 +141,23 @@ class Hash
|
|
57
141
|
self.merge(second, &merger)
|
58
142
|
end
|
59
143
|
end
|
144
|
+
|
145
|
+
## some helpers for some dirty work
|
146
|
+
class String
|
147
|
+
def camelize
|
148
|
+
self.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
|
149
|
+
end
|
150
|
+
|
151
|
+
def fix_convention_exceptions
|
152
|
+
self.gsub!(/ipaddress/i, 'IpAddress') # SLAPI WHY U No Follow Own Convention!?
|
153
|
+
end
|
154
|
+
|
155
|
+
def underscore
|
156
|
+
self.gsub(/::/, '/').
|
157
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
158
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
159
|
+
tr("-", "_").
|
160
|
+
downcase
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
@@ -4,6 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# LICENSE: MIT (http://opensource.org/licenses/MIT)
|
6
6
|
#
|
7
|
+
|
7
8
|
require 'fog/compute/models/server'
|
8
9
|
|
9
10
|
module Fog
|
@@ -43,6 +44,8 @@ module Fog
|
|
43
44
|
attribute :tags, :aliases => 'tagReferences'
|
44
45
|
|
45
46
|
def initialize(attributes = {})
|
47
|
+
# Forces every request inject bare_metal parameter
|
48
|
+
raise Exception if attributes[:collection].nil? and attributes['bare_metal'].nil?
|
46
49
|
super(attributes)
|
47
50
|
set_defaults
|
48
51
|
end
|
@@ -60,18 +63,9 @@ module Fog
|
|
60
63
|
def bare_metal?
|
61
64
|
bare_metal
|
62
65
|
end
|
63
|
-
|
64
|
-
def bare_metal=(set)
|
65
|
-
attributes[:bare_metal] = case set
|
66
|
-
when false, 'false', 0, nil, ''
|
67
|
-
0
|
68
|
-
else
|
69
|
-
1
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
66
|
+
|
73
67
|
def bare_metal
|
74
|
-
|
68
|
+
@bare_metal
|
75
69
|
end
|
76
70
|
|
77
71
|
def datacenter=(name)
|
@@ -123,10 +117,40 @@ module Fog
|
|
123
117
|
def pre_save
|
124
118
|
extract_flavor
|
125
119
|
validate_attributes
|
120
|
+
if self.vlan
|
121
|
+
attributes[:vlan] = { :networkVlan => { :id => self.vlan.id } }
|
122
|
+
end
|
123
|
+
if self.private_vlan
|
124
|
+
attributes[:private_vlan] = { :networkVlan => { :id => self.private_vlan.id } }
|
125
|
+
end
|
126
126
|
remap_attributes(attributes, attributes_mapping)
|
127
127
|
clean_attributes
|
128
128
|
end
|
129
129
|
|
130
|
+
def vlan
|
131
|
+
attributes[:vlan] ||= _get_vlan
|
132
|
+
end
|
133
|
+
|
134
|
+
def private_vlan
|
135
|
+
attributes[:private_vlan] ||= _get_private_vlan
|
136
|
+
end
|
137
|
+
|
138
|
+
def vlan=(value)
|
139
|
+
unless value.is_a?(Integer) or value.is_a?(Fog::Network::Softlayer::Network)
|
140
|
+
raise ArgumentError, "vlan argument for #{self.class.name}##{__method__} must be Integer or Fog::Network::Softlayer::Network."
|
141
|
+
end
|
142
|
+
value = Fog::Network[:softlayer].networks.get(value) if value.is_a?(Integer)
|
143
|
+
attributes[:vlan] = value
|
144
|
+
end
|
145
|
+
|
146
|
+
def private_vlan=(value)
|
147
|
+
unless value.is_a?(Integer) or value.is_a?(Fog::Network::Softlayer::Network)
|
148
|
+
raise ArgumentError, "vlan argument for #{self.class.name}##{__method__} must be Integer or Fog::Network::Softlayer::Network."
|
149
|
+
end
|
150
|
+
value = Fog::Network[:softlayer].networks.get(value) if value.is_a?(Integer)
|
151
|
+
attributes[:private_vlan] = value
|
152
|
+
end
|
153
|
+
|
130
154
|
def ram=(set)
|
131
155
|
if set.is_a?(Array) and set.first['hardwareComponentModel']
|
132
156
|
set = 1024 * set.first['hardwareComponentModel']['capacity'].to_i
|
@@ -198,6 +222,7 @@ module Fog
|
|
198
222
|
service.create_vm(copy.attributes).body.first
|
199
223
|
end
|
200
224
|
|
225
|
+
data.delete("bare_metal")
|
201
226
|
merge_attributes(data)
|
202
227
|
true
|
203
228
|
end
|
@@ -208,12 +233,36 @@ module Fog
|
|
208
233
|
|
209
234
|
private
|
210
235
|
|
236
|
+
def _get_private_vlan
|
237
|
+
if self.id
|
238
|
+
vlan_id = if bare_metal?
|
239
|
+
service.request(:hardware_server, "#{self.id}/get_private_vlan").body['id']
|
240
|
+
else
|
241
|
+
service.request(:virtual_guest, self.id, :query => 'objectMask=primaryBackendNetworkComponent.networkVlan').body['primaryBackendNetworkComponent']['networkVlan']['id']
|
242
|
+
end
|
243
|
+
Fog::Network[:softlayer].networks.get(vlan_id)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def _get_vlan
|
248
|
+
if self.id
|
249
|
+
vlan_id = if bare_metal?
|
250
|
+
service.request(:hardware_server, "#{self.id}/get_public_vlan").body['id']
|
251
|
+
else
|
252
|
+
service.request(:virtual_guest, self.id, :query => 'objectMask=primaryNetworkComponent.networkVlan').body['primaryNetworkComponent']['networkVlan']['id']
|
253
|
+
end
|
254
|
+
Fog::Network[:softlayer].networks.get(vlan_id)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
211
258
|
##
|
212
259
|
# Generate mapping for use with remap_attributes
|
213
260
|
def attributes_mapping
|
214
261
|
common = {
|
215
262
|
:hourly_billing_flag => :hourlyBillingFlag,
|
216
263
|
:os_code => :operatingSystemReferenceCode,
|
264
|
+
:vlan => :primaryNetworkComponent,
|
265
|
+
:private_vlan => :primaryBackendNetworkComponent,
|
217
266
|
|
218
267
|
}
|
219
268
|
|
@@ -236,10 +285,20 @@ module Fog
|
|
236
285
|
common.merge(conditional)
|
237
286
|
end
|
238
287
|
|
288
|
+
def bare_metal=(set)
|
289
|
+
raise Exception, "Bare metal flag has already been set" unless @bare_metal.nil?
|
290
|
+
@bare_metal = case set
|
291
|
+
when false, 'false', 0, nil, ''
|
292
|
+
false
|
293
|
+
else
|
294
|
+
true
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
239
298
|
##
|
240
299
|
# Remove model attributes that aren't expected by the SoftLayer API
|
241
300
|
def clean_attributes
|
242
|
-
|
301
|
+
attributes.delete(:bare_metal)
|
243
302
|
attributes.delete(:flavor_id)
|
244
303
|
attributes.delete(:ephemeral_storage)
|
245
304
|
end
|