cloud-appliance-descriptor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 195b5494bb781706b771efa52bd25ffdf8b6e2b3
4
+ data.tar.gz: 9b505c6f163da727011961f97ebfa26999cbba8f
5
+ SHA512:
6
+ metadata.gz: eef7a92ef347ce0e5770ec14e29286e1786889e6b3e7f1b1246996ce1082b99292e8951aac7b3d7ed89bb7ea7bff269585f3502ed17084970247e0ecba1f98d5
7
+ data.tar.gz: 4d20bc4828b0722c4c80747d37e73197c8ae1abd30f261d84c54cf201c782ea0fd9a05a26466666fd54f365016ec42acf59568586fb8c35391c946e3f54089c8
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
11
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,46 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+ - 2.2.1
8
+ - ruby-head
9
+ - jruby-19mode
10
+ - jruby-head
11
+
12
+ jdk:
13
+ - openjdk7
14
+ - oraclejdk7
15
+ - openjdk6
16
+
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ exclude:
22
+ - rvm: 1.9.3
23
+ jdk: openjdk7
24
+ - rvm: 1.9.3
25
+ jdk: oraclejdk7
26
+ - rvm: 2.0.0
27
+ jdk: openjdk7
28
+ - rvm: 2.0.0
29
+ jdk: oraclejdk7
30
+ - rvm: 2.1
31
+ jdk: openjdk7
32
+ - rvm: 2.1
33
+ jdk: oraclejdk7
34
+ - rvm: 2.2.1
35
+ jdk: openjdk7
36
+ - rvm: 2.2.1
37
+ jdk: oraclejdk7
38
+ - rvm: ruby-head
39
+ jdk: openjdk7
40
+ - rvm: ruby-head
41
+ jdk: oraclejdk7
42
+ fast_finish: true
43
+
44
+ branches:
45
+ only:
46
+ - master
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michal Kimle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # CloudApplianceDescriptor
2
+
3
+ Helper gem to ease creation of cloud appliance descriptor.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/Misenko/cloud-appliance-descriptor.png)](http://travis-ci.org/Misenko/cloud-appliance-descriptor)
6
+ [![Dependency Status](https://gemnasium.com/Misenko/cloud-appliance-descriptor.png)](https://gemnasium.com/Misenko/cloud-appliance-descriptor)
7
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/cloud-appliance-descriptor.png)](https://badge.fury.io/rb/cloud-appliance-descriptor)
8
+ [![Code Climate](https://codeclimate.com/github/Misenko/cloud-appliance-descriptor.png)](https://codeclimate.com/github/Misenko/cloud-appliance-descriptor)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'cloud-appliance-descriptor'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install cloud-appliance-descriptor
25
+
26
+ ## Usage
27
+
28
+ Cloud appliance is basically a virtual machine with set of disks running an operating system.
29
+ ```ruby
30
+ os = Cloud::Appliance::Descriptor::Os.new :distribution => 'Ubuntu', :version => '14.04'
31
+ disk = Cloud::Appliance::Descriptor::Disk.new :type => :os, :format => :raw
32
+
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' }
35
+ # or later via setter.
36
+ appliance.memory = 2048
37
+
38
+ # Disks and meta attributes can be added and removed via their add and remove methods.
39
+ appliance.add_disk disk
40
+ appliance.remove_meta_attribute 'KEY'
41
+
42
+ # Once populated, appliance can be rendered as JSON
43
+ json_output = appliance.to_json
44
+
45
+ # Appliance can be also constructed from its JSON representation
46
+ appliance_from_json = Cloud::Appliance::Descriptor::Appliance.from_json(json_input)
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/Misenko/cloud-appliance-descriptor/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubygems/tasks'
3
+
4
+ task default: 'test'
5
+
6
+ desc 'Run all tests; includes rspec and coverage reports'
7
+ task test: 'rcov:rspec'
8
+
9
+ desc 'Run all tests; includes rspec and coverage reports'
10
+ task spec: 'test'
11
+
12
+ Gem::Tasks.new(build: { tar: true, zip: true }, sign: { checksum: true, pgp: false })
13
+
14
+ namespace :rcov do
15
+ require 'rspec/core/rake_task'
16
+
17
+ RSpec::Core::RakeTask.new(:rspec)
18
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cloud/appliance/descriptor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cloud-appliance-descriptor'
8
+ spec.version = Cloud::Appliance::Descriptor::VERSION
9
+ spec.authors = ['Michal Kimle']
10
+ spec.email = ['kimle.michal@gmail.com']
11
+
12
+ spec.summary = 'Helper gem to ease creation of cloud appliance descriptor.'
13
+ spec.description = 'Helper gem to ease creation of cloud appliance descriptor.'
14
+ spec.homepage = 'https://github.com/Misenko/cloud-appliance-descriptor/'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.9'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
24
+ spec.add_development_dependency 'simplecov', '~> 0.9.0'
25
+ spec.add_development_dependency 'rubygems-tasks', '~> 0.2.4'
26
+ spec.add_development_dependency 'rubocop', '~> 0.32'
27
+ end
@@ -0,0 +1,12 @@
1
+ require 'cloud/appliance/descriptor/tools'
2
+ require 'cloud/appliance/descriptor/version'
3
+ require 'cloud/appliance/descriptor/disk'
4
+ require 'cloud/appliance/descriptor/os'
5
+ require 'cloud/appliance/descriptor/appliance'
6
+
7
+ module Cloud
8
+ module Appliance
9
+ module Descriptor
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,85 @@
1
+ require 'json'
2
+
3
+ module Cloud
4
+ module Appliance
5
+ module Descriptor
6
+ class Appliance
7
+ include Tools::GeneralInit
8
+
9
+ attr_accessor :action, :title, :description, :version, :identifier, :memory, :cpu, :vo, :os, :disks, :meta_attributes
10
+
11
+ def set_defaults
12
+ @description ||= ''
13
+ @memory ||= 1024
14
+ @cpu ||= 1
15
+ @os ||= Os.new
16
+ @disks ||= []
17
+ @meta_attributes ||= {}
18
+ end
19
+
20
+ def to_json
21
+ variables = {}
22
+ except = [:@action, :@os, :@disks]
23
+ instance_variables.select { |element| !except.include?(element) }.each do |variable|
24
+ value = instance_variable_get variable
25
+ variables[variable.to_s[1..-1]] = value
26
+ end
27
+
28
+ variables['os'] = os.to_hash
29
+ variables['disks'] = disks.map{ |disk| disk.to_hash }
30
+
31
+ { action => variables }.to_json
32
+ end
33
+
34
+ def self.from_json(string)
35
+ raw = JSON.parse(string)
36
+ self.from_hash(raw)
37
+ end
38
+
39
+ def self.from_hash(hash)
40
+ hash.each do |key, value|
41
+ action = key
42
+ parameters = value
43
+ os = parameters.delete "os"
44
+ disks = parameters.delete "disks"
45
+ parameters[:action] = action
46
+
47
+ appliance = Appliance.new parameters
48
+
49
+ if os
50
+ os = Os.new os
51
+ appliance.os = os
52
+ end
53
+
54
+ if disks
55
+ disks.each do |disk|
56
+ disk = Disk.new disk
57
+ appliance.add_disk disk
58
+ end
59
+ end
60
+
61
+ return appliance
62
+ end
63
+
64
+ nil
65
+ end
66
+
67
+ def add_disk(disk)
68
+ disks << disk
69
+ end
70
+
71
+ def add_meta_attribute(attribute)
72
+ meta_attributes.merge! attribute
73
+ end
74
+
75
+ def remove_disk(disk)
76
+ disks.delete(disk)
77
+ end
78
+
79
+ def remove_meta_attribute(key)
80
+ meta_attributes.delete(key)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,12 @@
1
+ module Cloud
2
+ module Appliance
3
+ module Descriptor
4
+ class Disk
5
+ include Tools::GeneralInit
6
+ include Tools::GeneralToHash
7
+
8
+ attr_accessor :type, :format, :path, :device_prefix, :target
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Cloud
2
+ module Appliance
3
+ module Descriptor
4
+ class Os
5
+ include Tools::GeneralInit
6
+ include Tools::GeneralToHash
7
+
8
+ attr_accessor :arch, :type, :distribution, :version
9
+
10
+ def set_defaults
11
+ @arch ||= :x86_64
12
+ @type ||= :linux
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'cloud/appliance/descriptor/tools/general_init'
2
+ require 'cloud/appliance/descriptor/tools/general_to_hash'
3
+
4
+ module Cloud
5
+ module Appliance
6
+ module Descriptor
7
+ module Tools
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Cloud
2
+ module Appliance
3
+ module Descriptor
4
+ module Tools
5
+ module GeneralInit
6
+ def initialize(*h)
7
+ if h.length == 1 && h.first.is_a?(Hash)
8
+ h.first.each do |k, v|
9
+ send("#{k}=", v) if respond_to? k
10
+ end
11
+ end
12
+
13
+ set_defaults if respond_to? :set_defaults
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Cloud
2
+ module Appliance
3
+ module Descriptor
4
+ module Tools
5
+ module GeneralToHash
6
+ def to_hash
7
+ variables = {}
8
+ instance_variables.each do |variable|
9
+ value = instance_variable_get variable
10
+ variables[variable.to_s[1..-1]] = value
11
+ end
12
+
13
+ variables
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Cloud
2
+ module Appliance
3
+ module Descriptor
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,221 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ module Cloud
5
+ module Appliance
6
+ module Descriptor
7
+ describe Appliance do
8
+ subject { appliance }
9
+
10
+ describe '#new' do
11
+ context 'without arguments' do
12
+ let(:appliance) { Appliance.new }
13
+
14
+ it 'creates empty appliance instance with defaults' do
15
+ is_expected.to be_an_instance_of Appliance
16
+ expect(subject.instance_variables.size).to eq 6
17
+ expect(subject.description).to eq('')
18
+ expect(subject.memory).to eq(1024)
19
+ expect(subject.cpu).to eq(1)
20
+ expect(subject.os.type).to eq(:linux)
21
+ expect(subject.os.arch).to eq(:x86_64)
22
+ expect(subject.disks).to eq([])
23
+ expect(subject.meta_attributes).to eq({})
24
+ end
25
+ end
26
+
27
+ context 'with invalid arguments' do
28
+ let(:appliance) { Appliance.new('invalid_argument') }
29
+
30
+ it 'creates empty appliance instance with defaults' do
31
+ is_expected.to be_an_instance_of Appliance
32
+ expect(subject.instance_variables.size).to eq 6
33
+ expect(subject.description).to eq('')
34
+ expect(subject.memory).to eq(1024)
35
+ expect(subject.cpu).to eq(1)
36
+ expect(subject.os.type).to eq(:linux)
37
+ expect(subject.os.arch).to eq(:x86_64)
38
+ expect(subject.disks).to eq([])
39
+ expect(subject.meta_attributes).to eq({})
40
+ end
41
+ end
42
+
43
+ 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
+
46
+ it 'creates appliance instance and populete its instance variables' do
47
+ is_expected.to be_an_instance_of Appliance
48
+ expect(subject.instance_variables.size).to eq 11
49
+ expect(subject.description).to eq('description')
50
+ expect(subject.memory).to eq(2048)
51
+ expect(subject.cpu).to eq(5)
52
+ expect(subject.os.type).to eq(:linux)
53
+ expect(subject.os.arch).to eq(:x86_64)
54
+ expect(subject.disks).to eq([])
55
+ expect(subject.meta_attributes).to eq({})
56
+ expect(subject.version).to eq('548242')
57
+ expect(subject.identifier).to eq('id')
58
+ expect(subject.title).to eq('Title')
59
+ expect(subject.action).to eq(:create)
60
+ expect(subject.vo).to eq('VO')
61
+ end
62
+ end
63
+
64
+ context 'with arguments NOT representing appliance variables' do
65
+ let(:appliance) { Appliance.new param: 'value', param2: 42 }
66
+
67
+ it 'creates empty appliance instance with defaults' do
68
+ is_expected.to be_an_instance_of Appliance
69
+ expect(subject.instance_variables.size).to eq 6
70
+ expect(subject.description).to eq('')
71
+ expect(subject.memory).to eq(1024)
72
+ expect(subject.cpu).to eq(1)
73
+ expect(subject.os.type).to eq(:linux)
74
+ expect(subject.os.arch).to eq(:x86_64)
75
+ expect(subject.disks).to eq([])
76
+ expect(subject.meta_attributes).to eq({})
77
+ end
78
+ end
79
+
80
+ context 'with arguments both representing and NOT representing appliance variables' do
81
+ let(:appliance) { Appliance.new version: '548242', cpu: 5, action: :create, param: 'value' }
82
+
83
+ it 'creates appliance instance and populete its instance variables' do
84
+ is_expected.to be_an_instance_of Appliance
85
+ expect(subject.instance_variables.size).to eq 8
86
+ expect(subject.description).to eq('')
87
+ expect(subject.memory).to eq(1024)
88
+ expect(subject.cpu).to eq(5)
89
+ expect(subject.os.type).to eq(:linux)
90
+ expect(subject.os.arch).to eq(:x86_64)
91
+ expect(subject.disks).to eq([])
92
+ expect(subject.meta_attributes).to eq({})
93
+ expect(subject.version).to eq('548242')
94
+ expect(subject.action).to eq(:create)
95
+ end
96
+ end
97
+ end
98
+
99
+ describe '.add_disk' do
100
+ let(:appliance) { Appliance.new }
101
+ let(:disk) { double('disk') }
102
+
103
+ it 'adds disk to disks array' do
104
+ expect(subject.disks).to be_empty
105
+ subject.add_disk disk
106
+ expect(subject.disks).to contain_exactly(disk)
107
+ end
108
+ end
109
+
110
+ describe '.remove_disk' do
111
+ let(:disk) { double('disk') }
112
+ let(:appliance) { Appliance.new disks: [disk]}
113
+
114
+ it 'removes disk from disks array' do
115
+ expect(subject.disks).to contain_exactly(disk)
116
+ subject.remove_disk disk
117
+ expect(subject.disks).to be_empty
118
+ end
119
+ end
120
+
121
+ describe '.add_meta_attribute' do
122
+ let(:appliance) { Appliance.new }
123
+ let(:attribute) { { :key => :value } }
124
+
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)
129
+ end
130
+ end
131
+
132
+ describe '.remove_meta_attribute' do
133
+ let(:attribute) { { :key => :value } }
134
+ let(:appliance) { Appliance.new meta_attributes: attribute }
135
+
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
140
+ end
141
+ end
142
+
143
+ describe '.to_json' do
144
+ let(:os) { Os.new distribution: 'Ubuntu', version: '14.04'}
145
+ let(:disk1) { Disk.new type: :os, format: :raw }
146
+ 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" } }
148
+ let(:disks) { [{"type"=>"data", "format"=>"qcow2"}, {"type"=>"os", "format"=>"raw"}] }
149
+
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"=>[]}} }
151
+
152
+ it 'converts appliance object into its JSON representation' do
153
+ hash = JSON.parse(subject.to_json)
154
+ disks_array = hash['create']['disks']
155
+ hash['create']['disks'] = []
156
+ expect(hash).to eq(json)
157
+ expect(disks_array).to match_array(disks)
158
+ end
159
+ end
160
+
161
+ 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\"}]}}" }
163
+ let(:appliance) { Appliance.from_json(json) }
164
+
165
+ it 'returns appliance object from its JSON representation' do
166
+ expect(subject.action).to eq('create')
167
+ expect(subject.title).to eq('Title')
168
+ expect(subject.version).to eq('548242')
169
+ expect(subject.vo).to eq('VO')
170
+ expect(subject.cpu).to eq(1)
171
+ expect(subject.memory).to eq(1024)
172
+ expect(subject.description).to eq('')
173
+ expect(subject.meta_attributes).to eq({ "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" })
174
+ expect(subject.os.distribution).to eq('Ubuntu')
175
+ expect(subject.os.version).to eq('14.04')
176
+ expect(subject.os.type).to eq('linux')
177
+ expect(subject.os.arch).to eq('x86_64')
178
+ expect(subject.disks.size).to eq(2)
179
+
180
+ disks = subject.disks
181
+ disks.sort_by! { |disk| disk.type }
182
+
183
+ expect(disks[0].type).to eq('data')
184
+ expect(disks[0].format).to eq('qcow2')
185
+ expect(disks[1].type).to eq('os')
186
+ expect(disks[1].format).to eq('raw')
187
+ end
188
+ end
189
+
190
+ 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"}]}} }
192
+ let(:appliance) { Appliance.from_hash(hash) }
193
+
194
+ it 'returns appliance object from its hash representation' do
195
+ expect(subject.action).to eq('create')
196
+ expect(subject.title).to eq('Title')
197
+ expect(subject.version).to eq('548242')
198
+ expect(subject.vo).to eq('VO')
199
+ expect(subject.cpu).to eq(1)
200
+ expect(subject.memory).to eq(1024)
201
+ expect(subject.description).to eq('')
202
+ expect(subject.meta_attributes).to eq({ "KEY1"=>"VALUE1", "KEY2"=>"VALUE2" })
203
+ expect(subject.os.distribution).to eq('Ubuntu')
204
+ expect(subject.os.version).to eq('14.04')
205
+ expect(subject.os.type).to eq('linux')
206
+ expect(subject.os.arch).to eq('x86_64')
207
+ expect(subject.disks.size).to eq(2)
208
+
209
+ disks = subject.disks
210
+ disks.sort_by! { |disk| disk.type }
211
+
212
+ expect(disks[0].type).to eq('data')
213
+ expect(disks[0].format).to eq('qcow2')
214
+ expect(disks[1].type).to eq('os')
215
+ expect(disks[1].format).to eq('raw')
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ module Cloud
4
+ module Appliance
5
+ module Descriptor
6
+ describe Disk do
7
+ subject { disk }
8
+
9
+ describe '#new' do
10
+ context 'without arguments' do
11
+ let(:disk) { Disk.new }
12
+
13
+ it 'creates empty disk instance' do
14
+ is_expected.to be_an_instance_of Disk
15
+ expect(subject.instance_variables).to be_empty
16
+ end
17
+ end
18
+
19
+ context 'with invalid arguments' do
20
+ let(:disk) { Disk.new('invalid_argument') }
21
+
22
+ it 'creates empty disk instance' do
23
+ is_expected.to be_an_instance_of Disk
24
+ expect(subject.instance_variables).to be_empty
25
+ end
26
+ end
27
+
28
+ context 'with arguments representing disk variables' do
29
+ let(:disk) { Disk.new type: :os, format: :raw, path: '/path/to/image', device_prefix: 'vd', target: 'vda' }
30
+
31
+ it 'creates disk instance and populete its instance variables' do
32
+ is_expected.to be_an_instance_of Disk
33
+ expect(subject.instance_variables.size).to eq 5
34
+ expect(subject.type).to eq(:os)
35
+ expect(subject.format).to eq(:raw)
36
+ expect(subject.path).to eq('/path/to/image')
37
+ expect(subject.device_prefix).to eq('vd')
38
+ expect(subject.target).to eq('vda')
39
+ end
40
+ end
41
+
42
+ context 'with arguments NOT representing disk variables' do
43
+ let(:disk) { Disk.new param: 'value', param2: 42 }
44
+
45
+ it 'creates empty disk instance' do
46
+ is_expected.to be_an_instance_of Disk
47
+ expect(subject.instance_variables).to be_empty
48
+ end
49
+ end
50
+
51
+ context 'with arguments both representing and NOT representing disk variables' do
52
+ let(:disk) { Disk.new type: :os, format: :raw, param: 'value' }
53
+
54
+ it 'creates disk instance and populete its instance variables' do
55
+ is_expected.to be_an_instance_of Disk
56
+ expect(subject.instance_variables.size).to eq 2
57
+ expect(subject.type).to eq(:os)
58
+ expect(subject.format).to eq(:raw)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '.to_hash' do
64
+ let(:disk) { Disk.new type: :os, format: :raw, path: '/path/to/image' }
65
+
66
+ it 'returns hash representation of disk instance - instance variables as keys with their values' do
67
+ expect(subject.to_hash).to eq({"type" => :os, "format" => :raw,"path" => "/path/to/image"})
68
+ subject.target = 'vda'
69
+ expect(subject.to_hash).to eq({"type" => :os, "format" => :raw, "path" => "/path/to/image", "target" => "vda"})
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ module Cloud
4
+ module Appliance
5
+ module Descriptor
6
+ describe Os do
7
+ subject { os }
8
+
9
+ describe '#new' do
10
+ context 'without arguments' do
11
+ let(:os) { Os.new }
12
+
13
+ it 'creates empty os instance with defaults' do
14
+ is_expected.to be_an_instance_of Os
15
+ expect(subject.instance_variables.size).to eq 2
16
+ expect(subject.arch).to eq(:x86_64)
17
+ expect(subject.type).to eq(:linux)
18
+ end
19
+ end
20
+
21
+ context 'with invalid arguments' do
22
+ let(:os) { Os.new('invalid_argument') }
23
+
24
+ it 'creates empty os instance with defaults' do
25
+ is_expected.to be_an_instance_of Os
26
+ expect(subject.instance_variables.size).to eq 2
27
+ expect(subject.arch).to eq(:x86_64)
28
+ expect(subject.type).to eq(:linux)
29
+ end
30
+ end
31
+
32
+ context 'with arguments representing os variables' do
33
+ let(:os) { Os.new arch: :i686, type: :linux, distribution: 'Ubuntu', version: '14.04' }
34
+
35
+ it 'creates os instance and populete its instance variables' do
36
+ is_expected.to be_an_instance_of Os
37
+ expect(subject.instance_variables.size).to eq 4
38
+ expect(subject.arch).to eq(:i686)
39
+ expect(subject.type).to eq(:linux)
40
+ expect(subject.distribution).to eq('Ubuntu')
41
+ expect(subject.version).to eq('14.04')
42
+ end
43
+ end
44
+
45
+ context 'with arguments NOT representing os variables' do
46
+ let(:os) { Os.new param: 'value', param2: 42 }
47
+
48
+ it 'creates empty os instance with defaults' do
49
+ is_expected.to be_an_instance_of Os
50
+ expect(subject.instance_variables.size).to eq 2
51
+ expect(subject.arch).to eq(:x86_64)
52
+ expect(subject.type).to eq(:linux)
53
+ end
54
+ end
55
+
56
+ context 'with arguments both representing and NOT representing os variables' do
57
+ let(:os) { Os.new distribution: 'Ubuntu', param: 'value' }
58
+
59
+ it 'creates os instance and populete its instance variables' do
60
+ is_expected.to be_an_instance_of Os
61
+ expect(subject.instance_variables.size).to eq 3
62
+ expect(subject.distribution).to eq('Ubuntu')
63
+ expect(subject.arch).to eq(:x86_64)
64
+ expect(subject.type).to eq(:linux)
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '.to_hash' do
70
+ let(:os) { Os.new distribution: 'Ubuntu' }
71
+
72
+ it 'returns hash representation of os instance - instance variables as keys with their values' do
73
+ expect(subject.to_hash).to eq({"arch" => :x86_64, "type" => :linux, "distribution" => "Ubuntu"})
74
+ subject.version = '14.04'
75
+ expect(subject.to_hash).to eq({"arch" => :x86_64, "type" => :linux, "distribution" => "Ubuntu", "version" => "14.04"})
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '/vendor/'
5
+ end
6
+
7
+ require 'cloud-appliance-descriptor'
8
+
9
+ RSpec.configure do |config|
10
+ config.color = true
11
+ config.tty = true
12
+ config.order = 'random'
13
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud-appliance-descriptor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michal Kimle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubygems-tasks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.32'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.32'
97
+ description: Helper gem to ease creation of cloud appliance descriptor.
98
+ email:
99
+ - kimle.michal@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - cloud-appliance-descriptor.gemspec
113
+ - lib/cloud-appliance-descriptor.rb
114
+ - lib/cloud/appliance/descriptor/appliance.rb
115
+ - lib/cloud/appliance/descriptor/disk.rb
116
+ - lib/cloud/appliance/descriptor/os.rb
117
+ - lib/cloud/appliance/descriptor/tools.rb
118
+ - lib/cloud/appliance/descriptor/tools/general_init.rb
119
+ - lib/cloud/appliance/descriptor/tools/general_to_hash.rb
120
+ - lib/cloud/appliance/descriptor/version.rb
121
+ - spec/cloud/appliance/descriptor/appliance_spec.rb
122
+ - spec/cloud/appliance/descriptor/disk_spec.rb
123
+ - spec/cloud/appliance/descriptor/os_spec.rb
124
+ - spec/spec_helper.rb
125
+ homepage: https://github.com/Misenko/cloud-appliance-descriptor/
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.4.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Helper gem to ease creation of cloud appliance descriptor.
149
+ test_files:
150
+ - spec/cloud/appliance/descriptor/appliance_spec.rb
151
+ - spec/cloud/appliance/descriptor/disk_spec.rb
152
+ - spec/cloud/appliance/descriptor/os_spec.rb
153
+ - spec/spec_helper.rb