steamcannon-deltacloud-client 0.0.9.8.1 → 0.1.0.2

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.
data/lib/documentation.rb CHANGED
@@ -1,98 +1,62 @@
1
- require 'lib/deltacloud'
1
+ #
2
+ # Copyright (C) 2010 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
+ module DeltaCloud
20
+ class Documentation
21
+
22
+ attr_reader :api, :description, :params, :collection_operations
23
+ attr_reader :collection, :operation
24
+
25
+ def initialize(api, opts={})
26
+ @description, @api = opts[:description], api
27
+ @params = parse_parameters(opts[:params]) if opts[:params]
28
+ @collection_operations = opts[:operations] if opts[:operations]
29
+ @collection = opts[:collection]
30
+ @operation = opts[:operation]
31
+ self
32
+ end
2
33
 
3
- skip_methods = [ "id=", "uri=" ]
34
+ def operations
35
+ @collection_operations.collect { |o| api.documentation(@collection, o) }
36
+ end
4
37
 
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
38
+ class OperationParameter
39
+ attr_reader :name
40
+ attr_reader :type
41
+ attr_reader :required
42
+ attr_reader :description
11
43
 
12
- @dc.entry_points.keys.each do |ep|
13
- @dc.send(ep)
14
- end
44
+ def initialize(data)
45
+ @name, @type, @required, @description = data[:name], data[:type], data[:required], data[:description]
46
+ end
15
47
 
16
- class_list = DeltaCloud::classes.collect { |c| DeltaCloud::module_eval("::DeltaCloud::API::#{c}")}
48
+ def to_comment
49
+ " # @param [#{@type}, #{@name}] #{@description}"
50
+ end
17
51
 
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
52
  end
32
- end
33
- end
34
53
 
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
54
+ private
42
55
 
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
56
+ def parse_parameters(params)
57
+ params.collect { |p| OperationParameter.new(p) }
70
58
  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"
59
+
87
60
  end
88
- out << " end"
89
- out << "end"
90
- end
91
61
 
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
62
  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,64 @@
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
+ module DeltaCloud
20
+
21
+ module HWP
22
+
23
+ class Property
24
+ attr_reader :name, :unit, :value, :kind
25
+
26
+ def initialize(xml, name)
27
+ @name, @kind, @value, @unit = xml['name'], xml['kind'].to_sym, xml['value'], xml['unit']
28
+ declare_ranges(xml)
29
+ self
30
+ end
31
+
32
+ def present?
33
+ ! @value.nil?
34
+ end
35
+
36
+ private
37
+
38
+ def declare_ranges(xml)
39
+ case xml['kind']
40
+ when 'range' then
41
+ self.class.instance_eval do
42
+ attr_reader :range
43
+ end
44
+ @range = { :from => xml.xpath('range').first['first'], :to => xml.xpath('range').first['last'] }
45
+ when 'enum' then
46
+ self.class.instance_eval do
47
+ attr_reader :options
48
+ end
49
+ @options = xml.xpath('enum/entry').collect { |e| e['value'] }
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ # FloatProperty is like Property but return value is Float instead of String.
56
+ class FloatProperty < Property
57
+ def initialize(xml, name)
58
+ super(xml, name)
59
+ @value = @value.to_f if @value
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,29 @@
1
+ module DeltaCloud
2
+ module InstanceState
3
+
4
+ class State
5
+ attr_reader :name
6
+ attr_reader :transitions
7
+
8
+ def initialize(name)
9
+ @name, @transitions = name, []
10
+ end
11
+ end
12
+
13
+ class Transition
14
+ attr_reader :to
15
+ attr_reader :action
16
+
17
+ def initialize(to, action)
18
+ @to = to
19
+ @action = action
20
+ end
21
+
22
+ def auto?
23
+ @action.nil?
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
data/lib/string.rb ADDED
@@ -0,0 +1,53 @@
1
+ #
2
+ # Copyright (C) 2010 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
+ class String
20
+
21
+ unless method_defined?(:classify)
22
+ # Create a class name from string
23
+ def classify
24
+ self.singularize.camelize
25
+ end
26
+ end
27
+
28
+ unless method_defined?(:camelize)
29
+ # Camelize converts strings to UpperCamelCase
30
+ def camelize
31
+ self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
32
+ end
33
+ end
34
+
35
+ unless method_defined?(:singularize)
36
+ # Strip 's' character from end of string
37
+ def singularize
38
+ self.gsub(/s$/, '')
39
+ end
40
+ end
41
+
42
+ # Convert string to float if string value seems like Float
43
+ def convert
44
+ return self.to_f if self.strip =~ /^([\d\.]+$)/
45
+ self
46
+ end
47
+
48
+ # Simply converts whitespaces and - symbols to '_' which is safe for Ruby
49
+ def sanitize
50
+ self.strip.gsub(/(\W+)/, '_')
51
+ end
52
+
53
+ end
@@ -64,7 +64,7 @@ describe "hardware_profiles" do
64
64
  it "should allow fetching different hardware_profiles" do
65
65
  client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
66
66
  hwp1 = client.hardware_profile( 'm1-small' )
67
- hwp2 = client.hardware_profile( 'm1-xlarge' )
67
+ hwp2 = client.hardware_profile( 'm1-large' )
68
68
  hwp1.storage.value.should_not eql(hwp2.storage.value)
69
69
  hwp1.memory.value.should_not eql(hwp2.memory.value)
70
70
  end
@@ -85,7 +85,7 @@ describe "instances" do
85
85
 
86
86
  it "should allow creation of new instances with reasonable defaults" do
87
87
  DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
88
- instance = client.create_instance( 'img1', :name=>'TestInstance' )
88
+ instance = client.create_instance( 'img1', :name=>'TestInstance', :hardware_profile => 'm1-large' )
89
89
  instance.should_not be_nil
90
90
  instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} )
91
91
  instance.id.should match( /inst[0-9]+/ )
@@ -98,7 +98,7 @@ describe "instances" do
98
98
 
99
99
  it "should allow creation of new instances with specific realm" do
100
100
  DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
101
- instance = client.create_instance( 'img1', :realm=>'eu' )
101
+ instance = client.create_instance( 'img1', :realm=>'eu', :hardware_profile => 'm1-large' )
102
102
  instance.should_not be_nil
103
103
  instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} )
104
104
  instance.id.should match( /inst[0-9]+/ )
@@ -44,7 +44,6 @@ describe "storage volumes" do
44
44
  storage_volume = client.storage_volume( 'vol3' )
45
45
  storage_volume.id.should eql( 'vol3' )
46
46
  storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' )
47
- storage_volume.state.should eql( 'IN-USE' )
48
47
  storage_volume.capacity.should eql( 1.0 )
49
48
  storage_volume.device.should eql( '/dev/sda1' )
50
49
  storage_volume.instance.should_not be_nil
@@ -61,7 +60,6 @@ describe "storage volumes" do
61
60
  storage_volume.should_not be_nil
62
61
  storage_volume.id.should eql( 'vol3' )
63
62
  storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' )
64
- storage_volume.state.should eql( 'IN-USE' )
65
63
  storage_volume.capacity.should eql( 1.0 )
66
64
  storage_volume.device.should eql( '/dev/sda1' )
67
65
  storage_volume.instance.should_not be_nil
metadata CHANGED
@@ -4,11 +4,10 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
- - 9
9
- - 8
10
7
  - 1
11
- version: 0.0.9.8.1
8
+ - 0
9
+ - 2
10
+ version: 0.1.0.2
12
11
  platform: ruby
13
12
  authors:
14
13
  - Red Hat, Inc.
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-10-21 00:00:00 -04:00
18
+ date: 2010-11-29 00:00:00 -05:00
20
19
  default_executable: deltacloudc
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -29,9 +28,9 @@ dependencies:
29
28
  - !ruby/object:Gem::Version
30
29
  segments:
31
30
  - 1
32
- - 4
33
- - 2
34
- version: 1.4.2
31
+ - 6
32
+ - 1
33
+ version: 1.6.1
35
34
  type: :runtime
36
35
  version_requirements: *id001
37
36
  - !ruby/object:Gem::Dependency
@@ -45,8 +44,8 @@ dependencies:
45
44
  segments:
46
45
  - 1
47
46
  - 4
48
- - 1
49
- version: 1.4.1
47
+ - 3
48
+ version: 1.4.3
50
49
  type: :runtime
51
50
  version_requirements: *id002
52
51
  - !ruby/object:Gem::Dependency
@@ -75,7 +74,11 @@ extra_rdoc_files:
75
74
  files:
76
75
  - Rakefile
77
76
  - lib/plain_formatter.rb
77
+ - lib/string.rb
78
78
  - lib/deltacloud.rb
79
+ - lib/base_object.rb
80
+ - lib/hwp_properties.rb
81
+ - lib/instance_state.rb
79
82
  - lib/documentation.rb
80
83
  - init.rb
81
84
  - bin/deltacloudc
@@ -88,18 +91,6 @@ files:
88
91
  - specs/spec_helper.rb
89
92
  - specs/instance_states_spec.rb
90
93
  - specs/initialization_spec.rb
91
- - specs/data/storage_volumes/vol3.yml
92
- - specs/data/storage_volumes/vol1.yml
93
- - specs/data/storage_volumes/vol2.yml
94
- - specs/data/images/img2.yml
95
- - specs/data/images/img3.yml
96
- - specs/data/images/img1.yml
97
- - specs/data/instances/inst2.yml
98
- - specs/data/instances/inst1.yml
99
- - specs/data/instances/inst0.yml
100
- - specs/data/storage_snapshots/snap3.yml
101
- - specs/data/storage_snapshots/snap1.yml
102
- - specs/data/storage_snapshots/snap2.yml
103
94
  - specs/fixtures/storage_volumes/vol3.yml
104
95
  - specs/fixtures/storage_volumes/vol1.yml
105
96
  - specs/fixtures/storage_volumes/vol2.yml
@@ -156,18 +147,6 @@ test_files:
156
147
  - specs/spec_helper.rb
157
148
  - specs/instance_states_spec.rb
158
149
  - specs/initialization_spec.rb
159
- - specs/data/storage_volumes/vol3.yml
160
- - specs/data/storage_volumes/vol1.yml
161
- - specs/data/storage_volumes/vol2.yml
162
- - specs/data/images/img2.yml
163
- - specs/data/images/img3.yml
164
- - specs/data/images/img1.yml
165
- - specs/data/instances/inst2.yml
166
- - specs/data/instances/inst1.yml
167
- - specs/data/instances/inst0.yml
168
- - specs/data/storage_snapshots/snap3.yml
169
- - specs/data/storage_snapshots/snap1.yml
170
- - specs/data/storage_snapshots/snap2.yml
171
150
  - specs/fixtures/storage_volumes/vol3.yml
172
151
  - specs/fixtures/storage_volumes/vol1.yml
173
152
  - specs/fixtures/storage_volumes/vol2.yml
@@ -1,4 +0,0 @@
1
- :description: Fedora 10
2
- :owner_id: fedoraproject
3
- :architecture: x86_64
4
- :id: img1
@@ -1,4 +0,0 @@
1
- :description: Fedora 10
2
- :owner_id: fedoraproject
3
- :architecture: i386
4
- :id: img2