occi-cli 4.0.0.alpha.2 → 4.0.0.alpha.3

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/README.md CHANGED
@@ -14,8 +14,7 @@ Ruby
14
14
 
15
15
  The following setup is recommended
16
16
 
17
- * usage of the Ruby Version Manager
18
- * Ruby 1.9.3
17
+ * Ruby 1.9.3+
19
18
  * RubyGems installed
20
19
 
21
20
  The following libraries / packages may be required to use rOCCI-cli
@@ -42,6 +41,8 @@ To install the most recent beta version
42
41
 
43
42
  ### Installation from source
44
43
 
44
+ **Installation from source is intended for advanced users or developers only!**
45
+
45
46
  To use rOCCI-cli from source it is very much recommended to use RVM. [Install RVM](https://rvm.io/rvm/install/) with
46
47
 
47
48
  curl -L https://get.rvm.io | bash -s stable --ruby
@@ -53,8 +54,8 @@ To build and install the bleeding edge version from master
53
54
  git clone git://github.com/gwdg/rOCCI-cli.git
54
55
  cd rOCCI-cli
55
56
  rvm install ruby-1.9.3
56
- rvm --create --ruby-version use 1.9.3@rOCCI-cli
57
- bundle install --deployment
57
+ gem install bundler
58
+ bundle install
58
59
  rake install
59
60
 
60
61
  #### Java
@@ -63,8 +64,7 @@ To build a Java jar file from master use
63
64
 
64
65
  git clone git://github.com/gwdg/rOCCI-cli.git
65
66
  cd rOCCI-cli
66
- rvm install jruby-1.7.1
67
- rvm --create --ruby-version use jruby-1.7.1@rOCCI-cli
67
+ rvm install jruby-1.7.4
68
68
  gem install bundler
69
69
  bundle install
70
70
  warble
@@ -127,6 +127,12 @@ To delete a compute resource use
127
127
  Changelog
128
128
  ---------
129
129
 
130
+ ### Version 4.0
131
+ * added extended support for OCCI-OS
132
+ * updated human-readable output rendering
133
+ * split the code into rOCCI-core, rOCCI-api and rOCCI-cli
134
+ * internal changes, refactoring and some bugfixes
135
+
130
136
  ### Version 3.1
131
137
  * added basic OS Keystone support
132
138
  * added support for PKCS12 credentials for X.509 authN
data/bin/occi CHANGED
@@ -21,6 +21,7 @@ require 'highline/import'
21
21
  require 'openssl'
22
22
 
23
23
  extend Occi::Api::Dsl
24
+ extend Occi::Cli::Helpers
24
25
 
25
26
  # get arguments and validate/parse them to an ostruct
26
27
  options = Occi::Cli::OcciOpts.parse ARGV
@@ -1,149 +1,188 @@
1
1
  # a bunch of OCCI client helpers for bin/occi
2
+ module Occi::Cli
3
+ module Helpers
4
+
5
+ def helper_list(options, output = nil)
6
+ found = []
7
+
8
+ if resource_types.include? options.resource
9
+ Occi::Log.debug "#{options.resource} is a resource type."
10
+ found = list options.resource
11
+ elsif mixin_types.include? options.resource
12
+ Occi::Log.debug "#{options.resource} is a mixin type."
13
+ found = mixins options.resource
14
+ else
15
+ Occi::Log.warn "I have no idea what #{options.resource} is ..."
16
+ raise "Unknown resource #{options.resource}, there is nothing to list here!"
17
+ end
2
18
 
3
- def helper_list(options, output = nil)
4
- found = []
5
-
6
- if resource_types.include? options.resource
7
- Occi::Log.debug "#{options.resource} is a resource type."
8
- found = list options.resource
9
- elsif mixin_types.include? options.resource
10
- Occi::Log.debug "#{options.resource} is a mixin type."
11
- found = mixins options.resource
12
- else
13
- Occi::Log.warn "I have no idea what #{options.resource} is ..."
14
- raise "Unknown resource #{options.resource}, there is nothing to list here!"
15
- end
16
-
17
- return found if output.nil?
19
+ return found if output.nil?
18
20
 
19
- if Occi::Cli::ResourceOutputFactory.allowed_resource_types.include? options.resource.to_sym
20
- puts output.format(found, :locations, options.resource.to_sym)
21
- else
22
- Occi::Log.warn "Not printing, the resource type is not supported!"
23
- end
24
- end
21
+ if Occi::Cli::ResourceOutputFactory.allowed_resource_types.include? options.resource.to_sym
22
+ puts output.format(found, :locations, options.resource.to_sym)
23
+ else
24
+ Occi::Log.warn "Not printing, the resource type is not supported!"
25
+ end
26
+ end
25
27
 
26
- def helper_describe(options, output = nil)
27
- found = []
28
+ def helper_describe(options, output = nil)
29
+ found = []
28
30
 
29
- if resource_types.include?(options.resource) || options.resource.start_with?(options.endpoint) || options.resource.start_with?('/')
30
- Occi::Log.debug "#{options.resource} is a resource type or an actual resource."
31
+ if resource_types.include?(options.resource) || options.resource.start_with?(options.endpoint) || options.resource.start_with?('/')
32
+ Occi::Log.debug "#{options.resource} is a resource type or an actual resource."
31
33
 
32
- found = describe(options.resource)
33
- elsif mixin_types.include? options.resource
34
- Occi::Log.debug "#{options.resourcre} is a mixin type."
34
+ found = describe(options.resource)
35
+ elsif mixin_types.include? options.resource
36
+ Occi::Log.debug "#{options.resourcre} is a mixin type."
35
37
 
36
- mixins(options.resource).each do |mxn|
37
- mxn = mxn.split("#").last
38
- found << mixin(mxn, options.resource, true)
39
- end
40
- elsif mixin_types.include? options.resource.split('#').first
41
- Occi::Log.debug "#{options.resource} is a specific mixin type."
42
-
43
- mxn_type,mxn = options.resource.split('#')
44
- found << mixin(mxn, mxn_type, true)
45
- else
46
- Occi::Log.warn "I have no idea what #{options.resource} is ..."
47
- raise "Unknown resource #{options.resource}, there is nothing to describe here!"
48
- end
38
+ mixins(options.resource).each do |mxn|
39
+ mxn = mxn.split("#").last
40
+ found << mixin(mxn, options.resource, true)
41
+ end
42
+ elsif mixin_types.include? options.resource.split('#').first
43
+ Occi::Log.debug "#{options.resource} is a specific mixin type."
44
+
45
+ mxn_type,mxn = options.resource.split('#')
46
+ found << mixin(mxn, mxn_type, true)
47
+ else
48
+ Occi::Log.warn "I have no idea what #{options.resource} is ..."
49
+ raise "Unknown resource #{options.resource}, there is nothing to describe here!"
50
+ end
49
51
 
50
- return found if output.nil?
51
-
52
- if options.resource.start_with? options.endpoint
53
- # resource contains full endpoint URI
54
- # e.g., http://localhost:3300/network/adfgadf-daf5a6df4afadf-adfad65f4ad
55
- resource_type = options.resource.split('/')[3].to_sym
56
- elsif options.resource.start_with? '/'
57
- # resource contains a path relative to endpoint URI
58
- # e.g., /network/adfgadf-daf5a6df4afadf-adfad65f4ad
59
- resource_type = options.resource.split('/')[1].to_sym
60
- elsif mixin_types.include? options.resource.split('#').first
61
- # resource contains a mixin with a type
62
- # e.g., os_tpl#debian6
63
- resource_type = options.resource.split('#').first.to_sym
64
- else
65
- # resource probably contains RAW resource_type
66
- resource_type = options.resource.to_sym
67
- end
52
+ return found if output.nil?
53
+
54
+ if options.resource.start_with? options.endpoint
55
+ # resource contains full endpoint URI
56
+ # e.g., http://localhost:3300/network/adfgadf-daf5a6df4afadf-adfad65f4ad
57
+ resource_type = options.resource.split('/')[3].to_sym
58
+ elsif options.resource.start_with? '/'
59
+ # resource contains a path relative to endpoint URI
60
+ # e.g., /network/adfgadf-daf5a6df4afadf-adfad65f4ad
61
+ resource_type = options.resource.split('/')[1].to_sym
62
+ elsif mixin_types.include? options.resource.split('#').first
63
+ # resource contains a mixin with a type
64
+ # e.g., os_tpl#debian6
65
+ resource_type = options.resource.split('#').first.to_sym
66
+ else
67
+ # resource probably contains RAW resource_type
68
+ resource_type = options.resource.to_sym
69
+ end
68
70
 
69
- if Occi::Cli::ResourceOutputFactory.allowed_resource_types.include? resource_type
70
- puts output.format(found, :resources, resource_type)
71
- else
72
- Occi::Log.warn "Not printing, the resource type [#{resource_type.to_s}] is not supported!"
73
- end
74
- end
71
+ if Occi::Cli::ResourceOutputFactory.allowed_resource_types.include? resource_type
72
+ puts output.format(found, :resources, resource_type)
73
+ else
74
+ Occi::Log.warn "Not printing, the resource type [#{resource_type.to_s}] is not supported!"
75
+ end
76
+ end
75
77
 
76
- def helper_create(options, output = nil)
77
- location = nil
78
+ def helper_create(options, output = nil)
79
+ location = nil
78
80
 
79
- if resource_types.include? options.resource
80
- Occi::Log.debug "#{options.resource} is a resource type."
81
- raise "Not yet implemented!" unless options.resource.include? "compute"
81
+ if resource_types.include? options.resource
82
+ Occi::Log.debug "#{options.resource} is a resource type."
83
+ raise "Not yet implemented!" unless options.resource.include? "compute"
82
84
 
83
- res = resource options.resource
85
+ res = resource options.resource
84
86
 
85
- Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"
87
+ Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"
86
88
 
87
- if options.links
88
- Occi::Log.debug "with links: #{options.links}"
89
+ if options.links
90
+ Occi::Log.debug "with links: #{options.links}"
89
91
 
90
- options.links.each do |link|
91
- link = options.endpoint.chomp('/') + link unless link.start_with? options.endpoint
92
+ options.links.each do |link|
93
+ link = options.endpoint.chomp('/') + link unless link.start_with? options.endpoint
92
94
 
93
- if link.include? "/storage/"
94
- Occi::Log.debug "Adding storagelink to #{options.resource}"
95
- res.storagelink link
96
- elsif link.include? "/network/"
97
- Occi::Log.debug "Adding networkinterface to #{options.resource}"
98
- res.networkinterface link
99
- else
100
- raise "Unknown link type #{link}, stopping here!"
95
+ if link.include? "/storage/"
96
+ Occi::Log.debug "Adding storagelink to #{options.resource}"
97
+ res.storagelink link
98
+ elsif link.include? "/network/"
99
+ Occi::Log.debug "Adding networkinterface to #{options.resource}"
100
+ res.networkinterface link
101
+ else
102
+ raise "Unknown link type #{link}, stopping here!"
103
+ end
104
+ end
101
105
  end
102
- end
103
- end
104
106
 
105
- if options.mixins
106
- Occi::Log.debug "with mixins: #{options.mixins}"
107
+ if options.mixins
108
+ Occi::Log.debug "with mixins: #{options.mixins}"
109
+
110
+ options.mixins.keys.each do |type|
111
+ Occi::Log.debug "Adding mixins of type #{type} to #{options.resource}"
112
+
113
+ options.mixins[type].each do |name|
114
+ mxn = mixin name, type
115
+
116
+ raise "Unknown mixin #{type}##{name}, stopping here!" if mxn.nil?
117
+ Occi::Log.debug "Adding mixin #{mxn} to #{options.resource}"
118
+ res.mixins << mxn
119
+ end
120
+ end
121
+
122
+ # TODO: find a better/universal way to do contextualization
123
+ if options.context_vars
124
+ Occi::Log.debug "with context variables: #{options.context_vars}"
125
+
126
+ options.context_vars.each_pair do |var, val|
127
+ schema = nil
128
+ mxn_attrs = Occi::Core::Attributes.new
129
+
130
+ case var
131
+ when :public_key
132
+ schema = "http://schemas.openstack.org/instance/credentials#"
133
+ mxn_attrs['org.openstack.credentials.publickey.name'] = {}
134
+ mxn_attrs['org.openstack.credentials.publickey.data'] = {}
135
+ when :user_data
136
+ schema = "http://schemas.openstack.org/compute/instance#"
137
+ mxn_attrs['org.openstack.compute.user_data'] = {}
138
+ else
139
+ schema = "http://schemas.ogf.org/occi/core#"
140
+ end
141
+
142
+ mxn = Occi::Core::Mixin.new(schema, var.to_s, 'OS contextualization mixin', mxn_attrs)
143
+ res.mixins << mxn
144
+
145
+ case var
146
+ when :public_key
147
+ res.attributes['org.openstack.credentials.publickey.name'] = 'Public SSH key'
148
+ res.attributes['org.openstack.credentials.publickey.data'] = val
149
+ when :user_data
150
+ res.attributes['org.openstack.compute.user_data'] = val
151
+ else
152
+ # do nothing
153
+ end
154
+ end
155
+ end
156
+ end
107
157
 
108
- options.mixins.keys.each do |type|
109
- Occi::Log.debug "Adding mixins of type #{type} to #{options.resource}"
158
+ #TODO: set other attributes
159
+ res.title = options.attributes[:title]
110
160
 
111
- options.mixins[type].each do |name|
112
- mxn = mixin name, type
161
+ Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"
113
162
 
114
- raise "Unknown mixin #{type}##{name}, stopping here!" if mxn.nil?
115
- Occi::Log.debug "Adding mixin #{mxn} to #{options.resource}"
116
- res.mixins << mxn
117
- end
163
+ location = create res
164
+ else
165
+ Occi::Log.warn "I have no idea what #{options.resource} is ..."
166
+ raise "Unknown resource #{options.resource}, there is nothing to create here!"
118
167
  end
119
- end
120
168
 
121
- #TODO: set other attributes
122
- res.title = options.attributes[:title]
169
+ return location if output.nil?
123
170
 
124
- Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"
125
-
126
- location = create res
127
- else
128
- Occi::Log.warn "I have no idea what #{options.resource} is ..."
129
- raise "Unknown resource #{options.resource}, there is nothing to create here!"
130
- end
171
+ puts location
172
+ end
131
173
 
132
- return location if output.nil?
174
+ def helper_delete(options, output = nil)
175
+ if delete(options.resource)
176
+ Occi::Log.info "Resource #{options.resource} successfully removed!"
177
+ else
178
+ raise "Failed to remove resource #{options.resource}!"
179
+ end
133
180
 
134
- puts location
135
- end
181
+ true
182
+ end
136
183
 
137
- def helper_delete(options, output = nil)
138
- if delete(options.resource)
139
- Occi::Log.info "Resource #{options.resource} successfully removed!"
140
- else
141
- raise "Failed to remove resource #{options.resource}!"
184
+ def helper_trigger(options, output = nil)
185
+ raise "Not yet implemented!"
186
+ end
142
187
  end
143
-
144
- true
145
- end
146
-
147
- def helper_trigger(options, output = nil)
148
- raise "Not yet implemented!"
149
188
  end
@@ -1,6 +1,7 @@
1
1
  require 'ostruct'
2
2
  require 'optparse'
3
3
  require 'uri'
4
+ require 'base64'
4
5
 
5
6
  require 'occi/cli/resource_output_factory'
6
7
 
@@ -12,6 +13,7 @@ module Occi::Cli
12
13
  MEDIA_TYPES = ["application/occi+json", "application/occi+xml", "text/plain,text/occi", "text/plain"].freeze
13
14
  ACTIONS = [:list, :describe, :create, :delete, :trigger].freeze
14
15
  LOG_OUTPUTS = [:stdout, :stderr].freeze
16
+ ALLOWED_CONTEXT_VARS = [:public_key, :user_data].freeze
15
17
 
16
18
  def self.parse(args, test_env = false)
17
19
 
@@ -188,7 +190,22 @@ occi --endpoint https://localhost:3300/ --action delete --resource /compute/65sd
188
190
  ary = /^(.+?)=(.+)$/.match(ctx).to_a.drop 1
189
191
  raise ArgumentError, "Context variables must always contain ATTR=VALUE pairs!" if ary.length != 2
190
192
 
191
- options.context_vars[ary[0].to_sym] = ary[1]
193
+ symbol = ary[0].to_sym
194
+ if ALLOWED_CONTEXT_VARS.include?(symbol)
195
+ context_data = ary[1]
196
+ if context_data.gsub!(/^file:\/\//,'')
197
+ raise 'File does not exist! #{context_data}' unless File.exist? context_data
198
+ context_data = File.read(context_data)
199
+ end
200
+
201
+ if symbol == :user_data
202
+ context_data = Base64.encode64(context_data)
203
+ end
204
+
205
+ options.context_vars[symbol] = context_data.strip
206
+ else
207
+ Occi::Log.warn "Only #{ALLOWED_CONTEXT_VARS.join(', ')} context variables are supported! Skipping #{ary[0].to_s} ..."
208
+ end
192
209
  end
193
210
  end
194
211
 
@@ -1,5 +1,5 @@
1
1
  module Occi
2
2
  module Cli
3
- VERSION = "4.0.0.alpha.2" unless defined?(::Occi::Cli::VERSION)
3
+ VERSION = "4.0.0.alpha.3" unless defined?(::Occi::Cli::VERSION)
4
4
  end
5
5
  end
data/occi-cli.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |gem|
9
9
  gem.version = Occi::Cli::VERSION
10
10
  gem.authors = ["Florian Feldhaus","Piotr Kasprzak", "Boris Parak"]
11
11
  gem.email = ["florian.feldhaus@gwdg.de", "piotr.kasprzak@gwdg.de", "xparak@mail.muni.cz"]
12
- gem.description = %q{OCCI is a collection of classes to simplify the implementation of the Open Cloud Computing API in Ruby}
13
- gem.summary = %q{OCCI toolkit}
12
+ gem.description = %q{This gem is a client implementation of the Open Cloud Computing Interface in Ruby}
13
+ gem.summary = %q{Executable OCCI client}
14
14
  gem.homepage = 'https://github.com/gwdg/rOCCI-cli'
15
15
  gem.license = 'Apache License, Version 2.0'
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.alpha.2
4
+ version: 4.0.0.alpha.3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-07-18 00:00:00.000000000 Z
14
+ date: 2013-07-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: occi-api
@@ -189,8 +189,8 @@ dependencies:
189
189
  - - ! '>='
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
- description: OCCI is a collection of classes to simplify the implementation of the
193
- Open Cloud Computing API in Ruby
192
+ description: This gem is a client implementation of the Open Cloud Computing Interface
193
+ in Ruby
194
194
  email:
195
195
  - florian.feldhaus@gwdg.de
196
196
  - piotr.kasprzak@gwdg.de
@@ -253,5 +253,5 @@ rubyforge_project:
253
253
  rubygems_version: 1.8.25
254
254
  signing_key:
255
255
  specification_version: 3
256
- summary: OCCI toolkit
256
+ summary: Executable OCCI client
257
257
  test_files: []