bbrowning-deltacloud-client 0.0.9.7-java
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +176 -0
- data/Rakefile +61 -0
- data/bin/deltacloudc +158 -0
- data/init.rb +20 -0
- data/lib/deltacloud.rb +572 -0
- data/lib/documentation.rb +98 -0
- data/lib/plain_formatter.rb +86 -0
- data/specs/fixtures/images/img1.yml +4 -0
- data/specs/fixtures/images/img2.yml +4 -0
- data/specs/fixtures/images/img3.yml +4 -0
- data/specs/fixtures/instances/inst0.yml +16 -0
- data/specs/fixtures/instances/inst1.yml +9 -0
- data/specs/fixtures/instances/inst2.yml +9 -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/hardware_profiles_spec.rb +78 -0
- data/specs/images_spec.rb +105 -0
- data/specs/initialization_spec.rb +60 -0
- data/specs/instance_states_spec.rb +78 -0
- data/specs/instances_spec.rb +191 -0
- data/specs/realms_spec.rb +64 -0
- data/specs/shared/resources.rb +30 -0
- data/specs/spec_helper.rb +52 -0
- data/specs/storage_snapshot_spec.rb +77 -0
- data/specs/storage_volume_spec.rb +89 -0
- metadata +166 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'lib/deltacloud'
|
2
|
+
|
3
|
+
skip_methods = [ "id=", "uri=" ]
|
4
|
+
|
5
|
+
begin
|
6
|
+
@dc=DeltaCloud.new('mockuser', 'mockpassword', 'http://localhost:3001/api')
|
7
|
+
rescue
|
8
|
+
puts "Please make sure that Deltacloud API is running with Mock driver"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
@dc.entry_points.keys.each do |ep|
|
13
|
+
@dc.send(ep)
|
14
|
+
end
|
15
|
+
|
16
|
+
class_list = DeltaCloud::classes.collect { |c| DeltaCloud::module_eval("::DeltaCloud::API::#{c}")}
|
17
|
+
|
18
|
+
def read_method_description(c, method)
|
19
|
+
if method =~ /es$/
|
20
|
+
" # Read #{c.downcase} collection from Deltacloud API"
|
21
|
+
else
|
22
|
+
case method
|
23
|
+
when "uri"
|
24
|
+
" # Return URI to API for this object"
|
25
|
+
when "action_urls"
|
26
|
+
" # Return available actions API URL"
|
27
|
+
when "client"
|
28
|
+
" # Return instance of API client"
|
29
|
+
else
|
30
|
+
" # Get #{method} attribute value from #{c.downcase}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def read_parameters(c, method)
|
36
|
+
out = []
|
37
|
+
if method =~ /es$/
|
38
|
+
out << " # @param [String, #id] Filter by ID"
|
39
|
+
end
|
40
|
+
out.join("\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_return_value(c, method)
|
44
|
+
if method =~ /es$/
|
45
|
+
rt = "Array"
|
46
|
+
else
|
47
|
+
rt = "String"
|
48
|
+
end
|
49
|
+
" # @return [String] Value of #{method}"
|
50
|
+
end
|
51
|
+
|
52
|
+
out = []
|
53
|
+
|
54
|
+
class_list.each do |c|
|
55
|
+
class_name = "#{c}".gsub(/^DeltaCloud::/, '')
|
56
|
+
out << "module DeltaCloud"
|
57
|
+
out << " class API"
|
58
|
+
@dc.entry_points.keys.each do |ep|
|
59
|
+
out << "# Return #{ep.to_s.classify} object with given id\n"
|
60
|
+
out << "# "
|
61
|
+
out << "# #{@dc.documentation(ep.to_s).description.split("\n").join("\n# ")}"
|
62
|
+
out << "# @return [#{ep.to_s.classify}]"
|
63
|
+
out << "def #{ep.to_s.gsub(/s$/, '')}"
|
64
|
+
out << "end"
|
65
|
+
out << "# Return collection of #{ep.to_s.classify} objects"
|
66
|
+
out << "# "
|
67
|
+
out << "# #{@dc.documentation(ep.to_s).description.split("\n").join("\n# ")}"
|
68
|
+
@dc.documentation(ep.to_s, 'index').params.each do |p|
|
69
|
+
out << p.to_comment
|
70
|
+
end
|
71
|
+
out << "# @return [Array] [#{ep.to_s.classify}]"
|
72
|
+
out << "def #{ep}(opts={})"
|
73
|
+
out << "end"
|
74
|
+
end
|
75
|
+
out << " end"
|
76
|
+
out << " class #{class_name}"
|
77
|
+
c.instance_methods(false).each do |method|
|
78
|
+
next if skip_methods.include?(method)
|
79
|
+
params = read_parameters(class_name, method)
|
80
|
+
retval = read_return_value(class_name, method)
|
81
|
+
out << read_method_description(class_name, method)
|
82
|
+
out << params if params
|
83
|
+
out << retval if retval
|
84
|
+
out << " def #{method}"
|
85
|
+
out << " # This method was generated dynamically from API"
|
86
|
+
out << " end\n"
|
87
|
+
end
|
88
|
+
out << " end"
|
89
|
+
out << "end"
|
90
|
+
end
|
91
|
+
|
92
|
+
FileUtils.rm_r('doc') rescue nil
|
93
|
+
FileUtils.mkdir_p('doc')
|
94
|
+
File.open('doc/deltacloud.rb', 'w') do |f|
|
95
|
+
f.puts(out.join("\n"))
|
96
|
+
end
|
97
|
+
system("yardoc -m markdown --readme README --title 'Deltacloud Client Library' 'lib/*.rb' 'doc/deltacloud.rb' --verbose")
|
98
|
+
FileUtils.rm('doc/deltacloud.rb')
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module DeltaCloud
|
2
|
+
module PlainFormatter
|
3
|
+
module FormatObject
|
4
|
+
|
5
|
+
class Base
|
6
|
+
def initialize(obj)
|
7
|
+
@obj = obj
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Image < Base
|
12
|
+
def format
|
13
|
+
sprintf("%-10s | %-20s | %-6s | %-20s | %15s",
|
14
|
+
@obj.id[0,10],
|
15
|
+
@obj.name ? @obj.name[0, 20]: 'unknown',
|
16
|
+
@obj.architecture[0,6],
|
17
|
+
@obj.description[0,20],
|
18
|
+
@obj.owner_id[0,15]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Realm < Base
|
24
|
+
def format
|
25
|
+
sprintf("%-10s | %-15s | %-5s | %10s GB",
|
26
|
+
@obj.id[0, 10],
|
27
|
+
@obj.name[0, 15],
|
28
|
+
@obj.state[0,5],
|
29
|
+
@obj.limit.to_s[0,10]
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class HardwareProfile < Base
|
35
|
+
def format
|
36
|
+
sprintf("%-15s | %-6s | %10s | %10s ", @obj.id[0, 15],
|
37
|
+
@obj.architecture.value[0,6], @obj.memory.value.to_s[0,10], @obj.storage.value.to_s[0,10])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Instance < Base
|
42
|
+
def format
|
43
|
+
sprintf("%-15s | %-15s | %-15s | %10s | %32s | %32s",
|
44
|
+
@obj.id ? @obj.id[0,15] : '-',
|
45
|
+
@obj.name ? @obj.name[0,15] : 'unknown',
|
46
|
+
@obj.image.name ? @obj.image.name[0,15] : 'unknown',
|
47
|
+
@obj.state ? @obj.state.to_s[0,10] : 'unknown',
|
48
|
+
@obj.public_addresses.join(',')[0,32],
|
49
|
+
@obj.private_addresses.join(',')[0,32]
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class StorageVolume < Base
|
55
|
+
def format
|
56
|
+
sprintf("%-10s | %15s GB | %-10s | %-10s | %-15s",
|
57
|
+
@obj.id[0,10],
|
58
|
+
@obj.capacity ? @obj.capacity.to_s[0,15] : 'unknown',
|
59
|
+
@obj.device ? @obj.device[0,10] : 'unknown',
|
60
|
+
@obj.respond_to?('state') ? @obj.state[0,10] : 'unknown',
|
61
|
+
@obj.instance ? @obj.instance.name[0,15] : 'unknown'
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class StorageSnapshot < Base
|
67
|
+
def format
|
68
|
+
sprintf("%-10s | %-15s | %-6s | %15s",
|
69
|
+
@obj.id[0,10],
|
70
|
+
@obj.storage_volume.respond_to?('name') ? @obj.storage_volume.name[0, 15] : 'unknown',
|
71
|
+
@obj.state ? @obj.state[0,10] : 'unknown',
|
72
|
+
@obj.created ? @obj.created[0,19] : 'unknown'
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def format(obj)
|
80
|
+
object_name = obj.class.name.classify.gsub(/^DeltaCloud::API::/, '')
|
81
|
+
format_class = DeltaCloud::PlainFormatter::FormatObject.const_get(object_name)
|
82
|
+
format_class.new(obj).format
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
:realm_id: us
|
3
|
+
:public_addresses:
|
4
|
+
- img1.inst0.public.com
|
5
|
+
:state: RUNNING
|
6
|
+
:name: "Mock Instance With Profile Change"
|
7
|
+
:private_addresses:
|
8
|
+
- img1.inst0.private.com
|
9
|
+
:image_id: img1
|
10
|
+
:instance_profile: !ruby/object:InstanceProfile
|
11
|
+
id: m1-large
|
12
|
+
memory: "12288"
|
13
|
+
:owner_id: mockuser
|
14
|
+
:actions:
|
15
|
+
- :reboot
|
16
|
+
- :stop
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
9
|
+
# License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
16
|
+
# License for the specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
19
|
+
|
20
|
+
require 'specs/spec_helper'
|
21
|
+
|
22
|
+
def prop_check(prop, value_class)
|
23
|
+
if prop.present?
|
24
|
+
prop.value.should_not be_nil
|
25
|
+
prop.value.should be_a(value_class)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "hardware_profiles" do
|
30
|
+
|
31
|
+
it_should_behave_like "all resources"
|
32
|
+
|
33
|
+
it "should allow retrieval of all hardware profiles" do
|
34
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
35
|
+
hardware_profiles = client.hardware_profiles
|
36
|
+
hardware_profiles.should_not be_empty
|
37
|
+
hardware_profiles.each do |hwp|
|
38
|
+
hwp.uri.should_not be_nil
|
39
|
+
hwp.uri.should be_a(String)
|
40
|
+
prop_check(hwp.architecture, String) if hwp.architecture
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow filtering of hardware_profiles by architecture" do
|
46
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
47
|
+
hardware_profiles = client.hardware_profiles( :architecture=>'i386' )
|
48
|
+
hardware_profiles.should_not be_empty
|
49
|
+
hardware_profiles.size.should eql( 2 )
|
50
|
+
hardware_profiles.first.architecture.value.should eql( 'i386' )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow fetching a hardware_profile by id" do
|
55
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
56
|
+
hwp = client.hardware_profile( 'm1-small' )
|
57
|
+
hwp.should_not be_nil
|
58
|
+
hwp.id.should eql( 'm1-small' )
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should allow fetching different hardware_profiles" do
|
63
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
64
|
+
hwp1 = client.hardware_profile( 'm1-small' )
|
65
|
+
hwp2 = client.hardware_profile( 'm1-xlarge' )
|
66
|
+
hwp1.storage.value.should_not eql(hwp2.storage.value)
|
67
|
+
hwp1.memory.value.should_not eql(hwp2.memory.value)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should allow fetching a hardware_profile by URI" do
|
71
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
72
|
+
hwp = client.fetch_hardware_profile( API_URL + '/hardware_profiles/m1-small' )
|
73
|
+
hwp.should_not be_nil
|
74
|
+
hwp.id.should eql( 'm1-small' )
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
9
|
+
# License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
16
|
+
# License for the specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
19
|
+
|
20
|
+
require 'specs/spec_helper'
|
21
|
+
|
22
|
+
describe "images" do
|
23
|
+
|
24
|
+
it_should_behave_like "all resources"
|
25
|
+
|
26
|
+
it "should allow retrieval of all images" do
|
27
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
28
|
+
images = client.images
|
29
|
+
images.should_not be_empty
|
30
|
+
images.size.should eql( 3 )
|
31
|
+
images.each do |image|
|
32
|
+
image.uri.should_not be_nil
|
33
|
+
image.uri.should be_a(String)
|
34
|
+
image.description.should_not be_nil
|
35
|
+
image.description.should be_a(String)
|
36
|
+
image.architecture.should_not be_nil
|
37
|
+
image.architecture.should be_a(String)
|
38
|
+
image.owner_id.should_not be_nil
|
39
|
+
image.owner_id.should be_a(String)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should allow retrieval of my own images" do
|
45
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
46
|
+
images = client.images( :owner_id=>:self )
|
47
|
+
images.should_not be_empty
|
48
|
+
images.size.should eql( 1 )
|
49
|
+
images.each do |image|
|
50
|
+
image.uri.should_not be_nil
|
51
|
+
image.uri.should be_a(String)
|
52
|
+
image.description.should_not be_nil
|
53
|
+
image.description.should be_a(String)
|
54
|
+
image.architecture.should_not be_nil
|
55
|
+
image.architecture.should be_a(String)
|
56
|
+
image.owner_id.should_not be_nil
|
57
|
+
image.owner_id.should be_a(String)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should allow retrieval of a single image by ID" do
|
63
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
64
|
+
image = client.image( 'img1' )
|
65
|
+
image.should_not be_nil
|
66
|
+
image.uri.should eql( API_URL + '/images/img1' )
|
67
|
+
image.id.should eql( 'img1' )
|
68
|
+
image.architecture.should eql( 'x86_64' )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should allow retrieval of a single image by URI" do
|
73
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
74
|
+
image = client.fetch_image( API_URL + '/images/img1' )
|
75
|
+
image.should_not be_nil
|
76
|
+
image.uri.should eql( API_URL + '/images/img1' )
|
77
|
+
image.id.should eql( 'img1' )
|
78
|
+
image.architecture.should eql( 'x86_64' )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "filtering by architecture" do
|
83
|
+
it "return matching images" do
|
84
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
85
|
+
images = client.images( :architecture=>'x86_64' )
|
86
|
+
images.should_not be_empty
|
87
|
+
images.each do |image|
|
88
|
+
image.architecture.should eql( 'x86_64' )
|
89
|
+
end
|
90
|
+
images = client.images( :architecture=>'i386' )
|
91
|
+
images.should_not be_empty
|
92
|
+
images.each do |image|
|
93
|
+
image.architecture.should eql( 'i386' )
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return an empty array for no matches" do
|
99
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
100
|
+
images = client.images( :architecture=>'8088' )
|
101
|
+
images.should be_empty
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|