occi-cli 4.0.0.alpha.1 → 4.0.0.alpha.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/Gemfile CHANGED
@@ -10,3 +10,7 @@ end
10
10
  platforms :jruby do
11
11
  gem 'jruby-openssl' if ((defined? JRUBY_VERSION) && (JRUBY_VERSION.split('.')[1].to_i < 7))
12
12
  end
13
+
14
+ platforms :ruby_18 do
15
+ gem 'oniguruma'
16
+ end
data/bin/occi CHANGED
@@ -41,8 +41,6 @@ Occi::Log.debug "Options: #{options}"
41
41
  if options.auth[:password].nil? || options.auth[:user_cert_password].nil?
42
42
  Occi::Log.debug "Password is not set, asking for it now ..."
43
43
 
44
- say("\n")
45
-
46
44
  options.auth[:user_cert_password] = ask("Enter a password: ") {
47
45
  |q| q.echo = false
48
46
  } unless options.auth[:type] == "none" || (options.auth[:voms] && options.auth[:type] == "x509")
@@ -244,7 +242,7 @@ begin
244
242
 
245
243
  options.mixins = {}
246
244
  (1..number_of_mixins).each do |mixin_number|
247
- mixin = ask("What mixin should I mix in? ") { |q| q.validate = /\A\w+#\w+\Z/ }
245
+ mixin = ask("What mixin should I mix in? ") { |q| q.validate = /^\S+?#\S+$/ }
248
246
  parts = mixin.split("#")
249
247
 
250
248
  options.mixins[parts[0]] = [] if options.mixins[parts[0]].nil?
@@ -203,9 +203,10 @@ occi --endpoint https://localhost:3300/ --action delete --resource /compute/65sd
203
203
  "--mixin NAME",
204
204
  String,
205
205
  "Type and name of the mixin as TYPE#NAME (e.g. os_tpl#monitoring, resource_tpl#medium)") do |mixin|
206
- parts = mixin.split("#")
206
+ parts = /^(\S+?)#(\S+)$/.match(mixin)
207
+ raise "Unknown mixin format! Use TYPE#NAME!" unless parts
207
208
 
208
- raise "Unknown mixin format! Use TYPE#NAME!" unless parts.length == 2
209
+ parts = parts.to_a.drop(1)
209
210
 
210
211
  options.mixins = {} if options.mixins.nil?
211
212
  options.mixins[parts[0]] = [] if options.mixins[parts[0]].nil?
@@ -282,7 +283,13 @@ occi --endpoint https://localhost:3300/ --action delete --resource /compute/65sd
282
283
  if @@quiet
283
284
  exit true
284
285
  else
285
- puts Occi::Cli::VERSION
286
+ if options.debug
287
+ puts "CLI: #{Occi::Cli::VERSION}"
288
+ puts "API: #{Occi::Api::VERSION}"
289
+ puts "Core: #{Occi::VERSION}"
290
+ else
291
+ puts Occi::Cli::VERSION
292
+ end
286
293
  exit! true
287
294
  end
288
295
  end
@@ -5,7 +5,7 @@ module Occi::Cli
5
5
 
6
6
  class ResourceOutputFactory
7
7
 
8
- @@allowed_formats = [:json, :plain].freeze
8
+ @@allowed_formats = [:json, :plain, :json_pretty].freeze
9
9
  @@allowed_resource_types = [:compute, :storage, :network, :os_tpl, :resource_tpl].freeze
10
10
  @@allowed_data_types = [:locations, :resources].freeze
11
11
 
@@ -31,7 +31,7 @@ module Occi::Cli
31
31
  # construct method name from data type and output format
32
32
  method = (data_type.to_s + "_to_" + output_format.to_s).to_sym
33
33
 
34
- ResourceOutputFactory.send method, data, resource_type
34
+ send method, data, resource_type
35
35
  end
36
36
 
37
37
  def self.allowed_formats
@@ -46,27 +46,41 @@ module Occi::Cli
46
46
  @@allowed_data_types
47
47
  end
48
48
 
49
- def self.resources_to_json(occi_resources, resource_type)
50
- # generate JSON document from an array of JSON objects
51
- JSON.generate occi_resources
49
+ def resources_to_json(occi_resources, resource_type)
50
+ # generate JSON document from an array of JSON objects
51
+ if @output_format == :json_pretty
52
+ JSON.pretty_generate occi_resources
53
+ else
54
+ JSON.generate occi_resources
55
+ end
52
56
  end
57
+ alias_method :resources_to_json_pretty, :resources_to_json
53
58
 
54
- def self.resources_to_plain(occi_resources, resource_type)
59
+ def resources_to_plain(occi_resources, resource_type)
55
60
  # using ERB templates for known resource and mixin types
56
- file = File.expand_path("..", __FILE__) + '/templates/' + resource_type.to_s + ".erb"
57
- template = ERB.new File.new(file).read
61
+ file = "#{File.expand_path('..', __FILE__)}/templates/#{resource_type.to_s}.erb"
62
+ template = ERB.new(File.new(file).read, nil, '-')
58
63
 
59
- formatted_output = ""
64
+ formatted_output = "\n"
60
65
 
61
66
  occi_resources.each do |occi_resource|
62
67
  json_resource = occi_resource.as_json
63
- formatted_output << template.result(binding) unless json_resource.nil? || json_resource.empty?
68
+ next unless json_resource
69
+
70
+ if json_resource.resources && json_resource.resources.first
71
+ attributes = json_resource.resources.first.attributes
72
+ next unless attributes && attributes.occi
73
+
74
+ links = json_resource.links || []
75
+ end
76
+
77
+ formatted_output << template.result(binding)
64
78
  end
65
79
 
66
80
  formatted_output
67
81
  end
68
82
 
69
- def self.locations_to_json(url_locations, resource_type)
83
+ def locations_to_json(url_locations, resource_type)
70
84
  # give all locatios a common key and convert to JSON
71
85
  locations = { resource_type => [] }
72
86
 
@@ -75,19 +89,25 @@ module Occi::Cli
75
89
  locations[resource_type] << location
76
90
  end
77
91
 
78
- locations.to_json
92
+ # generate JSON document from an array of strings
93
+ if @output_format == :json_pretty
94
+ JSON.pretty_generate locations
95
+ else
96
+ JSON.generate locations
97
+ end
79
98
  end
99
+ alias_method :locations_to_json_pretty, :locations_to_json
80
100
 
81
- def self.locations_to_plain(url_locations, resource_type)
101
+ def locations_to_plain(url_locations, resource_type)
82
102
  # just an attempt to make the array more readable
83
- output = "\n" + resource_type.to_s.capitalize + " locations:\n"
103
+ output = "\n#{resource_type.to_s.capitalize} locations:\n"
84
104
 
85
105
  url_locations.each do |location|
86
106
  location = location.split("/").last if [:os_tpl, :resource_tpl].include? resource_type
87
107
  output << "\t" << location << "\n"
88
108
  end
89
109
 
90
- output
110
+ "#{output}\n"
91
111
  end
92
112
 
93
113
  end
@@ -1,18 +1,22 @@
1
- <%# We always get a JSON %>
1
+ <%- # We always get a JSON -%>
2
2
  COMPUTE:
3
- ID: <%= json_resource.resources.first.attributes.occi.core.id %>
4
- TITLE: <%= json_resource.resources.first.attributes.occi.core.title %>
5
- STATE: <%= json_resource.resources.first.attributes.occi.compute.state %>
3
+ ID: <%= attributes.occi.core.id %>
4
+ TITLE: <%= attributes.occi.core.title || attributes.occi.compute.hostname %>
5
+ STATE: <%= attributes.occi.compute.state %>
6
+ MEMORY: <%= attributes.occi.compute.memory %> GB
7
+ CORES: <%= attributes.occi.compute.cores %>
6
8
  LINKS:
7
- <% if json_resource.links %><% json_resource.links.each do |link| %>
9
+ <%- links.each do |link| -%>
10
+ <%- next unless link && link.attributes -%>
11
+
8
12
  LINK "<%= link.kind %>":
9
13
  ID: <%= link.attributes.occi.core.id %>
10
- TITLE: <%= link.attributes.occi.core.title %>
14
+ TITLE: <%= link.attributes.occi.core.title || link.target.split('/').last %>
11
15
  TARGET: <%= link.target %>
12
16
  <% if link.attributes.occi.networkinterface %>
13
17
  IP ADDRESS: <%= link.attributes.occi.networkinterface.address %>
14
18
  MAC ADDRESS: <%= link.attributes.occi.networkinterface.mac %>
15
19
  <% elsif link.attributes.occi.storagelink %>
16
20
  MOUNT POINT: <%= link.attributes.occi.storagelink.deviceid %>
17
- <% end %>
18
- <% end %><% end %>
21
+ <%- end -%>
22
+ <% end if links %>
@@ -1,9 +1,8 @@
1
- <%# We always get a JSON %>
1
+ <%- # We always get a JSON -%>
2
2
  NETWORK:
3
- ID: <%= json_resource.resources.first.attributes.occi.core.id %>
4
- TITLE: <%= json_resource.resources.first.attributes.occi.core.title %>
5
- STATE: <%= json_resource.resources.first.attributes.occi.network.state %>
6
- ALLOCATION: <%= json_resource.resources.first.attributes.occi.network.allocation %>
7
- ADDRESS: <%= json_resource.resources.first.attributes.occi.network.address %>
8
-
3
+ ID: <%= attributes.occi.core.id %>
4
+ TITLE: <%= attributes.occi.core.title || attributes.occi.network.label %>
5
+ STATE: <%= attributes.occi.network.state %>
6
+ ALLOCATION: <%= attributes.occi.network.allocation || (attributes.occi.networkinterface && attributes.occi.networkinterface.allocation) %>
7
+ ADDRESS: <%= attributes.occi.network.address || (attributes.occi.networkinterface && attributes.occi.networkinterface.address) %>
9
8
 
@@ -1,7 +1,6 @@
1
- <%# We always get a JSON %>
1
+ <%- # We always get a JSON -%>
2
2
  OS_TPL:
3
3
  TITLE: <%= json_resource.title %>
4
4
  TERM: <%= json_resource.term %>
5
5
  LOCATION: <%= json_resource.location %>
6
6
 
7
-
@@ -1,7 +1,6 @@
1
- <%# We always get a JSON %>
1
+ <%- # We always get a JSON -%>
2
2
  RESOURCE_TPL:
3
3
  TITLE: <%= json_resource.title %>
4
4
  TERM: <%= json_resource.term %>
5
5
  LOCATION: <%= json_resource.location %>
6
6
 
7
-
@@ -1,8 +1,7 @@
1
- <%# We always get a JSON %>
1
+ <%- # We always get a JSON -%>
2
2
  STORAGE:
3
- ID: <%= json_resource.resources.first.attributes.occi.core.id %>
4
- TITLE: <%= json_resource.resources.first.attributes.occi.core.title %>
5
- STATE: <%= json_resource.resources.first.attributes.occi.storage.state%>
6
- DESCRIPTION: <%= json_resource.resources.first.attributes.occi.core.summary %>
7
-
3
+ ID: <%= attributes.occi.core.id %>
4
+ TITLE: <%= attributes.occi.core.title %>
5
+ STATE: <%= attributes.occi.storage.state%>
6
+ DESCRIPTION: <%= attributes.occi.core.summary %>
8
7
 
@@ -1,5 +1,5 @@
1
1
  module Occi
2
2
  module Cli
3
- VERSION = "4.0.0.alpha.1" unless defined?(::Occi::Cli::VERSION)
3
+ VERSION = "4.0.0.alpha.2" unless defined?(::Occi::Cli::VERSION)
4
4
  end
5
5
  end
data/occi-cli.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.description = %q{OCCI is a collection of classes to simplify the implementation of the Open Cloud Computing API in Ruby}
13
13
  gem.summary = %q{OCCI toolkit}
14
14
  gem.homepage = 'https://github.com/gwdg/rOCCI-cli'
15
+ gem.license = 'Apache License, Version 2.0'
15
16
 
16
17
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
18
  gem.files = `git ls-files`.split("\n")
@@ -21,6 +22,7 @@ Gem::Specification.new do |gem|
21
22
 
22
23
  gem.add_dependency 'occi-api'
23
24
  gem.add_dependency 'highline'
25
+ gem.add_dependency 'json'
24
26
 
25
27
  gem.add_development_dependency "rspec"
26
28
  gem.add_development_dependency "rake"
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.1
4
+ version: 4.0.0.alpha.2
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-10 00:00:00.000000000 Z
14
+ date: 2013-07-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: occi-api
@@ -45,6 +45,22 @@ dependencies:
45
45
  - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: json
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
48
64
  - !ruby/object:Gem::Dependency
49
65
  name: rspec
50
66
  requirement: !ruby/object:Gem::Requirement
@@ -214,7 +230,8 @@ files:
214
230
  - spec/occi/cli/resource_output_factory_spec.rb
215
231
  - spec/spec_helper.rb
216
232
  homepage: https://github.com/gwdg/rOCCI-cli
217
- licenses: []
233
+ licenses:
234
+ - Apache License, Version 2.0
218
235
  post_install_message:
219
236
  rdoc_options: []
220
237
  require_paths: