deltacloud-client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +11 -7
- data/bin/deltacloudc +9 -6
- data/lib/deltacloud.rb +412 -322
- data/lib/documentation.rb +97 -0
- data/lib/plain_formatter.rb +86 -0
- data/specs/instances_spec.rb +14 -14
- data/specs/realms_spec.rb +0 -2
- data/specs/spec_helper.rb +2 -5
- data/specs/storage_volume_spec.rb +2 -2
- metadata +20 -18
- data/credentials.yml +0 -2
- data/lib/dcloud/base_model.rb +0 -80
- data/lib/dcloud/hardware_profile.rb +0 -124
- data/lib/dcloud/image.rb +0 -56
- data/lib/dcloud/instance.rb +0 -142
- data/lib/dcloud/realm.rb +0 -57
- data/lib/dcloud/state.rb +0 -30
- data/lib/dcloud/storage_snapshot.rb +0 -59
- data/lib/dcloud/storage_volume.rb +0 -63
- data/lib/dcloud/transition.rb +0 -35
@@ -1,124 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License as published by the Free Software Foundation; either
|
7
|
-
# version 2.1 of the License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
|
19
|
-
require 'dcloud/base_model'
|
20
|
-
|
21
|
-
module DCloud
|
22
|
-
class HardwareProfile < BaseModel
|
23
|
-
|
24
|
-
class Property
|
25
|
-
class Range
|
26
|
-
attr_reader :first, :last
|
27
|
-
def initialize(element)
|
28
|
-
if element
|
29
|
-
@first = element.attributes['first']
|
30
|
-
@last = element.attributes['last']
|
31
|
-
end
|
32
|
-
end
|
33
|
-
def present?
|
34
|
-
! @first.nil?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
class Enum
|
38
|
-
attr_reader :entries
|
39
|
-
def initialize(element)
|
40
|
-
@entries = []
|
41
|
-
if element
|
42
|
-
element.get_elements( 'entry' ).each do |entry|
|
43
|
-
@entries << entry.attributes['value']
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
def present?
|
48
|
-
! @entries.empty?
|
49
|
-
end
|
50
|
-
end
|
51
|
-
attr_reader :name, :kind, :unit, :value, :range, :enum
|
52
|
-
|
53
|
-
def initialize(xml, name)
|
54
|
-
@name = name
|
55
|
-
p = REXML::XPath.first(xml, "property[@name = '#{name}']")
|
56
|
-
if p
|
57
|
-
@value = p.attributes['value']
|
58
|
-
@unit = p.attributes['unit']
|
59
|
-
@kind = p.attributes['kind']
|
60
|
-
@range = Range.new(p.get_elements('range')[0]) if @kind=='range'
|
61
|
-
@enum = Enum.new(p.get_elements('enum')[0]) if @kind=='enum'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def present?
|
66
|
-
! @value.nil?
|
67
|
-
end
|
68
|
-
|
69
|
-
# FIXME: how to range/enum/kind bits fit into this?
|
70
|
-
def to_s
|
71
|
-
v = @value || "---"
|
72
|
-
u = @unit || ""
|
73
|
-
u = "" if ["label", "count"].include?(u)
|
74
|
-
"#{v} #{u}"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class FloatProperty < Property
|
79
|
-
def initialize(xml, name)
|
80
|
-
super(xml, name)
|
81
|
-
@value = @value.to_f if @value
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
class IntegerProperty < Property
|
86
|
-
def initialize(xml, name)
|
87
|
-
super(xml, name)
|
88
|
-
@value = @value.to_i if @value
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
xml_tag_name :hardware_profile
|
93
|
-
|
94
|
-
attribute :memory
|
95
|
-
attribute :storage
|
96
|
-
attribute :cpu
|
97
|
-
attribute :architecture
|
98
|
-
|
99
|
-
def initialize(client, uri, xml=nil)
|
100
|
-
super( client, uri, xml )
|
101
|
-
end
|
102
|
-
|
103
|
-
def load_payload(xml=nil)
|
104
|
-
super(xml)
|
105
|
-
unless xml.nil?
|
106
|
-
@memory = FloatProperty.new(xml, 'memory')
|
107
|
-
@storage = FloatProperty.new(xml, 'storage')
|
108
|
-
@cpu = IntegerProperty.new(xml, 'cpu')
|
109
|
-
@architecture = Property.new(xml, 'architecture')
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def to_plain
|
114
|
-
sprintf("%-15s | %-6s | %10s | %10s ", id[0, 15],
|
115
|
-
architecture.to_s[0,6], memory.to_s[0,10], storage.to_s[0,10])
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
def property_value(xml, name)
|
120
|
-
p = REXML::XPath.first(xml, "property[@name = '#{name}']")
|
121
|
-
p ? p.attributes['value'] : ""
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/lib/dcloud/image.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License as published by the Free Software Foundation; either
|
7
|
-
# version 2.1 of the License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
|
19
|
-
require 'dcloud/base_model'
|
20
|
-
|
21
|
-
module DCloud
|
22
|
-
class Image < BaseModel
|
23
|
-
|
24
|
-
xml_tag_name :image
|
25
|
-
|
26
|
-
attribute :description
|
27
|
-
attribute :owner_id
|
28
|
-
attribute :architecture
|
29
|
-
attribute :name
|
30
|
-
|
31
|
-
def initialize(client, uri, xml=nil)
|
32
|
-
super( client, uri, xml )
|
33
|
-
end
|
34
|
-
|
35
|
-
def load_payload(xml)
|
36
|
-
super( xml )
|
37
|
-
unless xml.nil?
|
38
|
-
@description = xml.text( 'description' )
|
39
|
-
@owner_id = xml.text( 'owner_id' )
|
40
|
-
@name = xml.text( 'name' )
|
41
|
-
@architecture = xml.text( 'architecture' )
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def to_plain
|
46
|
-
sprintf("%-10s | %-20s | %-6s | %-20s | %15s",
|
47
|
-
self.id[0,10],
|
48
|
-
self.name ? self.name[0, 20]: 'unknown',
|
49
|
-
self.architecture[0,6],
|
50
|
-
self.description[0,20],
|
51
|
-
self.owner_id[0,15]
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
data/lib/dcloud/instance.rb
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License as published by the Free Software Foundation; either
|
7
|
-
# version 2.1 of the License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
|
19
|
-
require 'dcloud/base_model'
|
20
|
-
|
21
|
-
module DCloud
|
22
|
-
|
23
|
-
class InstanceProfile
|
24
|
-
attr_reader :hardware_profile, :id
|
25
|
-
|
26
|
-
def initialize(client, xml)
|
27
|
-
@hardware_profile = HardwareProfile.new(client, xml.attributes['href'])
|
28
|
-
@properties = {}
|
29
|
-
@id = xml.text("id")
|
30
|
-
xml.get_elements('property').each do |prop|
|
31
|
-
@properties[prop.attributes['name'].to_sym] = {
|
32
|
-
:value => prop.attributes['value'],
|
33
|
-
:unit => prop.attributes['unit'],
|
34
|
-
:kind => prop.attributes['kind'].to_sym
|
35
|
-
}
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def [](prop)
|
40
|
-
p = @properties[prop]
|
41
|
-
p ? p[:value] : nil
|
42
|
-
end
|
43
|
-
|
44
|
-
def property(prop)
|
45
|
-
@properties[prop]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Instance < BaseModel
|
50
|
-
|
51
|
-
xml_tag_name :instance
|
52
|
-
|
53
|
-
attribute :name
|
54
|
-
attribute :owner_id
|
55
|
-
attribute :public_addresses
|
56
|
-
attribute :private_addresses
|
57
|
-
attribute :state
|
58
|
-
attribute :actions
|
59
|
-
attribute :image
|
60
|
-
attribute :realm
|
61
|
-
attribute :action_urls
|
62
|
-
attribute :instance_profile
|
63
|
-
|
64
|
-
def initialize(client, uri, xml=nil)
|
65
|
-
@action_urls = {}
|
66
|
-
super( client, uri, xml )
|
67
|
-
end
|
68
|
-
|
69
|
-
def to_plain
|
70
|
-
sprintf("%-15s | %-15s | %-15s | %10s | %32s | %32s",
|
71
|
-
self.id ? self.id[0,15] : '-',
|
72
|
-
self.name ? self.name[0,15] : 'unknown',
|
73
|
-
self.image.name ? self.image.name[0,15] : 'unknown',
|
74
|
-
self.state ? self.state.to_s[0,10] : 'unknown',
|
75
|
-
self.public_addresses.join(',')[0,32],
|
76
|
-
self.private_addresses.join(',')[0,32]
|
77
|
-
)
|
78
|
-
end
|
79
|
-
|
80
|
-
def start!()
|
81
|
-
url = action_urls['start']
|
82
|
-
throw Exception.new( "Unable to start" ) unless url
|
83
|
-
client.post_instance( url )
|
84
|
-
unload
|
85
|
-
end
|
86
|
-
|
87
|
-
def reboot!()
|
88
|
-
url = action_urls['reboot']
|
89
|
-
throw Exception.new( "Unable to reboot" ) unless url
|
90
|
-
client.post_instance( url )
|
91
|
-
unload
|
92
|
-
end
|
93
|
-
|
94
|
-
def stop!()
|
95
|
-
url = action_urls['stop']
|
96
|
-
throw Exception.new( "Unable to stop" ) unless url
|
97
|
-
client.post_instance( url )
|
98
|
-
unload
|
99
|
-
end
|
100
|
-
|
101
|
-
def destroy!()
|
102
|
-
url = action_urls['destroy']
|
103
|
-
throw Exception.new( "Unable to destroy" ) unless url
|
104
|
-
client.post_instance( url )
|
105
|
-
unload
|
106
|
-
end
|
107
|
-
|
108
|
-
def load_payload(xml=nil)
|
109
|
-
super(xml)
|
110
|
-
unless xml.nil?
|
111
|
-
@owner_id = xml.text('owner_id')
|
112
|
-
@name = xml.text('name')
|
113
|
-
@public_addresses = []
|
114
|
-
xml.get_elements( 'public-addresses/address' ).each do |address|
|
115
|
-
@public_addresses << address.text
|
116
|
-
end
|
117
|
-
@private_addresses = []
|
118
|
-
xml.get_elements( 'private-addresses/address' ).each do |address|
|
119
|
-
@private_addresses << address.text
|
120
|
-
end
|
121
|
-
image_uri = xml.get_elements( 'image' )[0].attributes['href']
|
122
|
-
@image = Image.new( @client, image_uri )
|
123
|
-
# Only use realms if they are there
|
124
|
-
if (!xml.get_elements( 'realm' ).empty?)
|
125
|
-
realm_uri = xml.get_elements( 'realm' )[0].attributes['href']
|
126
|
-
@realm = Realm.new( @client, realm_uri )
|
127
|
-
end
|
128
|
-
instance_profile = xml.get_elements( 'hardware-profile' ).first
|
129
|
-
@instance_profile = InstanceProfile.new( @client, instance_profile )
|
130
|
-
@state = xml.text( 'state' )
|
131
|
-
@actions = []
|
132
|
-
xml.get_elements( 'actions/link' ).each do |link|
|
133
|
-
action_name = link.attributes['rel']
|
134
|
-
if ( action_name )
|
135
|
-
@actions << link.attributes['rel']
|
136
|
-
@action_urls[ link.attributes['rel'] ] = link.attributes['href']
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
data/lib/dcloud/realm.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License as published by the Free Software Foundation; either
|
7
|
-
# version 2.1 of the License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
require 'dcloud/base_model'
|
19
|
-
|
20
|
-
module DCloud
|
21
|
-
class Realm < BaseModel
|
22
|
-
|
23
|
-
xml_tag_name :realm
|
24
|
-
|
25
|
-
attribute :name
|
26
|
-
attribute :state
|
27
|
-
attribute :limit
|
28
|
-
|
29
|
-
def initialize(client, uri, xml=nil)
|
30
|
-
super( client, uri, xml )
|
31
|
-
end
|
32
|
-
|
33
|
-
def load_payload(xml=nil)
|
34
|
-
super(xml)
|
35
|
-
unless xml.nil?
|
36
|
-
@name = xml.text( 'name' )
|
37
|
-
@state = xml.text( 'state' )
|
38
|
-
@limit = xml.text( 'limit' )
|
39
|
-
if ( @limit.nil? || @limit == '' )
|
40
|
-
@limit = :unlimited
|
41
|
-
else
|
42
|
-
@limit = @limit.to_f
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_plain
|
48
|
-
sprintf("%-10s | %-15s | %-5s | %10s GB",
|
49
|
-
self.id[0, 10],
|
50
|
-
self.name[0, 15],
|
51
|
-
self.state[0,5],
|
52
|
-
self.limit.to_s[0,10]
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
data/lib/dcloud/state.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License as published by the Free Software Foundation; either
|
7
|
-
# version 2.1 of the License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
module DCloud
|
19
|
-
class State
|
20
|
-
|
21
|
-
attr_accessor :name
|
22
|
-
attr_accessor :transitions
|
23
|
-
|
24
|
-
def initialize(name)
|
25
|
-
@name = name
|
26
|
-
@transitions = []
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License as published by the Free Software Foundation; either
|
7
|
-
# version 2.1 of the License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
|
19
|
-
require 'dcloud/base_model'
|
20
|
-
|
21
|
-
module DCloud
|
22
|
-
class StorageSnapshot < BaseModel
|
23
|
-
|
24
|
-
xml_tag_name :storage_snapshot
|
25
|
-
|
26
|
-
attribute :created
|
27
|
-
attribute :state
|
28
|
-
attribute :storage_volume
|
29
|
-
|
30
|
-
def to_plain
|
31
|
-
sprintf("%-10s | %-15s | %-6s | %15s",
|
32
|
-
self.id[0,10],
|
33
|
-
self.storage_volume.name ? self.storage_volume.name[0, 15] : 'unknown',
|
34
|
-
self.state ? self.state[0,6] : 'unknown',
|
35
|
-
self.created ? self.created[0,15] : 'unknown'
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
def initialize(client, uri, xml=nil)
|
40
|
-
super( client, uri, xml )
|
41
|
-
end
|
42
|
-
|
43
|
-
def load_payload(xml=nil)
|
44
|
-
super(xml)
|
45
|
-
unless xml.nil?
|
46
|
-
@created = xml.text( 'created' )
|
47
|
-
@state = xml.text( 'state' )
|
48
|
-
storage_volumes = xml.get_elements( 'storage-volume' )
|
49
|
-
if ( ! storage_volumes.empty? )
|
50
|
-
storage_volume = storage_volumes.first
|
51
|
-
storage_volume_href = storage_volume.attributes['href']
|
52
|
-
if ( storage_volume_href )
|
53
|
-
@storage_volume = StorageVolume.new( @client, storage_volume_href )
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|