cloud-appliance-descriptor 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5facdfe4e4783893bbdb5a5bd0f5aaa1494f0324
|
4
|
+
data.tar.gz: 1c9c6d2f9fd9954614887b04e7e2d122915b62a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da92e5a2070789b82d74519ef66f3ee16648acfcf00e7f529b6aba476bac4275cda744fd8b7eeeb195b8437258dd1038e548a6108a727b85867985575affdbb
|
7
|
+
data.tar.gz: 53defb8255d554af9b00c2266ccf2072ed9e8652db630cb23281bbecb1bbcacadff9bc9e3991703d3ab9ac11dcf702156eb72dea1bad1791f1c97627318e3bc0
|
data/README.md
CHANGED
@@ -31,13 +31,14 @@ os = Cloud::Appliance::Descriptor::Os.new :distribution => 'Ubuntu', :version =>
|
|
31
31
|
disk = Cloud::Appliance::Descriptor::Disk.new :type => :os, :format => :raw
|
32
32
|
|
33
33
|
# Every attribute can be set either during object initialization
|
34
|
-
appliance = Cloud::Appliance::Descriptor::Appliance.new :action => :create, :title => 'Title', :version => '548242', :
|
34
|
+
appliance = Cloud::Appliance::Descriptor::Appliance.new :action => :create, :title => 'Title', :version => '548242', :os => os, :groups => ['GROUP1', 'GROUP2'], :attributes => { 'KEY' => 'VALUE' }
|
35
35
|
# or later via setter.
|
36
36
|
appliance.memory = 2048
|
37
37
|
|
38
|
-
# Disks and
|
38
|
+
# Disks, attributes and groups can be added and removed via their add and remove methods.
|
39
39
|
appliance.add_disk disk
|
40
|
-
appliance.
|
40
|
+
appliance.remove_attribute 'KEY'
|
41
|
+
appliance.remove_group 'GROUP1'
|
41
42
|
|
42
43
|
# Once populated, appliance can be rendered as JSON
|
43
44
|
json_output = appliance.to_json
|
@@ -6,15 +6,16 @@ module Cloud
|
|
6
6
|
class Appliance
|
7
7
|
include Tools::GeneralInit
|
8
8
|
|
9
|
-
attr_accessor :action, :title, :description, :version, :identifier, :memory, :cpu, :
|
9
|
+
attr_accessor :action, :title, :description, :version, :identifier, :memory, :cpu, :groups, :os, :disks, :attributes
|
10
10
|
|
11
11
|
def set_defaults
|
12
12
|
@description ||= ''
|
13
13
|
@memory ||= 1024
|
14
14
|
@cpu ||= 1
|
15
|
+
@groups ||= []
|
15
16
|
@os ||= Os.new
|
16
17
|
@disks ||= []
|
17
|
-
@
|
18
|
+
@attributes ||= {}
|
18
19
|
end
|
19
20
|
|
20
21
|
def to_json
|
@@ -64,20 +65,28 @@ module Cloud
|
|
64
65
|
nil
|
65
66
|
end
|
66
67
|
|
68
|
+
def add_group(group)
|
69
|
+
groups << group
|
70
|
+
end
|
71
|
+
|
67
72
|
def add_disk(disk)
|
68
73
|
disks << disk
|
69
74
|
end
|
70
75
|
|
71
|
-
def
|
72
|
-
|
76
|
+
def add_attribute(attribute)
|
77
|
+
attributes.merge! attribute
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_group(group)
|
81
|
+
groups.delete(group)
|
73
82
|
end
|
74
83
|
|
75
84
|
def remove_disk(disk)
|
76
85
|
disks.delete(disk)
|
77
86
|
end
|
78
87
|
|
79
|
-
def
|
80
|
-
|
88
|
+
def remove_attribute(key)
|
89
|
+
attributes.delete(key)
|
81
90
|
end
|
82
91
|
end
|
83
92
|
end
|
@@ -6,21 +6,21 @@ module Cloud
|
|
6
6
|
module Descriptor
|
7
7
|
describe Appliance do
|
8
8
|
subject { appliance }
|
9
|
+
let(:appliance) { Appliance.new }
|
9
10
|
|
10
11
|
describe '#new' do
|
11
12
|
context 'without arguments' do
|
12
|
-
let(:appliance) { Appliance.new }
|
13
|
-
|
14
13
|
it 'creates empty appliance instance with defaults' do
|
15
14
|
is_expected.to be_an_instance_of Appliance
|
16
|
-
expect(subject.instance_variables.size).to eq
|
15
|
+
expect(subject.instance_variables.size).to eq 7
|
17
16
|
expect(subject.description).to eq('')
|
18
17
|
expect(subject.memory).to eq(1024)
|
19
18
|
expect(subject.cpu).to eq(1)
|
19
|
+
expect(subject.groups).to eq([])
|
20
20
|
expect(subject.os.type).to eq(:linux)
|
21
21
|
expect(subject.os.arch).to eq(:x86_64)
|
22
22
|
expect(subject.disks).to eq([])
|
23
|
-
expect(subject.
|
23
|
+
expect(subject.attributes).to eq({})
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -29,19 +29,20 @@ module Cloud
|
|
29
29
|
|
30
30
|
it 'creates empty appliance instance with defaults' do
|
31
31
|
is_expected.to be_an_instance_of Appliance
|
32
|
-
expect(subject.instance_variables.size).to eq
|
32
|
+
expect(subject.instance_variables.size).to eq 7
|
33
33
|
expect(subject.description).to eq('')
|
34
34
|
expect(subject.memory).to eq(1024)
|
35
35
|
expect(subject.cpu).to eq(1)
|
36
|
+
expect(subject.groups).to eq([])
|
36
37
|
expect(subject.os.type).to eq(:linux)
|
37
38
|
expect(subject.os.arch).to eq(:x86_64)
|
38
39
|
expect(subject.disks).to eq([])
|
39
|
-
expect(subject.
|
40
|
+
expect(subject.attributes).to eq({})
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
context 'with arguments representing appliance variables' do
|
44
|
-
let(:appliance) { Appliance.new action: :create, title: 'Title', description: 'description', identifier: 'id', cpu: 5, memory: 2048, version: '548242',
|
45
|
+
let(:appliance) { Appliance.new action: :create, title: 'Title', description: 'description', identifier: 'id', cpu: 5, memory: 2048, version: '548242', groups: ['GROUP1', 'GROUP2'] }
|
45
46
|
|
46
47
|
it 'creates appliance instance and populete its instance variables' do
|
47
48
|
is_expected.to be_an_instance_of Appliance
|
@@ -52,12 +53,12 @@ module Cloud
|
|
52
53
|
expect(subject.os.type).to eq(:linux)
|
53
54
|
expect(subject.os.arch).to eq(:x86_64)
|
54
55
|
expect(subject.disks).to eq([])
|
55
|
-
expect(subject.
|
56
|
+
expect(subject.attributes).to eq({})
|
56
57
|
expect(subject.version).to eq('548242')
|
57
58
|
expect(subject.identifier).to eq('id')
|
58
59
|
expect(subject.title).to eq('Title')
|
59
60
|
expect(subject.action).to eq(:create)
|
60
|
-
expect(subject.
|
61
|
+
expect(subject.groups).to eq(['GROUP1', 'GROUP2'])
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
@@ -66,14 +67,15 @@ module Cloud
|
|
66
67
|
|
67
68
|
it 'creates empty appliance instance with defaults' do
|
68
69
|
is_expected.to be_an_instance_of Appliance
|
69
|
-
expect(subject.instance_variables.size).to eq
|
70
|
+
expect(subject.instance_variables.size).to eq 7
|
70
71
|
expect(subject.description).to eq('')
|
71
72
|
expect(subject.memory).to eq(1024)
|
72
73
|
expect(subject.cpu).to eq(1)
|
74
|
+
expect(subject.groups).to eq([])
|
73
75
|
expect(subject.os.type).to eq(:linux)
|
74
76
|
expect(subject.os.arch).to eq(:x86_64)
|
75
77
|
expect(subject.disks).to eq([])
|
76
|
-
expect(subject.
|
78
|
+
expect(subject.attributes).to eq({})
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -82,22 +84,43 @@ module Cloud
|
|
82
84
|
|
83
85
|
it 'creates appliance instance and populete its instance variables' do
|
84
86
|
is_expected.to be_an_instance_of Appliance
|
85
|
-
expect(subject.instance_variables.size).to eq
|
87
|
+
expect(subject.instance_variables.size).to eq 9
|
86
88
|
expect(subject.description).to eq('')
|
87
89
|
expect(subject.memory).to eq(1024)
|
88
90
|
expect(subject.cpu).to eq(5)
|
91
|
+
expect(subject.groups).to eq([])
|
89
92
|
expect(subject.os.type).to eq(:linux)
|
90
93
|
expect(subject.os.arch).to eq(:x86_64)
|
91
94
|
expect(subject.disks).to eq([])
|
92
|
-
expect(subject.
|
95
|
+
expect(subject.attributes).to eq({})
|
93
96
|
expect(subject.version).to eq('548242')
|
94
97
|
expect(subject.action).to eq(:create)
|
95
98
|
end
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
102
|
+
describe '.add_group' do
|
103
|
+
let(:group) { double('group') }
|
104
|
+
|
105
|
+
it 'adds group to groups array' do
|
106
|
+
expect(subject.groups).to be_empty
|
107
|
+
subject.add_group group
|
108
|
+
expect(subject.groups).to contain_exactly(group)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '.remove_group' do
|
113
|
+
let(:group) { double('group') }
|
114
|
+
let(:appliance) { Appliance.new groups: [group]}
|
115
|
+
|
116
|
+
it 'removes group from groups array' do
|
117
|
+
expect(subject.groups).to contain_exactly(group)
|
118
|
+
subject.remove_group group
|
119
|
+
expect(subject.groups).to be_empty
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
99
123
|
describe '.add_disk' do
|
100
|
-
let(:appliance) { Appliance.new }
|
101
124
|
let(:disk) { double('disk') }
|
102
125
|
|
103
126
|
it 'adds disk to disks array' do
|
@@ -118,25 +141,24 @@ module Cloud
|
|
118
141
|
end
|
119
142
|
end
|
120
143
|
|
121
|
-
describe '.
|
122
|
-
let(:appliance) { Appliance.new }
|
144
|
+
describe '.add_attribute' do
|
123
145
|
let(:attribute) { { :key => :value } }
|
124
146
|
|
125
|
-
it 'adds attribute to
|
126
|
-
expect(subject.
|
127
|
-
subject.
|
128
|
-
expect(subject.
|
147
|
+
it 'adds attribute to attributes hash' do
|
148
|
+
expect(subject.attributes).to be_empty
|
149
|
+
subject.add_attribute attribute
|
150
|
+
expect(subject.attributes).to eq(attribute)
|
129
151
|
end
|
130
152
|
end
|
131
153
|
|
132
|
-
describe '.
|
154
|
+
describe '.remove_attribute' do
|
133
155
|
let(:attribute) { { :key => :value } }
|
134
|
-
let(:appliance) { Appliance.new
|
156
|
+
let(:appliance) { Appliance.new attributes: attribute }
|
135
157
|
|
136
|
-
it 'removes attribute from
|
137
|
-
expect(subject.
|
138
|
-
subject.
|
139
|
-
expect(subject.
|
158
|
+
it 'removes attribute from attributes hash' do
|
159
|
+
expect(subject.attributes).to eq(attribute)
|
160
|
+
subject.remove_attribute :key
|
161
|
+
expect(subject.attributes).to be_empty
|
140
162
|
end
|
141
163
|
end
|
142
164
|
|
@@ -144,10 +166,10 @@ module Cloud
|
|
144
166
|
let(:os) { Os.new distribution: 'Ubuntu', version: '14.04'}
|
145
167
|
let(:disk1) { Disk.new type: :os, format: :raw }
|
146
168
|
let(:disk2) { Disk.new type: :data, format: :qcow2 }
|
147
|
-
let(:appliance) {Appliance.new action: :create, title: 'Title', version: '548242',
|
169
|
+
let(:appliance) {Appliance.new action: :create, title: 'Title', version: '548242', groups: ['GROUP1', 'GROUP2'], os: os, disks: [disk1, disk2], attributes: { "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" } }
|
148
170
|
let(:disks) { [{"type"=>"data", "format"=>"qcow2"}, {"type"=>"os", "format"=>"raw"}] }
|
149
171
|
|
150
|
-
let(:json) { {"create"=>{"title"=>"Title", "version"=>"548242", "
|
172
|
+
let(:json) { {"create"=>{"title"=>"Title", "version"=>"548242", "groups"=>["GROUP1","GROUP2"], "attributes"=>{"KEY1"=>"VALUE1", "KEY2"=>"VALUE2"}, "description"=>"", "memory"=>1024, "cpu"=>1, "os"=>{"distribution"=>"Ubuntu", "version"=>"14.04", "arch"=>"x86_64", "type"=>"linux"}, "disks"=>[]}} }
|
151
173
|
|
152
174
|
it 'converts appliance object into its JSON representation' do
|
153
175
|
hash = JSON.parse(subject.to_json)
|
@@ -159,18 +181,18 @@ module Cloud
|
|
159
181
|
end
|
160
182
|
|
161
183
|
describe '#from_json' do
|
162
|
-
let(:json) { "{\"create\":{\"title\":\"Title\",\"version\":\"548242\",\"
|
184
|
+
let(:json) { "{\"create\":{\"title\":\"Title\",\"version\":\"548242\",\"groups\":[\"GROUP1\",\"GROUP2\"],\"attributes\":{\"KEY1\":\"VALUE1\",\"KEY2\":\"VALUE2\"},\"description\":\"\",\"memory\":1024,\"cpu\":1,\"os\":{\"distribution\":\"Ubuntu\",\"version\":\"14.04\",\"arch\":\"x86_64\",\"type\":\"linux\"},\"disks\":[{\"type\":\"data\",\"format\":\"qcow2\"},{\"type\":\"os\",\"format\":\"raw\"}]}}" }
|
163
185
|
let(:appliance) { Appliance.from_json(json) }
|
164
186
|
|
165
187
|
it 'returns appliance object from its JSON representation' do
|
166
188
|
expect(subject.action).to eq('create')
|
167
189
|
expect(subject.title).to eq('Title')
|
168
190
|
expect(subject.version).to eq('548242')
|
169
|
-
expect(subject.
|
191
|
+
expect(subject.groups).to eq(['GROUP1', 'GROUP2'])
|
170
192
|
expect(subject.cpu).to eq(1)
|
171
193
|
expect(subject.memory).to eq(1024)
|
172
194
|
expect(subject.description).to eq('')
|
173
|
-
expect(subject.
|
195
|
+
expect(subject.attributes).to eq({ "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" })
|
174
196
|
expect(subject.os.distribution).to eq('Ubuntu')
|
175
197
|
expect(subject.os.version).to eq('14.04')
|
176
198
|
expect(subject.os.type).to eq('linux')
|
@@ -188,18 +210,18 @@ module Cloud
|
|
188
210
|
end
|
189
211
|
|
190
212
|
describe '#from_hash' do
|
191
|
-
let(:hash) { {"create"=>{"title"=>"Title", "version"=>"548242", "
|
213
|
+
let(:hash) { {"create"=>{"title"=>"Title", "version"=>"548242", "groups"=>["GROUP1","GROUP2"], "attributes"=>{"KEY1"=>"VALUE1", "KEY2"=>"VALUE2"}, "description"=>"", "memory"=>1024, "cpu"=>1, "os"=>{"distribution"=>"Ubuntu", "version"=>"14.04", "arch"=>"x86_64", "type"=>"linux"}, "disks"=>[{"type"=>"data", "format"=>"qcow2"}, {"type"=>"os", "format"=>"raw"}]}} }
|
192
214
|
let(:appliance) { Appliance.from_hash(hash) }
|
193
215
|
|
194
216
|
it 'returns appliance object from its hash representation' do
|
195
217
|
expect(subject.action).to eq('create')
|
196
218
|
expect(subject.title).to eq('Title')
|
197
219
|
expect(subject.version).to eq('548242')
|
198
|
-
expect(subject.
|
220
|
+
expect(subject.groups).to eq(['GROUP1','GROUP2'])
|
199
221
|
expect(subject.cpu).to eq(1)
|
200
222
|
expect(subject.memory).to eq(1024)
|
201
223
|
expect(subject.description).to eq('')
|
202
|
-
expect(subject.
|
224
|
+
expect(subject.attributes).to eq({ "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" })
|
203
225
|
expect(subject.os.distribution).to eq('Ubuntu')
|
204
226
|
expect(subject.os.version).to eq('14.04')
|
205
227
|
expect(subject.os.type).to eq('linux')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud-appliance-descriptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Kimle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|