occi-cli 4.0.0.beta.2 → 4.0.0

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.
@@ -16,13 +16,15 @@ module Occi::Cli
16
16
  raise "Unknown resource #{options.resource}, there is nothing to list here!"
17
17
  end
18
18
 
19
- return found if output.nil?
19
+ helper_list_output(found, options, output)
20
+ end
20
21
 
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
22
+ def helper_list_output(found, options, output)
23
+ return found unless output
24
+
25
+ helper_formatter_output(found, output, :locations, options.resource.to_sym)
26
+
27
+ nil
26
28
  end
27
29
 
28
30
  def helper_describe(options, output = nil)
@@ -49,7 +51,11 @@ module Occi::Cli
49
51
  raise "Unknown resource #{options.resource}, there is nothing to describe here!"
50
52
  end
51
53
 
52
- return found if output.nil?
54
+ helper_describe_output(found, options, output)
55
+ end
56
+
57
+ def helper_describe_output(found, options, output)
58
+ return found unless output
53
59
 
54
60
  if options.resource.start_with? options.endpoint
55
61
  # resource contains full endpoint URI
@@ -68,11 +74,9 @@ module Occi::Cli
68
74
  resource_type = options.resource.to_sym
69
75
  end
70
76
 
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
77
+ helper_formatter_output(found, output, :resources, resource_type)
78
+
79
+ nil
76
80
  end
77
81
 
78
82
  def helper_create(options, output = nil)
@@ -86,76 +90,9 @@ module Occi::Cli
86
90
 
87
91
  Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"
88
92
 
89
- if options.links
90
- Occi::Log.debug "with links: #{options.links}"
91
-
92
- options.links.each do |link|
93
- if link.start_with? options.endpoint
94
- link.gsub!(options.endpoint.chomp('/'), '')
95
- end
96
-
97
- if link.include? "/storage/"
98
- Occi::Log.debug "Adding storagelink to #{options.resource}"
99
- res.storagelink link
100
- elsif link.include? "/network/"
101
- Occi::Log.debug "Adding networkinterface to #{options.resource}"
102
- res.networkinterface link
103
- else
104
- raise "Unknown link type #{link}, stopping here!"
105
- end
106
- end
107
- end
108
-
109
- if options.mixins
110
- Occi::Log.debug "with mixins: #{options.mixins}"
111
-
112
- options.mixins.keys.each do |type|
113
- Occi::Log.debug "Adding mixins of type #{type} to #{options.resource}"
114
-
115
- options.mixins[type].each do |name|
116
- mxn = mixin name, type
117
-
118
- raise "Unknown mixin #{type}##{name}, stopping here!" if mxn.nil?
119
- Occi::Log.debug "Adding mixin #{mxn} to #{options.resource}"
120
- res.mixins << mxn
121
- end
122
- end
123
-
124
- # TODO: find a better/universal way to do contextualization
125
- if options.context_vars
126
- Occi::Log.debug "with context variables: #{options.context_vars}"
127
-
128
- options.context_vars.each_pair do |var, val|
129
- schema = nil
130
- mxn_attrs = Occi::Core::Attributes.new
131
-
132
- case var
133
- when :public_key
134
- schema = "http://schemas.openstack.org/instance/credentials#"
135
- mxn_attrs['org.openstack.credentials.publickey.name'] = {}
136
- mxn_attrs['org.openstack.credentials.publickey.data'] = {}
137
- when :user_data
138
- schema = "http://schemas.openstack.org/compute/instance#"
139
- mxn_attrs['org.openstack.compute.user_data'] = {}
140
- else
141
- schema = "http://schemas.ogf.org/occi/core#"
142
- end
143
-
144
- mxn = Occi::Core::Mixin.new(schema, var.to_s, 'OS contextualization mixin', mxn_attrs)
145
- res.mixins << mxn
146
-
147
- case var
148
- when :public_key
149
- res.attributes['org.openstack.credentials.publickey.name'] = 'Public SSH key'
150
- res.attributes['org.openstack.credentials.publickey.data'] = val
151
- when :user_data
152
- res.attributes['org.openstack.compute.user_data'] = val
153
- else
154
- # do nothing
155
- end
156
- end
157
- end
158
- end
93
+ helper_attach_links(options, res)
94
+ helper_attach_mixins(options, res)
95
+ helper_attach_context_vars(options, res)
159
96
 
160
97
  # TODO: set other attributes
161
98
  # TODO: OCCI-OS uses occi.compute.hostname instead of title
@@ -175,6 +112,80 @@ module Occi::Cli
175
112
  puts location
176
113
  end
177
114
 
115
+ def helper_attach_links(options, res)
116
+ return unless options.links
117
+ Occi::Log.debug "with links: #{options.links}"
118
+
119
+ options.links.each do |link|
120
+ if link.start_with? options.endpoint
121
+ link.gsub!(options.endpoint.chomp('/'), '')
122
+ end
123
+
124
+ if link.include? "/storage/"
125
+ Occi::Log.debug "Adding storagelink to #{options.resource}"
126
+ res.storagelink link
127
+ elsif link.include? "/network/"
128
+ Occi::Log.debug "Adding networkinterface to #{options.resource}"
129
+ res.networkinterface link
130
+ else
131
+ raise "Unknown link type #{link}, stopping here!"
132
+ end
133
+ end
134
+ end
135
+
136
+ def helper_attach_mixins(options, res)
137
+ return unless options.mixins
138
+ Occi::Log.debug "with mixins: #{options.mixins}"
139
+
140
+ options.mixins.keys.each do |type|
141
+ Occi::Log.debug "Adding mixins of type #{type} to #{options.resource}"
142
+
143
+ options.mixins[type].each do |name|
144
+ mxn = mixin name, type
145
+
146
+ raise "Unknown mixin #{type}##{name}, stopping here!" unless mxn
147
+ Occi::Log.debug "Adding mixin #{mxn} to #{options.resource}"
148
+ res.mixins << mxn
149
+ end
150
+ end
151
+ end
152
+
153
+ def helper_attach_context_vars(options, res)
154
+ # TODO: find a better/universal way to do contextualization
155
+ return unless options.context_vars
156
+ Occi::Log.debug "with context variables: #{options.context_vars}"
157
+
158
+ options.context_vars.each_pair do |var, val|
159
+ schema = nil
160
+ mxn_attrs = Occi::Core::Attributes.new
161
+
162
+ case var
163
+ when :public_key
164
+ schema = "http://schemas.openstack.org/instance/credentials#"
165
+ mxn_attrs['org.openstack.credentials.publickey.name'] = {}
166
+ mxn_attrs['org.openstack.credentials.publickey.data'] = {}
167
+ when :user_data
168
+ schema = "http://schemas.openstack.org/compute/instance#"
169
+ mxn_attrs['org.openstack.compute.user_data'] = {}
170
+ else
171
+ schema = "http://schemas.ogf.org/occi/core#"
172
+ end
173
+
174
+ mxn = Occi::Core::Mixin.new(schema, var.to_s, 'OS contextualization mixin', mxn_attrs)
175
+ res.mixins << mxn
176
+
177
+ case var
178
+ when :public_key
179
+ res.attributes['org.openstack.credentials.publickey.name'] = 'Public SSH key'
180
+ res.attributes['org.openstack.credentials.publickey.data'] = val
181
+ when :user_data
182
+ res.attributes['org.openstack.compute.user_data'] = val
183
+ else
184
+ # do nothing
185
+ end
186
+ end
187
+ end
188
+
178
189
  def helper_delete(options, output = nil)
179
190
  if delete(options.resource)
180
191
  Occi::Log.info "Resource #{options.resource} successfully removed!"
@@ -188,5 +199,14 @@ module Occi::Cli
188
199
  def helper_trigger(options, output = nil)
189
200
  raise "Not yet implemented!"
190
201
  end
202
+
203
+ def helper_formatter_output(found, output, format_symbol, resource_type)
204
+ if Occi::Cli::ResourceOutputFactory.allowed_resource_types.include? resource_type
205
+ puts output.format(found, format_symbol, resource_type)
206
+ else
207
+ Occi::Log.warn "Not printing, resource type [#{resource_type.to_s}] is not supported!"
208
+ end
209
+ end
210
+
191
211
  end
192
212
  end
@@ -1,5 +1,5 @@
1
1
  module Occi
2
2
  module Cli
3
- VERSION = "4.0.0.beta.2" unless defined?(::Occi::Cli::VERSION)
3
+ VERSION = "4.0.0" unless defined?(::Occi::Cli::VERSION)
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta.2
5
- prerelease: 6
4
+ version: 4.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Feldhaus
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-08-01 00:00:00.000000000 Z
14
+ date: 2013-08-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: occi-api
@@ -245,9 +245,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
245
  required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  none: false
247
247
  requirements:
248
- - - ! '>'
248
+ - - ! '>='
249
249
  - !ruby/object:Gem::Version
250
- version: 1.3.1
250
+ version: '0'
251
251
  requirements: []
252
252
  rubyforge_project:
253
253
  rubygems_version: 1.8.25