fog-opennebula 0.0.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 +7 -0
- data/.gitignore +32 -0
- data/CONTRIBUTORS.md +4 -0
- data/Gemfile +9 -0
- data/LICENSE.md +20 -0
- data/README.md +95 -0
- data/Rakefile +118 -0
- data/fog-opennebula.gemspec +35 -0
- data/lib/fog/bin/opennebula.rb +32 -0
- data/lib/fog/opennebula.rb +30 -0
- data/lib/fog/opennebula/compute.rb +136 -0
- data/lib/fog/opennebula/models/compute/flavor.rb +190 -0
- data/lib/fog/opennebula/models/compute/flavors.rb +46 -0
- data/lib/fog/opennebula/models/compute/group.rb +28 -0
- data/lib/fog/opennebula/models/compute/groups.rb +38 -0
- data/lib/fog/opennebula/models/compute/interface.rb +39 -0
- data/lib/fog/opennebula/models/compute/interfaces.rb +20 -0
- data/lib/fog/opennebula/models/compute/network.rb +48 -0
- data/lib/fog/opennebula/models/compute/networks.rb +42 -0
- data/lib/fog/opennebula/models/compute/server.rb +85 -0
- data/lib/fog/opennebula/models/compute/servers.rb +33 -0
- data/lib/fog/opennebula/requests/compute/OpenNebulaVNC.rb +314 -0
- data/lib/fog/opennebula/requests/compute/get_vnc_console.rb +58 -0
- data/lib/fog/opennebula/requests/compute/image_pool.rb +33 -0
- data/lib/fog/opennebula/requests/compute/list_groups.rb +87 -0
- data/lib/fog/opennebula/requests/compute/list_networks.rb +79 -0
- data/lib/fog/opennebula/requests/compute/list_vms.rb +79 -0
- data/lib/fog/opennebula/requests/compute/template_pool.rb +120 -0
- data/lib/fog/opennebula/requests/compute/vm_allocate.rb +97 -0
- data/lib/fog/opennebula/requests/compute/vm_destroy.rb +39 -0
- data/lib/fog/opennebula/requests/compute/vm_disk_snapshot.rb +33 -0
- data/lib/fog/opennebula/requests/compute/vm_resume.rb +35 -0
- data/lib/fog/opennebula/requests/compute/vm_shutdown.rb +22 -0
- data/lib/fog/opennebula/requests/compute/vm_stop.rb +21 -0
- data/lib/fog/opennebula/requests/compute/vm_suspend.rb +38 -0
- data/lib/fog/opennebula/version.rb +9 -0
- data/tests/opennebula/compute_tests.rb +15 -0
- data/tests/opennebula/models/compute/flavor_tests.rb +34 -0
- data/tests/opennebula/models/compute/flavors_tests.rb +15 -0
- data/tests/opennebula/models/compute/group_tests.rb +25 -0
- data/tests/opennebula/models/compute/groups_tests.rb +14 -0
- data/tests/opennebula/models/compute/network_tests.rb +24 -0
- data/tests/opennebula/models/compute/networks_tests.rb +14 -0
- data/tests/opennebula/requests/compute/vm_allocate_tests.rb +70 -0
- data/tests/opennebula/requests/compute/vm_disk_snapshot_test.rb +44 -0
- data/tests/opennebula/requests/compute/vm_suspend_resume_tests.rb +45 -0
- metadata +243 -0
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
|
5
|
+
module Compute
|
6
|
+
|
7
|
+
class OpenNebula
|
8
|
+
|
9
|
+
class Flavor < Fog::Model
|
10
|
+
|
11
|
+
identity :id
|
12
|
+
attribute :name
|
13
|
+
attribute :content
|
14
|
+
attribute :cpu
|
15
|
+
attribute :vcpu
|
16
|
+
attribute :memory
|
17
|
+
attribute :sched_requirements
|
18
|
+
attribute :sched_rank
|
19
|
+
attribute :sched_ds_requirements
|
20
|
+
attribute :sched_ds_rank
|
21
|
+
attribute :disk
|
22
|
+
attribute :nic
|
23
|
+
attribute :os
|
24
|
+
attribute :graphics
|
25
|
+
attribute :raw
|
26
|
+
attribute :context
|
27
|
+
attribute :user_variables
|
28
|
+
|
29
|
+
def to_label
|
30
|
+
"#{name} -- #{vcpu} VCPU - #{memory}MB Mem"
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
'' + get_cpu \
|
35
|
+
+ get_vcpu \
|
36
|
+
+ get_memory \
|
37
|
+
+ get_disk \
|
38
|
+
+ get_nic \
|
39
|
+
+ get_os \
|
40
|
+
+ get_graphics \
|
41
|
+
+ get_raw \
|
42
|
+
+ get_sched_requirements \
|
43
|
+
+ get_sched_ds_requirements \
|
44
|
+
+ get_sched_rank \
|
45
|
+
+ get_sched_ds_rank \
|
46
|
+
+ get_context \
|
47
|
+
+ get_user_variables
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_cpu
|
51
|
+
return "CPU=#{vcpu.to_f / 10}\n" unless cpu
|
52
|
+
return "CPU=#{vcpu}\n" if cpu.to_i > vcpu.to_i
|
53
|
+
|
54
|
+
"CPU=#{cpu}\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_vcpu
|
58
|
+
self.vcpu = 1 unless vcpu
|
59
|
+
"VCPU=#{vcpu}\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_memory
|
63
|
+
self.memory = 128 unless memory
|
64
|
+
"MEMORY=#{memory}\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_raw
|
68
|
+
return '' unless raw
|
69
|
+
|
70
|
+
ret = "RAW=#{raw}\n"
|
71
|
+
ret.tr!('{', '[')
|
72
|
+
ret.tr!('}', ']')
|
73
|
+
ret.tr!(/=>/, '=')
|
74
|
+
ret
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_disk
|
78
|
+
return '' unless disk
|
79
|
+
|
80
|
+
ret = ''
|
81
|
+
if disk.is_a? Array
|
82
|
+
disk.each do |d|
|
83
|
+
ret += "DISK=#{d}\n"
|
84
|
+
end
|
85
|
+
else
|
86
|
+
ret = "DISK=#{disk}\n"
|
87
|
+
end
|
88
|
+
ret.tr!('{', '[')
|
89
|
+
ret.tr!('}', ']')
|
90
|
+
ret.delete!('>')
|
91
|
+
ret
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_os
|
95
|
+
return '' unless os
|
96
|
+
|
97
|
+
ret = "OS=#{os}\n"
|
98
|
+
ret.tr!('{', '[')
|
99
|
+
ret.tr!('}', ']')
|
100
|
+
ret.delete!('>')
|
101
|
+
ret
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_graphics
|
105
|
+
return '' unless graphics
|
106
|
+
|
107
|
+
ret = "GRAPHICS=#{graphics}\n"
|
108
|
+
ret.tr!('{', '[')
|
109
|
+
ret.tr!('}', ']')
|
110
|
+
ret.delete!('>')
|
111
|
+
ret
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_nic
|
115
|
+
return '' if nic.nil?
|
116
|
+
|
117
|
+
ret = ''
|
118
|
+
if nic.is_a? Array
|
119
|
+
nic.each do |n|
|
120
|
+
ret += %(NIC=[MODEL="#{n.model}",NETWORK_ID="#{n.vnet.id}"]\n) unless n.vnet.nil?
|
121
|
+
end
|
122
|
+
end
|
123
|
+
# ret.gsub!(/\{/, '[')
|
124
|
+
# ret.gsub!(/\}/, ']')
|
125
|
+
# ret.gsub!(/>/,'')
|
126
|
+
ret
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_sched_ds_requirements
|
130
|
+
return '' unless sched_ds_requirements
|
131
|
+
|
132
|
+
%(SCHED_DS_REQUIREMENTS="#{sched_ds_requirements.gsub(/"/) { %q(\") }}"\n)
|
133
|
+
end
|
134
|
+
|
135
|
+
def get_sched_ds_rank
|
136
|
+
return '' unless sched_ds_rank
|
137
|
+
|
138
|
+
%(SCHED_DS_RANK="#{sched_ds_rank.gsub(/"/) { %q(\") }}"\n)
|
139
|
+
end
|
140
|
+
|
141
|
+
def get_sched_requirements
|
142
|
+
return '' unless sched_requirements
|
143
|
+
|
144
|
+
%(SCHED_REQUIREMENTS="#{sched_requirements.gsub(/"/) { %q(\") }}"\n)
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_sched_rank
|
148
|
+
return '' unless sched_rank
|
149
|
+
|
150
|
+
%(SCHED_RANK="#{sched_rank.gsub(/"/) { %q(\") }}"\n)
|
151
|
+
end
|
152
|
+
|
153
|
+
def get_context
|
154
|
+
return '' unless context
|
155
|
+
if context.is_a? String
|
156
|
+
return %(CONTEXT= [ #{context} ]\n)
|
157
|
+
elsif context.is_a? Hash
|
158
|
+
ret = ''
|
159
|
+
context.each do |key, value|
|
160
|
+
ret << %("#{key}"="#{value}",)
|
161
|
+
end
|
162
|
+
ret.chop! if ret.end_with?(',')
|
163
|
+
return %(CONTEXT=[ #{ret} ]\n)
|
164
|
+
else
|
165
|
+
return ''
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def get_user_variables
|
170
|
+
return '' unless user_variables
|
171
|
+
if user_variables.is_a? String
|
172
|
+
return %(#{user_variables}\n)
|
173
|
+
elsif user_variables.is_a? Hash
|
174
|
+
ret = ''
|
175
|
+
user_variables.each do |key, value|
|
176
|
+
ret << %(#{key}="#{value}"\n)
|
177
|
+
end
|
178
|
+
return ret
|
179
|
+
else
|
180
|
+
return ''
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/opennebula/models/compute/flavor'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
|
6
|
+
module Compute
|
7
|
+
|
8
|
+
class OpenNebula
|
9
|
+
|
10
|
+
class Flavors < Fog::Collection
|
11
|
+
|
12
|
+
model Fog::Compute::OpenNebula::Flavor
|
13
|
+
|
14
|
+
def all
|
15
|
+
data = service.template_pool
|
16
|
+
load(data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(flavor_id)
|
20
|
+
data = service.template_pool(:id => flavor_id)
|
21
|
+
load(data).first
|
22
|
+
rescue Fog::Compute::OpenNebula::NotFound
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_by_name(flavor_name)
|
27
|
+
data = service.template_pool(:name => flavor_name)
|
28
|
+
load(data)
|
29
|
+
rescue Fog::Compute::OpenNebula::NotFound
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_by_filter(flavor_filter)
|
34
|
+
data = service.template_pool(flavor_filter)
|
35
|
+
load(data)
|
36
|
+
rescue Fog::Compute::OpenNebula::NotFound
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
|
5
|
+
module Compute
|
6
|
+
|
7
|
+
class OpenNebula
|
8
|
+
|
9
|
+
class Group < Fog::Model
|
10
|
+
|
11
|
+
identity :id
|
12
|
+
attribute :name
|
13
|
+
|
14
|
+
def save
|
15
|
+
raise Fog::Errors::Error, 'Creating a new group is not yet implemented. Contributions welcome!'
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_label
|
19
|
+
name
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/opennebula/models/compute/group'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
|
6
|
+
module Compute
|
7
|
+
|
8
|
+
class OpenNebula
|
9
|
+
|
10
|
+
class Groups < Fog::Collection
|
11
|
+
|
12
|
+
model Fog::Compute::OpenNebula::Group
|
13
|
+
|
14
|
+
def all(filter = {})
|
15
|
+
load(service.list_groups(filter))
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(id)
|
19
|
+
group = all(:id => id)
|
20
|
+
|
21
|
+
if group.length > 1
|
22
|
+
raise Fog::Errors::Error, "groups.get should return only one group, not #{group.length}!"
|
23
|
+
end
|
24
|
+
|
25
|
+
group.first
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_by_name(str)
|
29
|
+
all(:name => str)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
|
5
|
+
module Compute
|
6
|
+
|
7
|
+
class OpenNebula
|
8
|
+
|
9
|
+
class Interface < Fog::Model
|
10
|
+
|
11
|
+
identity :id
|
12
|
+
attribute :vnet
|
13
|
+
attribute :model
|
14
|
+
attribute :name
|
15
|
+
attribute :mac
|
16
|
+
|
17
|
+
def save
|
18
|
+
raise Fog::Errors::Error, 'Creating a new interface is not yet implemented. Contributions welcome!'
|
19
|
+
end
|
20
|
+
|
21
|
+
def vnetid
|
22
|
+
vnet
|
23
|
+
end
|
24
|
+
|
25
|
+
def persisted?
|
26
|
+
mac
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy
|
30
|
+
raise Fog::Errors::Error, 'Destroying an interface is not yet implemented. Contributions welcome!'
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/opennebula/models/compute/interface'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
|
6
|
+
module Compute
|
7
|
+
|
8
|
+
class OpenNebula
|
9
|
+
|
10
|
+
class Interfaces < Fog::Collection
|
11
|
+
|
12
|
+
model Fog::Compute::OpenNebula::Interface
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
|
5
|
+
module Compute
|
6
|
+
|
7
|
+
class OpenNebula
|
8
|
+
|
9
|
+
class Network < Fog::Model
|
10
|
+
|
11
|
+
identity :id
|
12
|
+
attribute :name
|
13
|
+
attribute :uname
|
14
|
+
attribute :uid
|
15
|
+
attribute :gid
|
16
|
+
attribute :description
|
17
|
+
attribute :vlan
|
18
|
+
|
19
|
+
def description
|
20
|
+
attributes[:description] || ''
|
21
|
+
end
|
22
|
+
|
23
|
+
def vlan
|
24
|
+
attributes[:vlan] || ''
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
raise Fog::Errors::Error, 'Creating a new network is not yet implemented. Contributions welcome!'
|
29
|
+
end
|
30
|
+
|
31
|
+
def shutdown
|
32
|
+
raise Fog::Errors::Error, 'Shutting down a new network is not yet implemented. Contributions welcome!'
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_label
|
36
|
+
ret = ''
|
37
|
+
ret += "#{description} - " unless description.empty?
|
38
|
+
ret += "VLAN #{vlan} - " unless vlan.empty?
|
39
|
+
ret += name.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/opennebula/models/compute/network'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
|
6
|
+
module Compute
|
7
|
+
|
8
|
+
class OpenNebula
|
9
|
+
|
10
|
+
class Networks < Fog::Collection
|
11
|
+
|
12
|
+
model Fog::Compute::OpenNebula::Network
|
13
|
+
|
14
|
+
def all(filter = {})
|
15
|
+
get_by_filter(filter)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(id)
|
19
|
+
data = service.list_networks(:id => id)
|
20
|
+
load(data).first
|
21
|
+
rescue Fog::Compute::OpenNebula::NotFound
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_by_name(network)
|
26
|
+
data = service.list_networks(:network => network)
|
27
|
+
load(data).first
|
28
|
+
rescue Fog::Compute::OpenNebula::NotFound
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_by_filter(filter)
|
33
|
+
load(service.list_networks(filter))
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|