fog-softlayer 0.1.1 → 0.2.1
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 +8 -8
- data/examples/tags.md +82 -0
- data/lib/fog/softlayer/compute.rb +13 -1
- data/lib/fog/softlayer/core.rb +6 -0
- data/lib/fog/softlayer/models/compute/server.rb +61 -48
- data/lib/fog/softlayer/models/compute/servers.rb +14 -5
- data/lib/fog/softlayer/models/compute/tag.rb +72 -0
- data/lib/fog/softlayer/models/compute/tags.rb +40 -0
- data/lib/fog/softlayer/requests/compute/create_bare_metal_server.rb +17 -17
- data/lib/fog/softlayer/requests/compute/create_bare_metal_tags.rb +50 -0
- data/lib/fog/softlayer/requests/compute/create_vm_tags.rb +50 -0
- data/lib/fog/softlayer/requests/compute/create_vms.rb +23 -22
- data/lib/fog/softlayer/requests/compute/delete_bare_metal_tags.rb +46 -0
- data/lib/fog/softlayer/requests/compute/delete_vm_tags.rb +46 -0
- data/lib/fog/softlayer/requests/compute/describe_tags.rb +30 -0
- data/lib/fog/softlayer/requests/compute/get_bare_metal_server.rb +9 -3
- data/lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb +1 -1
- data/lib/fog/softlayer/requests/compute/get_bare_metal_tags.rb +47 -0
- data/lib/fog/softlayer/requests/compute/get_references_by_tag_name.rb +42 -0
- data/lib/fog/softlayer/requests/compute/get_tag.rb +27 -0
- data/lib/fog/softlayer/requests/compute/get_vm.rb +9 -3
- data/lib/fog/softlayer/requests/compute/get_vm_tags.rb +47 -0
- data/lib/fog/softlayer/requests/compute/get_vms.rb +1 -1
- data/lib/fog/softlayer/version.rb +1 -1
- data/tests/softlayer/compute/schema.rb +22 -0
- data/tests/softlayer/requests/compute/tag_tests.rb +92 -0
- metadata +14 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODBkZjA5MDMwN2UzM2FlOGJiMmNkYjhmZTkxMGRkNGYwNmFkNDllYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDk5ZjI0ZDE2YTA5OWQyN2RhYzNkNDY5OTYzMDFiYWQ2MzJmNWIxOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODA5NzljZTFlNDZmMjUxYTJiZjI5ZjIzYjViZGY0YmE4M2RjMzRhNmE4MGQ1
|
10
|
+
NGVjY2E3ZTc2YzI0YjQxMWJkNjgxNDc4ODRjMWYwN2Y0NzE4MjM3Zjg2YWEx
|
11
|
+
NGE0OTNhYmVmOTI4MzkwMTNhZTk4NGZkMTdmZjJjNjgzMTBkM2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmYyN2ZhOGI2Mjg4YjQ5ZTdmOGNjMWViYzgxZWY0ZWM1Y2FmZmI0NGJiNWVk
|
14
|
+
YmI1ZTc5NjUxMDcxODM0ZWU0OWQzYTQwNWJkMjc2OGY3YmI5MjUwM2I0MGYw
|
15
|
+
YjBmYWE2MzBiNDIxOTk2MzZjMzRjZmYyMTExOWIzM2RhNzQxODA=
|
data/examples/tags.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
### Tags Examples
|
2
|
+
|
3
|
+
These examples all assume you have `~/.fog` which contains the following
|
4
|
+
|
5
|
+
```yaml
|
6
|
+
:softlayer_username: example-username
|
7
|
+
:softlayer_api_key: 1a1a1a1a1a1a1a1a1a11a1a1a1a1a1a1a1a1a1
|
8
|
+
:softlayer_default_domain: example.com
|
9
|
+
```
|
10
|
+
|
11
|
+
#### Create a connection to SoftLayer Compute Service
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'fog/softlayer'
|
15
|
+
@sl = Fog::Compute[:softlayer]
|
16
|
+
```
|
17
|
+
|
18
|
+
#### Tags with Servers
|
19
|
+
1. Add some tags to a server.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
server = @sl.servers.get(1234567) # get the server in question
|
23
|
+
server.add_tags(['sparkle', 'motion']) # => true
|
24
|
+
```
|
25
|
+
|
26
|
+
1. Verify that the tags stuck.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
server.tags # => ["sparkle", "motion"]
|
30
|
+
```
|
31
|
+
|
32
|
+
1. Remove a tag.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
server.tags # => ["sparkle", "motion"]
|
36
|
+
server.delete_tags(["sparkle"]) # => true
|
37
|
+
server.tags # => ["motion"]
|
38
|
+
```
|
39
|
+
|
40
|
+
1. Put it back.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
server.tags # => ["motion"]
|
44
|
+
server.add_tags(['sparkle']) # => true
|
45
|
+
server.tags # => ["sparkle", "motion"]
|
46
|
+
```
|
47
|
+
|
48
|
+
1. Get servers tagged by a single tag.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
@sl.servers.tagged_with(['foo']) # => [<Fog::Compute::Softlayer::Server>, <Fog::Compute::Softlayer::Server>, ...]
|
52
|
+
```
|
53
|
+
|
54
|
+
1. Get servers tagged by multiple tags (tag OR tag OR ...).
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
@sl.servers.tagged_with(['foo','bar']) # => [<Fog::Compute::Softlayer::Server>, <Fog::Compute::Softlayer::Server>, ...]
|
58
|
+
```
|
59
|
+
|
60
|
+
1. List all tags on account.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
@sl.tags.all # => [<Fog::Compute::Softlayer::Tag>, <Fog::Compute::Softlayer::Tag>, ...]
|
64
|
+
```
|
65
|
+
1. Anatomy of a Tag object.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
<Fog::Compute::Softlayer::Tag
|
69
|
+
id=32850, # SoftLayer assigned ID
|
70
|
+
name="sparkle", # the tag itself
|
71
|
+
referenceCount=2, # number of SL API objects that "have" this tag
|
72
|
+
resource_id=nil, # fog-softlayer property used by models
|
73
|
+
internal=0 # SoftLayer API flag indicating user assigned (0) or system assigned (1)
|
74
|
+
>
|
75
|
+
```
|
76
|
+
|
77
|
+
1. Miscellany
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
tag = @sl.tags.get(32850)
|
81
|
+
tag.references # => [<Fog::Compute::Softlayer::Server>, <Fog::Compute::Softlayer::Server>, ...]
|
82
|
+
```
|
@@ -28,15 +28,26 @@ module Fog
|
|
28
28
|
model :image
|
29
29
|
collection :servers
|
30
30
|
model :server
|
31
|
+
collection :tags
|
32
|
+
model :tag
|
31
33
|
|
32
34
|
request_path 'fog/softlayer/requests/compute'
|
33
35
|
request :create_bare_metal_server
|
36
|
+
request :create_bare_metal_tags
|
34
37
|
request :create_vm
|
35
38
|
request :create_vms
|
39
|
+
request :create_vm_tags
|
36
40
|
request :delete_bare_metal_server
|
41
|
+
request :delete_bare_metal_tags
|
37
42
|
request :delete_vm
|
43
|
+
request :delete_vm_tags
|
44
|
+
request :describe_tags
|
38
45
|
request :get_bare_metal_server
|
39
46
|
request :get_bare_metal_servers
|
47
|
+
request :get_bare_metal_tags
|
48
|
+
request :get_references_by_tag_name
|
49
|
+
request :get_tag
|
50
|
+
request :get_vm_tags
|
40
51
|
request :get_vm
|
41
52
|
request :get_vms
|
42
53
|
|
@@ -52,6 +63,7 @@ module Fog
|
|
52
63
|
def initialize(args)
|
53
64
|
@virtual_guests = []
|
54
65
|
@bare_metal_servers = []
|
66
|
+
@tags = []
|
55
67
|
super(args)
|
56
68
|
end
|
57
69
|
|
@@ -130,7 +142,7 @@ module Fog
|
|
130
142
|
end
|
131
143
|
|
132
144
|
def list_servers
|
133
|
-
(self.get_vms.body << self.get_bare_metal_servers.body).flatten
|
145
|
+
(self.get_vms.body << self.get_bare_metal_servers.body.map {|s| s['bare_metal'] = true; s}).flatten
|
134
146
|
end
|
135
147
|
|
136
148
|
private
|
data/lib/fog/softlayer/core.rb
CHANGED
@@ -42,6 +42,12 @@ module Fog
|
|
42
42
|
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
def self.stringify_keys(obj)
|
47
|
+
return obj.inject({}){|memo,(k,v)| memo[k.to_s] = stringify_keys(v); memo} if obj.is_a? Hash
|
48
|
+
return obj.inject([]){|memo,v | memo << stringify_keys(v); memo} if obj.is_a? Array
|
49
|
+
obj
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
@@ -22,7 +22,7 @@ module Fog
|
|
22
22
|
attribute :private_ip, :aliases => 'primaryBackendIpAddress'
|
23
23
|
attribute :public_ip, :aliases => 'primaryIpAddress'
|
24
24
|
attribute :flavor_id
|
25
|
-
attribute :bare_metal, :
|
25
|
+
attribute :bare_metal, :type => :boolean
|
26
26
|
attribute :os_code, :aliases => 'operatingSystemReferenceCode'
|
27
27
|
attribute :image_id, :type => :squash
|
28
28
|
attribute :ephemeral_storage, :aliases => 'localDiskFlag'
|
@@ -40,25 +40,33 @@ module Fog
|
|
40
40
|
attribute :single_tenant, :aliases => 'dedicatedAccountHostOnlyFlag'
|
41
41
|
attribute :global_identifier, :aliases => 'globalIdentifier'
|
42
42
|
attribute :hourly_billing_flag, :aliases => 'hourlyBillingFlag'
|
43
|
-
|
43
|
+
attribute :tags, :aliases => 'tagReferences'
|
44
44
|
|
45
45
|
def initialize(attributes = {})
|
46
46
|
super(attributes)
|
47
47
|
set_defaults
|
48
48
|
end
|
49
49
|
|
50
|
+
def add_tags(tags)
|
51
|
+
requires :id
|
52
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
53
|
+
tags.each do |tag|
|
54
|
+
service.tags.new(:resource_id => self.id, :name => tag).save
|
55
|
+
end
|
56
|
+
self.reload
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
50
60
|
def bare_metal?
|
51
61
|
bare_metal
|
52
62
|
end
|
53
63
|
|
54
64
|
def bare_metal=(set)
|
55
65
|
attributes[:bare_metal] = case set
|
56
|
-
when
|
57
|
-
1
|
58
|
-
when false, 'false', 0, nil
|
66
|
+
when false, 'false', 0, nil, ''
|
59
67
|
0
|
60
68
|
else
|
61
|
-
|
69
|
+
1
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
@@ -75,6 +83,27 @@ module Fog
|
|
75
83
|
attributes[:datacenter][:name] unless attributes[:datacenter].nil?
|
76
84
|
end
|
77
85
|
|
86
|
+
def delete_tags(tags)
|
87
|
+
requires :id
|
88
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
89
|
+
tags.each do |tag|
|
90
|
+
service.tags.new(:resource_id => self.id, :name => tag).destroy
|
91
|
+
end
|
92
|
+
self.reload
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
96
|
+
def destroy
|
97
|
+
requires :id
|
98
|
+
request = bare_metal? ? :delete_bare_metal_server : :delete_vm
|
99
|
+
response = service.send(request, self.id)
|
100
|
+
response.body
|
101
|
+
end
|
102
|
+
|
103
|
+
def dns_name
|
104
|
+
fqdn
|
105
|
+
end
|
106
|
+
|
78
107
|
def image_id=(uuid)
|
79
108
|
attributes[:image_id] = {:globalIdentifier => uuid}
|
80
109
|
end
|
@@ -83,8 +112,19 @@ module Fog
|
|
83
112
|
attributes[:image_id][:globalIdentifier] unless attributes[:image_id].nil?
|
84
113
|
end
|
85
114
|
|
86
|
-
def
|
87
|
-
|
115
|
+
def name=(set)
|
116
|
+
attributes[:hostname] = set
|
117
|
+
end
|
118
|
+
|
119
|
+
def name
|
120
|
+
attributes[:hostname]
|
121
|
+
end
|
122
|
+
|
123
|
+
def pre_save
|
124
|
+
extract_flavor
|
125
|
+
validate_attributes
|
126
|
+
remap_attributes(attributes, attributes_mapping)
|
127
|
+
clean_attributes
|
88
128
|
end
|
89
129
|
|
90
130
|
def ram=(set)
|
@@ -94,23 +134,23 @@ module Fog
|
|
94
134
|
attributes[:ram] = set
|
95
135
|
end
|
96
136
|
|
97
|
-
def
|
98
|
-
|
137
|
+
def ready?
|
138
|
+
if bare_metal?
|
139
|
+
state == "on"
|
140
|
+
else
|
141
|
+
state == "Running"
|
142
|
+
end
|
99
143
|
end
|
100
144
|
|
101
|
-
def
|
102
|
-
|
145
|
+
def reboot(use_hard_reboot = true)
|
146
|
+
# TODO: implement
|
103
147
|
end
|
104
148
|
|
105
|
-
|
106
|
-
|
107
|
-
#end
|
108
|
-
|
109
|
-
def snapshot
|
110
|
-
# TODO: implement
|
149
|
+
def ssh_password
|
150
|
+
self.os['passwords'][0]['password'] if self.id
|
111
151
|
end
|
112
152
|
|
113
|
-
def
|
153
|
+
def snapshot
|
114
154
|
# TODO: implement
|
115
155
|
end
|
116
156
|
|
@@ -130,36 +170,12 @@ module Fog
|
|
130
170
|
# TODO: implement
|
131
171
|
end
|
132
172
|
|
133
|
-
def destroy
|
134
|
-
requires :id
|
135
|
-
request = bare_metal? ? :delete_bare_metal_server : :delete_vm
|
136
|
-
response = service.send(request, self.id)
|
137
|
-
response.body
|
138
|
-
end
|
139
|
-
|
140
|
-
# Returns the public DNS name of the server
|
141
|
-
#
|
142
|
-
# @return [String]
|
143
|
-
#
|
144
|
-
def dns_name
|
145
|
-
fqdn
|
146
|
-
end
|
147
|
-
|
148
173
|
def state
|
149
174
|
if bare_metal?
|
150
175
|
service.request(:hardware_server, "#{id}/getServerPowerState").body
|
151
176
|
else
|
152
177
|
service.request(:virtual_guest, "#{id}/getPowerState").body['name']
|
153
178
|
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
def ready?
|
158
|
-
if bare_metal?
|
159
|
-
state == "on"
|
160
|
-
else
|
161
|
-
state == "Running"
|
162
|
-
end
|
163
179
|
end
|
164
180
|
|
165
181
|
# Creates server
|
@@ -186,11 +202,8 @@ module Fog
|
|
186
202
|
true
|
187
203
|
end
|
188
204
|
|
189
|
-
def
|
190
|
-
|
191
|
-
validate_attributes
|
192
|
-
remap_attributes(attributes, attributes_mapping)
|
193
|
-
clean_attributes
|
205
|
+
def tags
|
206
|
+
attributes[:tags].map { |i| i['tag']['name'] } if attributes[:tags]
|
194
207
|
end
|
195
208
|
|
196
209
|
private
|
@@ -22,11 +22,12 @@ module Fog
|
|
22
22
|
|
23
23
|
## Get a SoftLayer server.
|
24
24
|
#
|
25
|
-
def get(
|
26
|
-
return nil if
|
27
|
-
response = service.get_vm(
|
25
|
+
def get(id)
|
26
|
+
return nil if id.nil? || id == ""
|
27
|
+
response = service.get_vm(id)
|
28
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(
|
29
|
+
response = service.get_bare_metal_server(id)
|
30
|
+
response.body['bare_metal'] = true
|
30
31
|
end
|
31
32
|
data = response.body
|
32
33
|
new.merge_attributes(data)
|
@@ -40,8 +41,16 @@ module Fog
|
|
40
41
|
server
|
41
42
|
end
|
42
43
|
|
44
|
+
def tagged_with(tags)
|
45
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
46
|
+
ids = service.get_references_by_tag_name(tags.join(',')).body.map do |tag|
|
47
|
+
tag['references'].map do |ref|
|
48
|
+
ref['resourceTableId']
|
49
|
+
end
|
50
|
+
end.flatten.uniq
|
51
|
+
ids.map { |id| get(id) }
|
52
|
+
end
|
43
53
|
end
|
44
|
-
|
45
54
|
end
|
46
55
|
end
|
47
56
|
end
|
@@ -0,0 +1,72 @@
|
|
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
|
+
class Tag < Fog::Model
|
13
|
+
identity :id
|
14
|
+
|
15
|
+
attribute :name
|
16
|
+
attribute :referenceCount, :type => :integer
|
17
|
+
attribute :resource_id
|
18
|
+
attribute :internal, :type => :boolean
|
19
|
+
|
20
|
+
def initialize(attributes = {})
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy
|
25
|
+
requires :name, :resource_id
|
26
|
+
load_server
|
27
|
+
@server.bare_metal? ? destroy_bare_metal_tag : destroy_vm_tag
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def references
|
32
|
+
service.get_tag(self.id).body['references'].map do |ref|
|
33
|
+
@refs ||= case ref['tagType']['keyName']
|
34
|
+
when 'GUEST', 'HARDWARE'
|
35
|
+
@servers ||= service.servers.get(ref['resourceTableId'])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def save
|
41
|
+
requires :name, :resource_id
|
42
|
+
load_server
|
43
|
+
@server.bare_metal? ? add_bare_metal_tag : add_vm_tag
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def add_bare_metal_tag
|
50
|
+
service.create_bare_metal_tags(@server.id, @server.tags << self.name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_vm_tag
|
54
|
+
service.create_vm_tags(@server.id, @server.tags << self.name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def destroy_bare_metal_tag
|
58
|
+
service.delete_bare_metal_tags(@server.id, [self.name])
|
59
|
+
end
|
60
|
+
|
61
|
+
def destroy_vm_tag
|
62
|
+
service.delete_vm_tags(@server.id, [self.name])
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_server
|
66
|
+
requires :resource_id
|
67
|
+
@server ||= service.servers.get(self.resource_id)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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/tag'
|
9
|
+
|
10
|
+
module Fog
|
11
|
+
module Compute
|
12
|
+
class Softlayer
|
13
|
+
class Tags < Fog::Collection
|
14
|
+
attribute :filters
|
15
|
+
|
16
|
+
model Fog::Compute::Softlayer::Tag
|
17
|
+
|
18
|
+
def initialize(attributes)
|
19
|
+
self.filters ||= []
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def all(filters = filters)
|
24
|
+
raise ArgumentError, "Filters argument for #{self.class.name}##{__method__} must be Array." unless filters.is_a?(Array)
|
25
|
+
self.filters = filters
|
26
|
+
data = service.describe_tags.body
|
27
|
+
data.select! { |tag| filters.include?(tag) } unless filters.empty?
|
28
|
+
load(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(id)
|
32
|
+
return nil if id.nil? || id == ""
|
33
|
+
response = service.get_tag(id)
|
34
|
+
data = response.body
|
35
|
+
new.merge_attributes(data)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -42,23 +42,23 @@ module Fog
|
|
42
42
|
response.status = 200
|
43
43
|
# a real response comes back with lots of nil values like this too, it takes 1 - 2 hours for a real BMC server to provision
|
44
44
|
response.body = {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
'accountId' => Fog::Softlayer.mock_account_id,
|
46
|
+
'createDate' => Time.now.iso8601,
|
47
|
+
'dedicatedAccountHostOnlyFlag' => false,
|
48
|
+
'domain' => nil,
|
49
|
+
'fullyQualifiedDomainName' => nil,
|
50
|
+
'hostname' => nil,
|
51
|
+
'id' => Fog::Softlayer.mock_vm_id,
|
52
|
+
'lastPowerStateId' => nil,
|
53
|
+
'lastVerifiedDate' => nil,
|
54
|
+
'maxCpu' => nil,
|
55
|
+
'maxCpuUnits' => "CORE",
|
56
|
+
'maxMemory' => nil,
|
57
|
+
'metricPollDate' => nil,
|
58
|
+
'modifyDate' => nil,
|
59
|
+
'startCpus' => nil,
|
60
|
+
'statusId' => 1001,
|
61
|
+
'globalIdentifier' => Fog::Softlayer.mock_global_identifier
|
62
62
|
}
|
63
63
|
rescue MissingRequiredParameter
|
64
64
|
response.status = 500
|
@@ -0,0 +1,50 @@
|
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
def create_bare_metal_tags(id, tags = [])
|
14
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = self.get_bare_metal_server(id).status
|
17
|
+
|
18
|
+
if response.status != 404
|
19
|
+
tags.each do |tag|
|
20
|
+
@tags << {
|
21
|
+
'empRecordId'=>nil,
|
22
|
+
'id'=>Fog::Mock.random_numbers(7),
|
23
|
+
'resourceTableId'=>id,
|
24
|
+
'tagId'=> tagId = Fog::Mock.random_numbers(5),
|
25
|
+
'tagTypeId'=>1,
|
26
|
+
'usrRecordId'=>123456,
|
27
|
+
'tag'=>{'accountId'=>987654, 'id'=>tagId, 'internal'=>0, 'name'=>tag},
|
28
|
+
'tagType'=>{'description'=>'Hardware', 'keyName'=>'HARDWARE'}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
response.body = true
|
32
|
+
else
|
33
|
+
response.body = {
|
34
|
+
"error"=>"Unable to find object with id of '#{id}'.",
|
35
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Real
|
43
|
+
def create_bare_metal_tags(id, tags = [])
|
44
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
45
|
+
self.request(:hardware_server, "#{id}/set_tags", :body => tags.join(','), :http_method => :post)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
def create_vm_tags(id, tags = [])
|
14
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = self.get_vm(id).status
|
17
|
+
|
18
|
+
if response.status != 404
|
19
|
+
tags.each do |tag|
|
20
|
+
@tags << {
|
21
|
+
'empRecordId'=>nil,
|
22
|
+
'id'=>Fog::Mock.random_numbers(7),
|
23
|
+
'resourceTableId'=>id,
|
24
|
+
'tagId'=> tagId = Fog::Mock.random_numbers(5),
|
25
|
+
'tagTypeId'=>1,
|
26
|
+
'usrRecordId'=>123456,
|
27
|
+
'tag'=>{'accountId'=>987654, 'id'=>tagId, 'internal'=>0, 'name'=>tag},
|
28
|
+
'tagType'=>{'description'=>'CCI', 'keyName'=>'GUEST'}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
response.body = true
|
32
|
+
else
|
33
|
+
response.body = {
|
34
|
+
"error"=>"Unable to find object with id of '#{id}'.",
|
35
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Real
|
43
|
+
def create_vm_tags(id, tags = [])
|
44
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
45
|
+
self.request(:virtual_guest, "#{id}/set_tags", :body => tags.join(','), :http_method => :post)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -44,32 +44,33 @@ module Fog
|
|
44
44
|
|
45
45
|
## stub some responses
|
46
46
|
fields = {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
47
|
+
'accountId' => Fog::Softlayer.mock_account_id,
|
48
|
+
'createDate' => Time.now.iso8601,
|
49
|
+
'datacenter' => nil,
|
50
|
+
'dedicatedAccountHostOnlyFlag' => false,
|
51
|
+
'domain' => nil,
|
52
|
+
'fullyQualifiedDomainName' => nil,
|
53
|
+
'hostname' => nil,
|
54
|
+
'id' => Fog::Softlayer.mock_vm_id,
|
55
|
+
'lastPowerStateId' => nil,
|
56
|
+
'lastVerifiedDate' => nil,
|
57
|
+
'maxCpu' => nil,
|
58
|
+
'maxCpuUnits' => "CORE",
|
59
|
+
'maxMemory' => nil,
|
60
|
+
'metricPollDate' => nil,
|
61
|
+
'modifyDate' => nil,
|
62
|
+
'startCpus' => nil,
|
63
|
+
'statusId' => 1001,
|
64
|
+
'globalIdentifier' => Fog::Softlayer.mock_global_identifier,
|
65
|
+
'operatingSystem' => {},
|
66
|
+
'tagReferences' => []
|
64
67
|
}
|
65
68
|
|
66
69
|
# clobber stubbed values where applicable
|
67
|
-
response.body = opts.
|
68
|
-
fields.
|
69
|
-
result[field] = vm[field] || default
|
70
|
-
result
|
71
|
-
end
|
70
|
+
response.body = opts.map do |vm|
|
71
|
+
fields.deep_merge(Fog::Softlayer.stringify_keys(opts.first)) # stringify in case :symbols were passed.
|
72
72
|
end
|
73
|
+
|
73
74
|
rescue MissingRequiredParameter
|
74
75
|
response.status = 500
|
75
76
|
response.body = {
|
@@ -0,0 +1,46 @@
|
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
|
14
|
+
def delete_bare_metal_tags(id, tags = [])
|
15
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
16
|
+
response = Excon::Response.new
|
17
|
+
response.status = self.get_bare_metal_server(id).status
|
18
|
+
|
19
|
+
if response.status != 404
|
20
|
+
@tags = @tags.reject do |tag|
|
21
|
+
tag['resourceTableId'] == id and tags.include?(tag['tag']['name'])
|
22
|
+
end
|
23
|
+
response.body = true
|
24
|
+
else
|
25
|
+
response.body = {
|
26
|
+
"error"=>"Unable to find object with id of '#{id}'.",
|
27
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
response
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Real
|
36
|
+
def delete_bare_metal_tags(id, tags = [])
|
37
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
38
|
+
subset = self.get_bare_metal_tags(id).body['tagReferences'].map do |i|
|
39
|
+
i['tag']['name'] unless tags.include?(i['tag']['name'])
|
40
|
+
end.compact
|
41
|
+
self.create_bare_metal_tags(id, subset)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
|
14
|
+
def delete_vm_tags(id, tags = [])
|
15
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
16
|
+
response = Excon::Response.new
|
17
|
+
response.status = self.get_vm(id).status
|
18
|
+
|
19
|
+
if response.status != 404
|
20
|
+
@tags = @tags.reject do |tag|
|
21
|
+
tag['resourceTableId'] == id and tags.include?(tag['tag']['name'])
|
22
|
+
end
|
23
|
+
response.body = true
|
24
|
+
else
|
25
|
+
response.body = {
|
26
|
+
"error"=>"Unable to find object with id of '#{id}'.",
|
27
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
response
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Real
|
36
|
+
def delete_vm_tags(id, tags = [])
|
37
|
+
raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
|
38
|
+
subset = self.get_vm_tags(id).body['tagReferences'].map do |i|
|
39
|
+
i['tag']['name'] unless tags.include?(i['tag']['name'])
|
40
|
+
end.compact
|
41
|
+
self.create_vm_tags(id, subset)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
|
14
|
+
def describe_tags
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.body = @tags
|
17
|
+
response.status = 200
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class Real
|
24
|
+
def describe_tags
|
25
|
+
self.request(:account, :get_tags, :query => 'objectMask=mask[referenceCount]')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -11,8 +11,14 @@ module Fog
|
|
11
11
|
class Mock
|
12
12
|
def get_bare_metal_server(identifier)
|
13
13
|
response = Excon::Response.new
|
14
|
-
response.body = @bare_metal_servers.map {|vm| vm if vm['id'] == identifier}.compact.
|
15
|
-
response.status = 200
|
14
|
+
response.body = @bare_metal_servers.map {|vm| vm if vm['id'] == identifier.to_s }.compact.first || {}
|
15
|
+
response.status = response.body.empty? ? 404 : 200
|
16
|
+
if response.status == 404
|
17
|
+
response.body = {
|
18
|
+
"error"=>"Unable to find object with id of '#{identifier}'.",
|
19
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
20
|
+
}
|
21
|
+
end
|
16
22
|
response
|
17
23
|
end
|
18
24
|
|
@@ -20,7 +26,7 @@ module Fog
|
|
20
26
|
|
21
27
|
class Real
|
22
28
|
def get_bare_metal_server(identifier)
|
23
|
-
request(:hardware_server, identifier, :expected => [200, 404], :query => 'objectMask=mask[datacenter,memory,provisionDate,processorCoreAmount,hardDrives,datacenter,hourlyBillingFlag,operatingSystem.passwords.password]')
|
29
|
+
request(:hardware_server, identifier, :expected => [200, 404], :query => 'objectMask=mask[datacenter,tagReferences,memory,provisionDate,processorCoreAmount,hardDrives,datacenter,hourlyBillingFlag,operatingSystem.passwords.password]')
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
@@ -20,7 +20,7 @@ module Fog
|
|
20
20
|
|
21
21
|
class Real
|
22
22
|
def get_bare_metal_servers
|
23
|
-
request(:account, :get_hardware, :query => 'objectMask=mask[datacenter,memory,processorCoreAmount,hardDrives,datacenter,hourlyBillingFlag,operatingSystem.passwords.password]')
|
23
|
+
request(:account, :get_hardware, :query => 'objectMask=mask[datacenter,tagReferences,memory,processorCoreAmount,hardDrives,datacenter,hourlyBillingFlag,operatingSystem.passwords.password]')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
|
14
|
+
def get_bare_metal_tags(id)
|
15
|
+
response = Excon::Response.new
|
16
|
+
|
17
|
+
response.status = self.get_bare_metal_server(id).status
|
18
|
+
|
19
|
+
bmc = self.get_bare_metal_server(id).body
|
20
|
+
unless bmc['error']
|
21
|
+
tags = @tags.map do |tag|
|
22
|
+
tag if tag['resourceTableId'] == id
|
23
|
+
end.compact
|
24
|
+
end
|
25
|
+
|
26
|
+
bmc['tagReferences'] = tags
|
27
|
+
response.body = bmc
|
28
|
+
|
29
|
+
if response.status == 404
|
30
|
+
response.body = {
|
31
|
+
"error"=>"Unable to find object with id of '#{id}'.",
|
32
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
response
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Real
|
41
|
+
def get_bare_metal_tags(id)
|
42
|
+
self.request(:hardware_server, id, :query => 'objectMask=id;tagReferences')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
|
14
|
+
def get_references_by_tag_name(tag_list)
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = 200
|
17
|
+
|
18
|
+
response.body = tag_list.split(',').map do |tag|
|
19
|
+
refs = @tags.select { |ref| ref['tag']['name'] == tag }
|
20
|
+
unless refs.empty?
|
21
|
+
{
|
22
|
+
'accountId' => Fog::Softlayer.mock_account_id,
|
23
|
+
'id'=>Fog::Mock.random_numbers(7),
|
24
|
+
'internal' => 0,
|
25
|
+
'name' => tag,
|
26
|
+
'references' => refs
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end.compact
|
30
|
+
response
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Real
|
36
|
+
def get_references_by_tag_name(tag_list)
|
37
|
+
self.request(:tag, "get_tag_by_tag_name/#{tag_list}", :query => 'objectMask=references')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
|
14
|
+
def get_tag(id)
|
15
|
+
# TODO: Implement
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class Real
|
21
|
+
def get_tag(id)
|
22
|
+
self.request(:tag, "#{id}/get_object", :query => "objectMask=references;references.tagType")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -11,8 +11,14 @@ module Fog
|
|
11
11
|
class Mock
|
12
12
|
def get_vm(identifier)
|
13
13
|
response = Excon::Response.new
|
14
|
-
response.body = @virtual_guests.map {|vm| vm if vm['id'] == identifier}.compact.
|
15
|
-
response.status = 200
|
14
|
+
response.body = @virtual_guests.map {|vm| vm if vm['id'] == identifier.to_s }.compact.first || {}
|
15
|
+
response.status = response.body.empty? ? 404 : 200
|
16
|
+
if response.status == 404
|
17
|
+
response.body = {
|
18
|
+
"error"=>"Unable to find object with id of '#{identifier}'.",
|
19
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
20
|
+
}
|
21
|
+
end
|
16
22
|
response
|
17
23
|
end
|
18
24
|
|
@@ -20,7 +26,7 @@ module Fog
|
|
20
26
|
|
21
27
|
class Real
|
22
28
|
def get_vm(identifier)
|
23
|
-
request(:virtual_guest, identifier, :expected => [200, 404], :query => 'objectMask=mask[datacenter,blockDevices,blockDeviceTemplateGroup.globalIdentifier,operatingSystem.passwords.password]')
|
29
|
+
request(:virtual_guest, identifier, :expected => [200, 404], :query => 'objectMask=mask[datacenter,tagReferences,blockDevices,blockDeviceTemplateGroup.globalIdentifier,operatingSystem.passwords.password]')
|
24
30
|
end
|
25
31
|
end
|
26
32
|
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
|
+
|
8
|
+
module Fog
|
9
|
+
module Compute
|
10
|
+
class Softlayer
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
|
14
|
+
def get_vm_tags(id)
|
15
|
+
response = Excon::Response.new
|
16
|
+
|
17
|
+
response.status = self.get_vm(id).status
|
18
|
+
|
19
|
+
vm = self.get_vm(id).body
|
20
|
+
unless vm['error']
|
21
|
+
tags = @tags.map do |tag|
|
22
|
+
tag if tag['resourceTableId'] == id
|
23
|
+
end.compact
|
24
|
+
end
|
25
|
+
|
26
|
+
vm['tagReferences'] = tags
|
27
|
+
response.body = vm
|
28
|
+
|
29
|
+
if response.status == 404
|
30
|
+
response.body = {
|
31
|
+
"error"=>"Unable to find object with id of '#{id}'.",
|
32
|
+
"code"=>"SoftLayer_Exception_ObjectNotFound"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
response
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Real
|
41
|
+
def get_vm_tags(id)
|
42
|
+
self.request(:virtual_guest, id, :query => 'objectMask=mask[tagReferences]')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -20,7 +20,7 @@ module Fog
|
|
20
20
|
|
21
21
|
class Real
|
22
22
|
def get_vms
|
23
|
-
request(:account, :get_virtual_guests, :query => 'objectMask=mask[datacenter,blockDevices,blockDeviceTemplateGroup.globalIdentifier,operatingSystem.passwords.password]')
|
23
|
+
request(:account, :get_virtual_guests, :query => 'objectMask=mask[datacenter,tagReferences,blockDevices,blockDeviceTemplateGroup.globalIdentifier,operatingSystem.passwords.password]')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -72,6 +72,17 @@ class Softlayer
|
|
72
72
|
"globalIdentifier" => String
|
73
73
|
}
|
74
74
|
|
75
|
+
TAGS = {
|
76
|
+
'empRecordId'=>nil,
|
77
|
+
'id'=>String,
|
78
|
+
'resourceTableId'=>Integer,
|
79
|
+
'tagId'=> Fog::Nullable::String,
|
80
|
+
'tagTypeId'=>Fog::Nullable::Integer,
|
81
|
+
'usrRecordId'=>Fog::Nullable::Integer,
|
82
|
+
'tag'=>{'accountId'=>Integer, 'id'=>String, 'internal'=>Integer, 'name'=>String},
|
83
|
+
'tagType'=>{'description'=>String, 'keyName'=>String}
|
84
|
+
}
|
85
|
+
|
75
86
|
end
|
76
87
|
|
77
88
|
module VirtualGuest
|
@@ -95,6 +106,17 @@ class Softlayer
|
|
95
106
|
"globalIdentifier" => String
|
96
107
|
}
|
97
108
|
|
109
|
+
TAGS = {
|
110
|
+
'empRecordId'=>nil,
|
111
|
+
'id'=>String,
|
112
|
+
'resourceTableId'=>Integer,
|
113
|
+
'tagId'=> Fog::Nullable::String,
|
114
|
+
'tagTypeId'=>Fog::Nullable::Integer,
|
115
|
+
'usrRecordId'=>Fog::Nullable::Integer,
|
116
|
+
'tag'=>{'accountId'=>Integer, 'id'=>String, 'internal'=>Integer, 'name'=>String},
|
117
|
+
'tagType'=>{'description'=>String, 'keyName'=>String}
|
118
|
+
}
|
119
|
+
|
98
120
|
end
|
99
121
|
|
100
122
|
module Collected
|
@@ -0,0 +1,92 @@
|
|
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
|
+
|
8
|
+
Shindo.tests("Fog::Compute[:softlayer] | tag requests", ["softlayer"]) do
|
9
|
+
|
10
|
+
@sl_connection = Fog::Compute[:softlayer]
|
11
|
+
|
12
|
+
opts = { :flavor_id => 'm1.small', :os_code => 'UBUNTU_LATEST', :name => 'matt', :datacenter => 'dal05'}
|
13
|
+
@vm = @sl_connection.servers.create(opts)
|
14
|
+
|
15
|
+
opts[:bare_metal] = true
|
16
|
+
@bmc = @sl_connection.servers.create(opts)
|
17
|
+
|
18
|
+
test_tags = ['foo', 'bar', 'baz']
|
19
|
+
|
20
|
+
tests('success') do
|
21
|
+
|
22
|
+
tests("#create_vm_tags('#{@vm.id}', #{test_tags})") do
|
23
|
+
returns(true, "returns true") { @sl_connection.create_vm_tags(@vm.id, test_tags).body}
|
24
|
+
end
|
25
|
+
|
26
|
+
tests("#create_bare_metal_tags('#{@bmc.id}', #{test_tags})") do
|
27
|
+
returns(true, "returns true") { @sl_connection.create_bare_metal_tags(@bmc.id, test_tags).body }
|
28
|
+
end
|
29
|
+
|
30
|
+
tests("#get_vm_tags('#{@vm.id}')") do
|
31
|
+
data_matches_schema(Softlayer::Compute::Formats::VirtualGuest::TAGS, {:allow_extra_keys => true}) { @sl_connection.get_vm_tags(@vm.id).body['tagReferences'].first }
|
32
|
+
end
|
33
|
+
|
34
|
+
tests("#get_bare_metal_tags('#{@bmc.id}')") do
|
35
|
+
data_matches_schema(Softlayer::Compute::Formats::BareMetal::TAGS, {:allow_extra_keys => true}) { @sl_connection.get_bare_metal_tags(@bmc.id).body['tagReferences'].first }
|
36
|
+
end
|
37
|
+
|
38
|
+
tests("#delete_vm_tags('#{@vm.id}')") do
|
39
|
+
returns(3, "three tags for VM with id #{@vm.id}") { @sl_connection.get_vm_tags(@vm.id).body['tagReferences'].count }
|
40
|
+
returns(true, "returns true") { @sl_connection.delete_vm_tags(@vm.id, ['foo', 'bar']).body }
|
41
|
+
returns(1, "one tag remains for VM with id #{@vm.id}") { @sl_connection.get_vm_tags(@vm.id).body['tagReferences'].count }
|
42
|
+
end
|
43
|
+
|
44
|
+
tests("#delete_bare_metal_tags('#{@bmc.id}')") do
|
45
|
+
returns(3, "three tags for BM server with id #{@bmc.id}") { @sl_connection.get_bare_metal_tags(@bmc.id).body['tagReferences'].count }
|
46
|
+
returns(true, "returns true") { @sl_connection.delete_bare_metal_tags(@bmc.id, ['foo', 'bar']).body }
|
47
|
+
returns(1, "one tag remains for BM server with id #{@bmc.id}") { @sl_connection.get_bare_metal_tags(@bmc.id).body['tagReferences'].count }
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
tests('failure') do
|
53
|
+
|
54
|
+
tests("#create_vm_tags(123456789, #{test_tags})") do
|
55
|
+
returns(404, "server doesn't exist") { @sl_connection.create_vm_tags(123456789).status }
|
56
|
+
end
|
57
|
+
|
58
|
+
tests("#create_bare_metal_tags(123456789, #{test_tags})") do
|
59
|
+
returns(404, "server doesn't exist") { @sl_connection.create_bare_metal_tags(123456789).status }
|
60
|
+
end
|
61
|
+
|
62
|
+
tests("#get_vm_tags(123456789)") do
|
63
|
+
returns(404, "server doesn't exist") { @sl_connection.get_vm_tags(123456789).status }
|
64
|
+
end
|
65
|
+
|
66
|
+
tests("#get_bare_metal_tags(123456789)") do
|
67
|
+
returns(404, "server doesn't exist") { @sl_connection.get_bare_metal_tags(123456789).status }
|
68
|
+
end
|
69
|
+
|
70
|
+
tests("#delete_vm_tags(123456789, #{test_tags})") do
|
71
|
+
returns(404, "server doesn't exist") { @sl_connection.delete_vm_tags(123456789, test_tags).status }
|
72
|
+
end
|
73
|
+
|
74
|
+
tests("#delete_bare_metal_tags(123456789, #{test_tags})") do
|
75
|
+
returns(404, "server doesn't exist") { @sl_connection.delete_bare_metal_tags(123456789, test_tags).status }
|
76
|
+
end
|
77
|
+
|
78
|
+
tests("#delete_bare_metal_tags(123456789, #{test_tags})") do
|
79
|
+
returns(404, "server doesn't exist") { @sl_connection.delete_bare_metal_tags(123456789, test_tags).status }
|
80
|
+
end
|
81
|
+
|
82
|
+
tests("#create_vm_tags").raises(ArgumentError) do
|
83
|
+
@sl_connection.create_vm_tags(@vm.id, 'foo')
|
84
|
+
end
|
85
|
+
|
86
|
+
tests("#create_bare_metal_tags").raises(ArgumentError) do
|
87
|
+
@sl_connection.create_bare_metal_tags(@vm.id, 'foo')
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-softlayer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Eldridge
|
@@ -235,6 +235,7 @@ files:
|
|
235
235
|
- examples/compute.md
|
236
236
|
- examples/dns.md
|
237
237
|
- examples/storage.md
|
238
|
+
- examples/tags.md
|
238
239
|
- fog-softlayer.gemspec
|
239
240
|
- gemfiles/Gemfile-edge
|
240
241
|
- gemfiles/Gemfile-ruby-1.8.7
|
@@ -250,6 +251,8 @@ files:
|
|
250
251
|
- lib/fog/softlayer/models/compute/images.rb
|
251
252
|
- lib/fog/softlayer/models/compute/server.rb
|
252
253
|
- lib/fog/softlayer/models/compute/servers.rb
|
254
|
+
- lib/fog/softlayer/models/compute/tag.rb
|
255
|
+
- lib/fog/softlayer/models/compute/tags.rb
|
253
256
|
- lib/fog/softlayer/models/dns/domain.rb
|
254
257
|
- lib/fog/softlayer/models/dns/domains.rb
|
255
258
|
- lib/fog/softlayer/models/dns/record.rb
|
@@ -259,13 +262,22 @@ files:
|
|
259
262
|
- lib/fog/softlayer/models/storage/file.rb
|
260
263
|
- lib/fog/softlayer/models/storage/files.rb
|
261
264
|
- lib/fog/softlayer/requests/compute/create_bare_metal_server.rb
|
265
|
+
- lib/fog/softlayer/requests/compute/create_bare_metal_tags.rb
|
262
266
|
- lib/fog/softlayer/requests/compute/create_vm.rb
|
267
|
+
- lib/fog/softlayer/requests/compute/create_vm_tags.rb
|
263
268
|
- lib/fog/softlayer/requests/compute/create_vms.rb
|
264
269
|
- lib/fog/softlayer/requests/compute/delete_bare_metal_server.rb
|
270
|
+
- lib/fog/softlayer/requests/compute/delete_bare_metal_tags.rb
|
265
271
|
- lib/fog/softlayer/requests/compute/delete_vm.rb
|
272
|
+
- lib/fog/softlayer/requests/compute/delete_vm_tags.rb
|
273
|
+
- lib/fog/softlayer/requests/compute/describe_tags.rb
|
266
274
|
- lib/fog/softlayer/requests/compute/get_bare_metal_server.rb
|
267
275
|
- lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb
|
276
|
+
- lib/fog/softlayer/requests/compute/get_bare_metal_tags.rb
|
277
|
+
- lib/fog/softlayer/requests/compute/get_references_by_tag_name.rb
|
278
|
+
- lib/fog/softlayer/requests/compute/get_tag.rb
|
268
279
|
- lib/fog/softlayer/requests/compute/get_vm.rb
|
280
|
+
- lib/fog/softlayer/requests/compute/get_vm_tags.rb
|
269
281
|
- lib/fog/softlayer/requests/compute/get_vms.rb
|
270
282
|
- lib/fog/softlayer/requests/dns/create_domain.rb
|
271
283
|
- lib/fog/softlayer/requests/dns/create_record.rb
|
@@ -328,6 +340,7 @@ files:
|
|
328
340
|
- tests/softlayer/models/storage/directory_tests.rb
|
329
341
|
- tests/softlayer/models/storage/file_tests.rb
|
330
342
|
- tests/softlayer/requests/compute/bmc_tests.rb
|
343
|
+
- tests/softlayer/requests/compute/tag_tests.rb
|
331
344
|
- tests/softlayer/requests/compute/vm_tests.rb
|
332
345
|
- tests/softlayer/requests/storage/auth_tests.rb
|
333
346
|
- tests/softlayer/requests/storage/container_tests.rb
|