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: 195b5494bb781706b771efa52bd25ffdf8b6e2b3
4
- data.tar.gz: 9b505c6f163da727011961f97ebfa26999cbba8f
3
+ metadata.gz: 5facdfe4e4783893bbdb5a5bd0f5aaa1494f0324
4
+ data.tar.gz: 1c9c6d2f9fd9954614887b04e7e2d122915b62a8
5
5
  SHA512:
6
- metadata.gz: eef7a92ef347ce0e5770ec14e29286e1786889e6b3e7f1b1246996ce1082b99292e8951aac7b3d7ed89bb7ea7bff269585f3502ed17084970247e0ecba1f98d5
7
- data.tar.gz: 4d20bc4828b0722c4c80747d37e73197c8ae1abd30f261d84c54cf201c782ea0fd9a05a26466666fd54f365016ec42acf59568586fb8c35391c946e3f54089c8
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', :vo => 'VO', :os => os, :meta_attributes => { 'KEY' => 'VALUE' }
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 meta attributes can be added and removed via their add and remove methods.
38
+ # Disks, attributes and groups can be added and removed via their add and remove methods.
39
39
  appliance.add_disk disk
40
- appliance.remove_meta_attribute 'KEY'
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, :vo, :os, :disks, :meta_attributes
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
- @meta_attributes ||= {}
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 add_meta_attribute(attribute)
72
- meta_attributes.merge! attribute
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 remove_meta_attribute(key)
80
- meta_attributes.delete(key)
88
+ def remove_attribute(key)
89
+ attributes.delete(key)
81
90
  end
82
91
  end
83
92
  end
@@ -1,7 +1,7 @@
1
1
  module Cloud
2
2
  module Appliance
3
3
  module Descriptor
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
7
7
  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 6
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.meta_attributes).to eq({})
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 6
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.meta_attributes).to eq({})
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', vo: 'VO' }
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.meta_attributes).to eq({})
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.vo).to eq('VO')
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 6
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.meta_attributes).to eq({})
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 8
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.meta_attributes).to eq({})
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 '.add_meta_attribute' do
122
- let(:appliance) { Appliance.new }
144
+ describe '.add_attribute' do
123
145
  let(:attribute) { { :key => :value } }
124
146
 
125
- it 'adds attribute to meta_attributes hash' do
126
- expect(subject.meta_attributes).to be_empty
127
- subject.add_meta_attribute attribute
128
- expect(subject.meta_attributes).to eq(attribute)
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 '.remove_meta_attribute' do
154
+ describe '.remove_attribute' do
133
155
  let(:attribute) { { :key => :value } }
134
- let(:appliance) { Appliance.new meta_attributes: attribute }
156
+ let(:appliance) { Appliance.new attributes: attribute }
135
157
 
136
- it 'removes attribute from meta_attributes hash' do
137
- expect(subject.meta_attributes).to eq(attribute)
138
- subject.remove_meta_attribute :key
139
- expect(subject.meta_attributes).to be_empty
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', vo: 'VO', os: os, disks: [disk1, disk2], meta_attributes: { "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" } }
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", "vo"=>"VO", "meta_attributes"=>{"KEY1"=>"VALUE1", "KEY2"=>"VALUE2"}, "description"=>"", "memory"=>1024, "cpu"=>1, "os"=>{"distribution"=>"Ubuntu", "version"=>"14.04", "arch"=>"x86_64", "type"=>"linux"}, "disks"=>[]}} }
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\",\"vo\":\"VO\",\"meta_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\"}]}}" }
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.vo).to eq('VO')
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.meta_attributes).to eq({ "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" })
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", "vo"=>"VO", "meta_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"}]}} }
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.vo).to eq('VO')
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.meta_attributes).to eq({ "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" })
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.1.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-09-07 00:00:00.000000000 Z
11
+ date: 2015-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler