deltacloud-client 1.0.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.
Files changed (45) hide show
  1. data/Rakefile +6 -46
  2. data/lib/base_object.rb +1 -1
  3. data/lib/client_bucket_methods.rb +2 -2
  4. data/lib/deltacloud.rb +8 -7
  5. metadata +81 -127
  6. data/bin/deltacloudc +0 -243
  7. data/lib/plain_formatter.rb +0 -145
  8. data/specs/buckets_spec.rb +0 -148
  9. data/specs/content_spec.rb +0 -137
  10. data/specs/data/images/img1.yml +0 -4
  11. data/specs/data/images/img2.yml +0 -4
  12. data/specs/data/images/img3.yml +0 -4
  13. data/specs/data/instances/inst0.yml +0 -16
  14. data/specs/data/instances/inst1.yml +0 -9
  15. data/specs/data/instances/inst2.yml +0 -9
  16. data/specs/data/storage_snapshots/snap1.yml +0 -4
  17. data/specs/data/storage_snapshots/snap2.yml +0 -4
  18. data/specs/data/storage_snapshots/snap3.yml +0 -4
  19. data/specs/data/storage_volumes/vol1.yml +0 -7
  20. data/specs/data/storage_volumes/vol2.yml +0 -7
  21. data/specs/data/storage_volumes/vol3.yml +0 -7
  22. data/specs/errors_spec.rb +0 -59
  23. data/specs/fixtures/images/img1.yml +0 -4
  24. data/specs/fixtures/images/img2.yml +0 -4
  25. data/specs/fixtures/images/img3.yml +0 -4
  26. data/specs/fixtures/instances/inst0.yml +0 -16
  27. data/specs/fixtures/instances/inst1.yml +0 -9
  28. data/specs/fixtures/instances/inst2.yml +0 -9
  29. data/specs/fixtures/storage_snapshots/snap1.yml +0 -4
  30. data/specs/fixtures/storage_snapshots/snap2.yml +0 -4
  31. data/specs/fixtures/storage_snapshots/snap3.yml +0 -4
  32. data/specs/fixtures/storage_volumes/vol1.yml +0 -7
  33. data/specs/fixtures/storage_volumes/vol2.yml +0 -7
  34. data/specs/fixtures/storage_volumes/vol3.yml +0 -7
  35. data/specs/hardware_profiles_spec.rb +0 -80
  36. data/specs/images_spec.rb +0 -107
  37. data/specs/initialization_spec.rb +0 -64
  38. data/specs/instance_states_spec.rb +0 -80
  39. data/specs/instances_spec.rb +0 -210
  40. data/specs/keys_spec.rb +0 -97
  41. data/specs/realms_spec.rb +0 -66
  42. data/specs/shared/resources.rb +0 -30
  43. data/specs/spec_helper.rb +0 -53
  44. data/specs/storage_snapshot_spec.rb +0 -81
  45. data/specs/storage_volume_spec.rb +0 -91
data/Rakefile CHANGED
@@ -21,61 +21,21 @@ require 'rake/testtask'
21
21
 
22
22
  load 'deltacloud-client.gemspec'
23
23
 
24
- desc "Generate documentation"
25
- task 'documentation' do
26
- load 'lib/documentation.rb'
27
- end
28
-
29
-
30
24
  spec = Gem::Specification.load('deltacloud-client.gemspec')
25
+
31
26
  Gem::PackageTask.new(spec) do |pkg|
32
27
  pkg.need_tar = true
33
28
  end
34
29
 
35
- def available?(name)
36
- Gem::Specification.find_by_name(name)
37
- rescue Gem::LoadError
38
- false
39
- rescue
40
- Gem.available?(name)
41
- end
42
-
43
- if available?('rspec')
44
- require 'rspec/core/rake_task'
45
- desc "Run all examples"
46
- RSpec::Core::RakeTask.new('spec') do |t|
47
- t.pattern = FileList['specs/**/*_spec.rb']
48
- t.rspec_opts = [ "--format", "nested", "--color"]
49
- end
50
- end
51
-
52
- desc "Reinstall gem"
30
+ desc "Re-install the deltacloud-client gem"
53
31
  task :reinstall do
54
32
  puts %x{gem uninstall deltacloud-client --all -I -x}
55
33
  puts %x{gem build deltacloud-client.gemspec}
56
34
  puts %x{gem install deltacloud-client-*.gem --local}
57
35
  end
58
36
 
59
- desc "Setup Fixtures"
60
- task 'fixtures' do
61
- FileUtils.rm_rf( File.dirname( __FILE__ ) + '/specs/data' )
62
- FileUtils.cp_r( File.dirname( __FILE__ ) + '/specs/fixtures', File.dirname( __FILE__ ) + '/specs/data' )
63
- end
64
-
65
- namespace :test do
66
- Rake::TestTask.new(:cmd) do |t|
67
- t.libs << "tests"
68
- t.test_files = FileList['tests/cmd.rb']
69
- t.verbose = true
70
- end
71
- end
72
-
73
- desc "Clean Fixtures"
74
- task 'fixtures:clean' do
75
- FileUtils.rm_rf( File.dirname( __FILE__ ) + '/specs/data' )
76
- end
77
-
78
- begin
79
- require 'ci/reporter/rake/rspec'
80
- rescue LoadError
37
+ Rake::TestTask.new(:test) do |t|
38
+ t.test_files = FileList[
39
+ 'tests/*test.rb', # EC2 frontend internal API tests
40
+ ]
81
41
  end
data/lib/base_object.rb CHANGED
@@ -13,7 +13,7 @@
13
13
  # License for the specific language governing permissions and limitations
14
14
  # under the License.
15
15
 
16
- require 'string'
16
+ require_relative './string.rb'
17
17
 
18
18
  module DeltaCloud
19
19
 
@@ -27,7 +27,7 @@ module ClientBucketMethods
27
27
  #actually response here is 204 - no content - so nothing returned to client?
28
28
  request(:delete, "#{api_uri.to_s}/buckets/#{params['id']}") do |response|
29
29
  handle_backend_error(response) if response.code!=204
30
- response
30
+ nil if response.code == 204
31
31
  end
32
32
  end
33
33
 
@@ -53,7 +53,7 @@ module ClientBucketMethods
53
53
  def destroy_blob(params)
54
54
  request(:delete, "#{api_uri.to_s}/buckets/#{params['bucket']}/#{params[:id]}") do |response|
55
55
  handle_backend_error(response) if response.code!=204
56
- response
56
+ nil if response.code == 204
57
57
  end
58
58
  end
59
59
 
data/lib/deltacloud.rb CHANGED
@@ -17,12 +17,13 @@ require 'nokogiri'
17
17
  require 'rest_client'
18
18
  require 'base64'
19
19
  require 'logger'
20
- require 'hwp_properties'
21
- require 'instance_state'
22
- require 'documentation'
23
- require 'base_object'
24
- require 'errors'
25
- require 'client_bucket_methods'
20
+ require 'require_relative' if RUBY_VERSION =~ /^1\.8/
21
+ require_relative './hwp_properties.rb'
22
+ require_relative './instance_state.rb'
23
+ require_relative './documentation.rb'
24
+ require_relative './base_object.rb'
25
+ require_relative './errors.rb'
26
+ require_relative './client_bucket_methods.rb'
26
27
 
27
28
  module DeltaCloud
28
29
 
@@ -146,7 +147,7 @@ module DeltaCloud
146
147
  end
147
148
 
148
149
  define_method :"fetch_#{model.to_s.singularize}" do |url|
149
- id = url.grep(/\/#{model}\/(.*)$/)
150
+ url =~ /\/#{model}\/(.*)$/
150
151
  self.send(model.to_s.singularize.to_sym, $1)
151
152
  end
152
153
 
metadata CHANGED
@@ -1,169 +1,123 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: deltacloud-client
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 2
10
+ version: 1.0.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - The Apache Software Foundation
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-08-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rest-client
16
- requirement: &70208850754540 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 13
29
+ segments:
30
+ - 1
31
+ - 6
32
+ - 1
21
33
  version: 1.6.1
22
34
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70208850754540
25
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
26
37
  name: nokogiri
27
- requirement: &70208850754060 !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
28
40
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 1
45
+ segments:
46
+ - 1
47
+ - 4
48
+ - 3
32
49
  version: 1.4.3
33
50
  type: :runtime
34
- prerelease: false
35
- version_requirements: *70208850754060
36
- - !ruby/object:Gem::Dependency
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
37
53
  name: rspec
38
- requirement: &70208850753600 !ruby/object:Gem::Requirement
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
39
56
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 15
61
+ segments:
62
+ - 2
63
+ - 0
64
+ - 0
43
65
  version: 2.0.0
44
66
  type: :development
45
- prerelease: false
46
- version_requirements: *70208850753600
67
+ version_requirements: *id003
47
68
  description: Deltacloud REST Client for API
48
69
  email: dev@deltacloud.apache.org
49
- executables:
50
- - deltacloudc
70
+ executables: []
71
+
51
72
  extensions: []
52
- extra_rdoc_files:
73
+
74
+ extra_rdoc_files:
53
75
  - LICENSE
54
76
  - NOTICE
55
- files:
77
+ files:
56
78
  - Rakefile
57
- - lib/base_object.rb
58
- - lib/client_bucket_methods.rb
59
79
  - lib/deltacloud.rb
60
- - lib/documentation.rb
61
- - lib/errors.rb
62
- - lib/hwp_properties.rb
63
80
  - lib/instance_state.rb
64
- - lib/plain_formatter.rb
65
81
  - lib/string.rb
66
- - bin/deltacloudc
82
+ - lib/errors.rb
83
+ - lib/documentation.rb
84
+ - lib/base_object.rb
85
+ - lib/hwp_properties.rb
86
+ - lib/client_bucket_methods.rb
67
87
  - LICENSE
68
88
  - NOTICE
69
- - specs/buckets_spec.rb
70
- - specs/content_spec.rb
71
- - specs/data/images/img1.yml
72
- - specs/data/images/img2.yml
73
- - specs/data/images/img3.yml
74
- - specs/data/instances/inst0.yml
75
- - specs/data/instances/inst1.yml
76
- - specs/data/instances/inst2.yml
77
- - specs/data/storage_snapshots/snap1.yml
78
- - specs/data/storage_snapshots/snap2.yml
79
- - specs/data/storage_snapshots/snap3.yml
80
- - specs/data/storage_volumes/vol1.yml
81
- - specs/data/storage_volumes/vol2.yml
82
- - specs/data/storage_volumes/vol3.yml
83
- - specs/errors_spec.rb
84
- - specs/fixtures/images/img1.yml
85
- - specs/fixtures/images/img2.yml
86
- - specs/fixtures/images/img3.yml
87
- - specs/fixtures/instances/inst0.yml
88
- - specs/fixtures/instances/inst1.yml
89
- - specs/fixtures/instances/inst2.yml
90
- - specs/fixtures/storage_snapshots/snap1.yml
91
- - specs/fixtures/storage_snapshots/snap2.yml
92
- - specs/fixtures/storage_snapshots/snap3.yml
93
- - specs/fixtures/storage_volumes/vol1.yml
94
- - specs/fixtures/storage_volumes/vol2.yml
95
- - specs/fixtures/storage_volumes/vol3.yml
96
- - specs/hardware_profiles_spec.rb
97
- - specs/images_spec.rb
98
- - specs/initialization_spec.rb
99
- - specs/instance_states_spec.rb
100
- - specs/instances_spec.rb
101
- - specs/keys_spec.rb
102
- - specs/realms_spec.rb
103
- - specs/shared/resources.rb
104
- - specs/spec_helper.rb
105
- - specs/storage_snapshot_spec.rb
106
- - specs/storage_volume_spec.rb
107
89
  homepage: http://www.deltacloud.org
108
90
  licenses: []
91
+
109
92
  post_install_message:
110
93
  rdoc_options: []
111
- require_paths:
94
+
95
+ require_paths:
112
96
  - lib
113
- required_ruby_version: !ruby/object:Gem::Requirement
97
+ required_ruby_version: !ruby/object:Gem::Requirement
114
98
  none: false
115
- requirements:
116
- - - ! '>='
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
107
  none: false
121
- requirements:
122
- - - ! '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
125
115
  requirements: []
116
+
126
117
  rubyforge_project:
127
- rubygems_version: 1.8.15
118
+ rubygems_version: 1.8.11
128
119
  signing_key:
129
120
  specification_version: 3
130
121
  summary: Deltacloud REST Client
131
- test_files:
132
- - specs/buckets_spec.rb
133
- - specs/content_spec.rb
134
- - specs/data/images/img1.yml
135
- - specs/data/images/img2.yml
136
- - specs/data/images/img3.yml
137
- - specs/data/instances/inst0.yml
138
- - specs/data/instances/inst1.yml
139
- - specs/data/instances/inst2.yml
140
- - specs/data/storage_snapshots/snap1.yml
141
- - specs/data/storage_snapshots/snap2.yml
142
- - specs/data/storage_snapshots/snap3.yml
143
- - specs/data/storage_volumes/vol1.yml
144
- - specs/data/storage_volumes/vol2.yml
145
- - specs/data/storage_volumes/vol3.yml
146
- - specs/errors_spec.rb
147
- - specs/fixtures/images/img1.yml
148
- - specs/fixtures/images/img2.yml
149
- - specs/fixtures/images/img3.yml
150
- - specs/fixtures/instances/inst0.yml
151
- - specs/fixtures/instances/inst1.yml
152
- - specs/fixtures/instances/inst2.yml
153
- - specs/fixtures/storage_snapshots/snap1.yml
154
- - specs/fixtures/storage_snapshots/snap2.yml
155
- - specs/fixtures/storage_snapshots/snap3.yml
156
- - specs/fixtures/storage_volumes/vol1.yml
157
- - specs/fixtures/storage_volumes/vol2.yml
158
- - specs/fixtures/storage_volumes/vol3.yml
159
- - specs/hardware_profiles_spec.rb
160
- - specs/images_spec.rb
161
- - specs/initialization_spec.rb
162
- - specs/instance_states_spec.rb
163
- - specs/instances_spec.rb
164
- - specs/keys_spec.rb
165
- - specs/realms_spec.rb
166
- - specs/shared/resources.rb
167
- - specs/spec_helper.rb
168
- - specs/storage_snapshot_spec.rb
169
- - specs/storage_volume_spec.rb
122
+ test_files: []
123
+
data/bin/deltacloudc DELETED
@@ -1,243 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one or more
4
- # contributor license agreements. See the NOTICE file distributed with
5
- # this work for additional information regarding copyright ownership. The
6
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
7
- # "License"); you may not use this file except in compliance with the
8
- # License. You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- # License for the specific language governing permissions and limitations
16
- # under the License.
17
-
18
- require 'rubygems'
19
- require 'optparse'
20
- require 'uri'
21
- require 'deltacloud'
22
- require 'plain_formatter'
23
-
24
- include DeltaCloud::PlainFormatter
25
-
26
- options = {
27
- :verbose => false
28
- }
29
-
30
- @optparse = OptionParser.new do |opts|
31
-
32
- opts.banner = <<BANNER
33
- Usage:
34
- deltacloudc collection operation [options]
35
-
36
- URL format:
37
- API_URL=http://[user]:[password]@[api_url][port][/uri]
38
-
39
- Examples:
40
-
41
- 1. To list collections for deltacloud api on port 3333 of server deltacloud.foo
42
-
43
- deltacloudc -l -u http://user:password@deltacloud.foo:3333/api
44
-
45
- 2. To list the operations for the 'images' collection:
46
-
47
- deltacloudc images -l -u http://user:password@deltacloud.foo:3333/api
48
-
49
- 3. To list all images (i.e. call the 'index' operation of 'images'):
50
-
51
- deltacloudc images index -u http://user:password@deltacloud.foo:3333/api
52
-
53
- 4. To get the details of image '5':
54
-
55
- deltacloudc images show -i 5 -u http://user:password@deltacloud.foo:3333/api
56
-
57
- Options:
58
- BANNER
59
- opts.on( '-i', '--id ID', 'ID for operation') { |id| options[:id] = id }
60
- opts.on( '-d', '--image-id ID', 'Image ID') { |id| options[:image_id] = id }
61
- opts.on( '-b', '--bucket-id ID', 'Bucket ID') {|id| options[:bucket_id] = id }
62
- opts.on( '-r', '--bucket-location NAME', 'Bucket location') {|name| options[:bucket_location] = name }
63
- opts.on( '-a', '--arch ARCH', 'Architecture (x86, x86_64)') { |id| options[:architecture] = id }
64
- opts.on( '-p', '--hardware-profile HARDWARE_PROFILE', 'Hardware Profile') { |id| options[:hwp_id] = id }
65
- opts.on( '-n', '--name NAME', 'Name (for instance eg.)') { |name| options[:name] = name }
66
- opts.on( '-s', '--state STATE', 'Instance state (RUNNING, STOPPED)') { |state| options[:state] = state }
67
- opts.on( '-u', '--url URL', 'API url ($API_URL variable)') { |url| options[:api_url] = url }
68
- opts.on( '-U', '--user USER', 'API username ($API_USERNAME variable)') { |u| options[:api_user] = u }
69
- opts.on( '-P', '--password PASSWORD', 'API password ($API_PASSWORD variable)') { |p| options[:api_password] = p }
70
- opts.on( '-l', '--list', 'List collections/operations') { |id| options[:list] = true }
71
- opts.on( '-h', '--help', 'Display this screen' ) { puts @optparse; Kernel.exit! }
72
- opts.on( '-v', '--version', 'Display API version' ) { options[:version]=true }
73
- opts.on( '-V', '--verbose', 'Print verbose messages' ) { options[:verbose]=true }
74
- opts.on( '-f', '--file-path PATH', 'local path for new blob data') {|path| options[:file_path]=path }
75
- opts.on( '-m', '--blob-metadata k1=v1, k2=v2', 'Comma seperated k=v pairs for blob metadata (for create operation)') do |meta|
76
- blob_meta = {}
77
- meta.gsub!(/ /,"")
78
- meta.scan(/(\w+)=(\w+)/).map {|k,v| blob_meta[k] = v }
79
- options[:blob_metadata] = blob_meta
80
- end
81
- end
82
-
83
- def invalid_usage(error_msg='')
84
- puts "\n ERROR: #{error_msg} \n\n"
85
- puts @optparse
86
- exit(1)
87
- end
88
-
89
- begin
90
- @optparse.parse!
91
- rescue Exception => e
92
- invalid_usage(e.message)
93
- end
94
-
95
- # First try to get API_URL from environment
96
- options[:api_url] = ENV['API_URL'] if options[:api_url].nil?
97
-
98
- if(options[:api_url].nil?)
99
- invalid_usage("You must supply the url to the deltacloud api; either use '-u' flag or set the 'API_URL' environment variable")
100
- end
101
-
102
- url = URI.parse(options[:api_url])
103
- api_url = "http://#{url.host}#{url.port ? ":#{url.port}" : ''}#{url.path}"
104
-
105
- options[:collection] = ARGV[0]
106
- options[:operation] = ARGV[1]
107
-
108
- # Connect to Deltacloud API and fetch all entry points
109
- client = DeltaCloud.new(options[:api_user] || ENV['API_USER'], options[:api_password] || ENV['API_PASSWORD'], api_url)
110
- collections = client.entry_points.keys
111
-
112
- # Exclude collection which don't have methods in client library yet
113
- collections.delete(:instance_states)
114
- #add blob collection if buckets is present
115
- collections << :blob if collections.include?(:buckets)
116
-
117
- # If list parameter passed print out available collection
118
- # with API documentation
119
- if options[:list] and options[:collection].nil?
120
- collections.each do |c|
121
- puts sprintf("%-22s", c.to_s[0, 22])
122
- end
123
- exit(0)
124
- end
125
-
126
- # If collection parameter is present and user requested list
127
- # print all operation defined for collection with API documentation
128
- if options[:list] and options[:collection]
129
- #deal with blobs again - bypass 'normal' docs procedure
130
- if options[:collection] =~ /blob/i
131
- puts "create \t\t: Create a new blob in a specified bucket (POST /api/buckets/:bucket)"
132
- puts "destroy \t: Delete a specified blob in a specified bucket (DELETE /api/buckets/:bucket/:blob)"
133
- puts "show \t\t: Get details of a specified blob in a specified bucket (GET /api/buckets/:bucket/:blob)"
134
- puts "data \t\t: Get the contents of a specified blob - the blob data content itself"
135
- exit(0)
136
- end
137
- doc = client.documentation(options[:collection])
138
- doc.operations.each do |c|
139
- puts sprintf("%-20s: %s", c.operation, c.description)
140
- end
141
- exit(0)
142
- end
143
-
144
- if options[:version]
145
- puts "Deltacloud API(#{client.driver_name}) 0.1"
146
- exit(0)
147
- end
148
-
149
- # List items from collection (typically /instances)
150
- # Do same if 'index' operation is set
151
- if options[:collection] and ( options[:operation].nil? or options[:operation].eql?('index') )
152
- invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection].to_sym)
153
- #cannot list blobs - can only show a specific blob
154
- invalid_usage("You must specify a particular blob with -i and a particular bucket with -b") if options[:collection] =~ (/blob/i)
155
- params = {}
156
- params.merge!(:architecture => options[:architecture]) if options[:architecture]
157
- params.merge!(:id => options[:id]) if options[:id]
158
- params.merge!(:state => options[:state]) if options[:state]
159
- client.send(options[:collection].to_s, params).each do |model|
160
- puts format(model)
161
- end
162
- exit(0)
163
- end
164
-
165
- if options[:collection] and options[:operation]
166
-
167
- invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection].to_sym)
168
-
169
- params = {}
170
- params.merge!(:id => options[:id]) if options[:id]
171
-
172
- # If collection is set and requested operation is 'show' just 'singularize'
173
- # collection name and print item with specified id (-i parameter)
174
- #Blobs are a special case so deal with first -
175
- if options[:collection] =~ (/blob/i)
176
- invalid_usage("Please specify the bucket for this blob using the -b option") unless options[:bucket_id]
177
- invalid_usage("Missing blob ID, please specify with -i option") unless options[:id]
178
- params = {}
179
- params.merge!(:id => options[:id], 'bucket' => options[:bucket_id])
180
- params.merge!('metadata'=>options[:blob_metadata]) unless options[:blob_metadata].nil?
181
- case options[:operation]
182
- when 'show' then puts format(client.send( options[:collection], params))
183
- when 'data' then puts client.blob_data(params)
184
- when 'create' then
185
- invalid_usage("Specify the location of the new blob data (full local path) using -f option") unless options[:file_path]
186
- params.merge!('file_path'=>options[:file_path])
187
- blob = client.create_blob(params)
188
- puts format(blob)
189
- when 'destroy' then client.destroy_blob(params)
190
- else invalid_usage("Please specify a valid operation for the blob collection - try -l to see available operations")
191
- end
192
- exit(0)
193
- end
194
-
195
- if options[:operation].eql?('show')
196
- invalid_usage("Missing ID, must be provided with --id") unless options[:id]
197
- puts format(client.send(options[:collection].gsub(/s$/, ''), options[:id]))
198
- exit(0)
199
- end
200
-
201
- # If collection is set and requested operation is create new instance,
202
- # --image-id, --hardware-profile and --name parameters are used
203
- # Returns created instance in plain form
204
- if options[:collection].eql?('instances') and options[:operation].eql?('create')
205
- invalid_usage("Missing image-id") unless options[:image_id]
206
- if options[:name] and ! client.feature?(:instances, :user_name)
207
- invalid_usage("Driver does not support user-supplied name")
208
- end
209
- params.merge!(:name => options[:name]) if options[:name]
210
- params.merge!(:image_id => options[:image_id]) if options[:image_id]
211
- params.merge!(:hwp_id => options[:hwp_id]) if options[:hwp_id]
212
- instance = client.create_instance(options[:image_id], params)
213
- puts format(instance)
214
- exit(0)
215
- end
216
-
217
- #Create and Destroy a bucket - require the bucket id:
218
- if options[:collection].eql?('buckets')
219
- if options[:operation].eql?('create')
220
- invalid_usage("Please specify an id for the new bucket with -i") unless options[:id]
221
- bucket = client.create_bucket('id'=>options[:id], 'bucket_location'=>options[:bucket_location])
222
- puts format(bucket)
223
- elsif options[:operation].eql?('destroy')
224
- invalid_usage("Please specify the bucket you wish to destroy with -i") unless options[:id]
225
- client.destroy_bucket('id'=>options[:id])
226
- else
227
- invalid_usage("Please specify a valid operation on buckets - use -l to see valid operations")
228
- end
229
- exit(0)
230
- end
231
-
232
- # All other operations above collections is done there:
233
- if options[:collection].eql?('instances')
234
- instance = client.instance(options[:id])
235
- instance.send("#{options[:operation]}!".to_s)
236
- instance = client.instance(options[:id])
237
- puts format(instance)
238
- exit(0)
239
- end
240
- end
241
-
242
- # If all above passed (eg. no parameters)
243
- puts @optparse