deltacloud-client 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +502 -0
- data/Rakefile +39 -0
- data/credentials.yml +2 -0
- data/init.rb +19 -0
- data/lib/dcloud/base_model.rb +80 -0
- data/lib/dcloud/flavor.rb +43 -0
- data/lib/dcloud/image.rb +46 -0
- data/lib/dcloud/instance.rb +97 -0
- data/lib/dcloud/realm.rb +47 -0
- data/lib/dcloud/state.rb +30 -0
- data/lib/dcloud/storage_snapshot.rb +50 -0
- data/lib/dcloud/storage_volume.rb +53 -0
- data/lib/dcloud/transition.rb +35 -0
- data/lib/deltacloud.rb +356 -0
- data/specs/data/images/img1.yml +3 -0
- data/specs/data/images/img2.yml +3 -0
- data/specs/data/images/img3.yml +3 -0
- data/specs/data/instances/inst1.yml +8 -0
- data/specs/data/instances/inst2.yml +8 -0
- data/specs/data/storage_snapshots/snap1.yml +4 -0
- data/specs/data/storage_snapshots/snap2.yml +4 -0
- data/specs/data/storage_snapshots/snap3.yml +4 -0
- data/specs/data/storage_volumes/vol1.yml +6 -0
- data/specs/data/storage_volumes/vol2.yml +6 -0
- data/specs/data/storage_volumes/vol3.yml +6 -0
- data/specs/fixtures/images/img1.yml +3 -0
- data/specs/fixtures/images/img2.yml +3 -0
- data/specs/fixtures/images/img3.yml +3 -0
- data/specs/fixtures/instances/inst1.yml +8 -0
- data/specs/fixtures/instances/inst2.yml +8 -0
- data/specs/fixtures/storage_snapshots/snap1.yml +4 -0
- data/specs/fixtures/storage_snapshots/snap2.yml +4 -0
- data/specs/fixtures/storage_snapshots/snap3.yml +4 -0
- data/specs/fixtures/storage_volumes/vol1.yml +6 -0
- data/specs/fixtures/storage_volumes/vol2.yml +6 -0
- data/specs/fixtures/storage_volumes/vol3.yml +6 -0
- data/specs/flavors_spec.rb +67 -0
- data/specs/images_spec.rb +104 -0
- data/specs/initialization_spec.rb +59 -0
- data/specs/instance_states_spec.rb +77 -0
- data/specs/instances_spec.rb +171 -0
- data/specs/realms_spec.rb +65 -0
- data/specs/shared/resources.rb +29 -0
- data/specs/spec_helper.rb +54 -0
- data/specs/storage_snapshot_spec.rb +76 -0
- data/specs/storage_volume_spec.rb +86 -0
- metadata +108 -0
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
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 'spec/rake/spectask'
|
20
|
+
|
21
|
+
|
22
|
+
desc "Run all examples"
|
23
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
24
|
+
t.spec_files = FileList['specs/**/*_spec.rb']
|
25
|
+
t.spec_opts = [
|
26
|
+
'--format html:spec_report.html'
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Setup Fixtures"
|
31
|
+
task 'fixtures' do
|
32
|
+
FileUtils.rm_rf( File.dirname( __FILE__ ) + '/specs/data' )
|
33
|
+
FileUtils.cp_r( File.dirname( __FILE__ ) + '/specs/fixtures', File.dirname( __FILE__ ) + '/specs/data' )
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Clean Fixtures"
|
37
|
+
task 'fixtures:clean' do
|
38
|
+
FileUtils.rm_rf( File.dirname( __FILE__ ) + '/specs/data' )
|
39
|
+
end
|
data/credentials.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1,19 @@
|
|
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 'deltacloud'
|
@@ -0,0 +1,80 @@
|
|
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
|
+
module DCloud
|
20
|
+
class BaseModel
|
21
|
+
|
22
|
+
def self.xml_tag_name(name=nil)
|
23
|
+
unless ( name.nil? )
|
24
|
+
@xml_tag_name = name
|
25
|
+
end
|
26
|
+
@xml_tag_name || self.class.name.downcase.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def self.attribute(attr)
|
31
|
+
build_reader attr
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.build_reader(attr)
|
35
|
+
eval "
|
36
|
+
def #{attr}
|
37
|
+
check_load_payload
|
38
|
+
@#{attr}
|
39
|
+
end
|
40
|
+
"
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_reader :uri
|
44
|
+
|
45
|
+
def initialize(client, uri=nil, xml=nil)
|
46
|
+
@client = client
|
47
|
+
@uri = uri
|
48
|
+
@loaded = false
|
49
|
+
load_payload( xml )
|
50
|
+
end
|
51
|
+
|
52
|
+
def id()
|
53
|
+
check_load_payload
|
54
|
+
@id
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
attr_reader :client
|
61
|
+
|
62
|
+
def check_load_payload()
|
63
|
+
return if @loaded
|
64
|
+
xml = @client.fetch_resource( self.class.xml_tag_name.to_sym, @uri )
|
65
|
+
load_payload(xml)
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_payload(xml=nil)
|
69
|
+
unless ( xml.nil? )
|
70
|
+
@loaded = true
|
71
|
+
@id = xml.text( 'id' )
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def unload
|
76
|
+
@loaded = false
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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 Flavor < BaseModel
|
23
|
+
|
24
|
+
xml_tag_name :flavor
|
25
|
+
|
26
|
+
attribute :memory
|
27
|
+
attribute :storage
|
28
|
+
attribute :architecture
|
29
|
+
|
30
|
+
def initialize(client, uri, xml=nil)
|
31
|
+
super( client, uri, xml )
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_payload(xml=nil)
|
35
|
+
super(xml)
|
36
|
+
unless xml.nil?
|
37
|
+
@memory = xml.text( 'memory' ).to_f
|
38
|
+
@storage = xml.text( 'storage' ).to_f
|
39
|
+
@architecture = xml.text( 'architecture' )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/dcloud/image.rb
ADDED
@@ -0,0 +1,46 @@
|
|
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
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,97 @@
|
|
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 Instance < BaseModel
|
23
|
+
|
24
|
+
xml_tag_name :instance
|
25
|
+
|
26
|
+
attribute :name
|
27
|
+
attribute :owner_id
|
28
|
+
attribute :public_addresses
|
29
|
+
attribute :private_addresses
|
30
|
+
attribute :state
|
31
|
+
attribute :actions
|
32
|
+
attribute :image
|
33
|
+
attribute :flavor
|
34
|
+
attribute :realm
|
35
|
+
attribute :action_urls
|
36
|
+
|
37
|
+
def initialize(client, uri, xml=nil)
|
38
|
+
@action_urls = {}
|
39
|
+
super( client, uri, xml )
|
40
|
+
end
|
41
|
+
|
42
|
+
def start!()
|
43
|
+
url = action_urls['start']
|
44
|
+
throw Exception.new( "Unable to start" ) unless url
|
45
|
+
client.post_instance( url )
|
46
|
+
unload
|
47
|
+
end
|
48
|
+
|
49
|
+
def reboot!()
|
50
|
+
url = action_urls['reboot']
|
51
|
+
throw Exception.new( "Unable to reboot" ) unless url
|
52
|
+
client.post_instance( url )
|
53
|
+
unload
|
54
|
+
end
|
55
|
+
|
56
|
+
def stop!()
|
57
|
+
url = action_urls['stop']
|
58
|
+
throw Exception.new( "Unable to stop" ) unless url
|
59
|
+
client.post_instance( url )
|
60
|
+
unload
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_payload(xml=nil)
|
64
|
+
super(xml)
|
65
|
+
unless xml.nil?
|
66
|
+
@owner_id = xml.text('owner_id')
|
67
|
+
@name = xml.text('name')
|
68
|
+
@public_addresses = []
|
69
|
+
xml.get_elements( 'public-addresses/address' ).each do |address|
|
70
|
+
@public_addresses << address.text
|
71
|
+
end
|
72
|
+
@private_addresses = []
|
73
|
+
xml.get_elements( 'private-addresses/address' ).each do |address|
|
74
|
+
@private_addresses << address.text
|
75
|
+
end
|
76
|
+
image_uri = xml.get_elements( 'image' )[0].attributes['href']
|
77
|
+
@image = Image.new( @client, image_uri )
|
78
|
+
flavor_uri = xml.get_elements( 'flavor' )[0].attributes['href']
|
79
|
+
@flavor = Flavor.new( @client, flavor_uri )
|
80
|
+
# Only use realms if they are there
|
81
|
+
if (!xml.get_elements( 'realm' ).empty?)
|
82
|
+
realm_uri = xml.get_elements( 'realm' )[0].attributes['href']
|
83
|
+
@realm = Realm.new( @client, realm_uri )
|
84
|
+
end
|
85
|
+
@state = xml.text( 'state' )
|
86
|
+
@actions = []
|
87
|
+
xml.get_elements( 'actions/link' ).each do |link|
|
88
|
+
action_name = link.attributes['rel']
|
89
|
+
if ( action_name )
|
90
|
+
@actions << link.attributes['rel']
|
91
|
+
@action_urls[ link.attributes['rel'] ] = link.attributes['href']
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/dcloud/realm.rb
ADDED
@@ -0,0 +1,47 @@
|
|
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
|
+
end
|
47
|
+
end
|
data/lib/dcloud/state.rb
ADDED
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,50 @@
|
|
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 initialize(client, uri, xml=nil)
|
31
|
+
super( client, uri, xml )
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_payload(xml=nil)
|
35
|
+
super(xml)
|
36
|
+
unless xml.nil?
|
37
|
+
@created = xml.text( 'created' )
|
38
|
+
@state = xml.text( 'state' )
|
39
|
+
storage_volumes = xml.get_elements( 'storage-volume' )
|
40
|
+
if ( ! storage_volumes.empty? )
|
41
|
+
storage_volume = storage_volumes.first
|
42
|
+
storage_volume_href = storage_volume.attributes['href']
|
43
|
+
if ( storage_volume_href )
|
44
|
+
@storage_volume = StorageVolume.new( @client, storage_volume_href )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|