occi 2.5.19 → 3.0.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/.gitignore +4 -0
  2. data/.travis.yml +3 -1
  3. data/AUTHORS +4 -3
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +64 -21
  6. data/README.md +19 -14
  7. data/Rakefile +12 -8
  8. data/Test Results - discovery_interface.html +862 -0
  9. data/bin/occi +333 -83
  10. data/examples/dsl_example.rb +6 -6
  11. data/examples/x509auth_example.rb +6 -6
  12. data/features/common/step_definitions/common_steps.rb +32 -0
  13. data/features/occi/core/create/create.feature +17 -0
  14. data/features/occi/core/create/step_definitions/create_steps.rb +0 -0
  15. data/features/occi/core/delete/delete.feature +14 -0
  16. data/features/occi/core/delete/step_definitions/delete_steps.rb +0 -0
  17. data/features/occi/core/discovery_interface/discovery_interface.feature +35 -0
  18. data/features/occi/core/discovery_interface/step_definitions/discovery_interface_steps.rb +19 -0
  19. data/features/occi/core/miscellaneous/miscellaneous.feature +14 -0
  20. data/features/occi/core/miscellaneous/step_definitions/miscellaneous_steps.rb +0 -0
  21. data/features/occi/core/read/read.feature +14 -0
  22. data/features/occi/core/read/step_definitions/read_steps.rb +0 -0
  23. data/features/occi/core/update/step_definitions/update_steps.rb +0 -0
  24. data/features/occi/core/update/update.feature +14 -0
  25. data/features/occi/infrastructure/create/create.feature +14 -0
  26. data/features/occi/infrastructure/create/step_definitions/create_steps.rb +0 -0
  27. data/features/support/env.rb +4 -0
  28. data/lib/occi.rb +29 -3
  29. data/lib/occi/api/client/client_amqp.rb +756 -0
  30. data/lib/occi/api/client/client_http.rb +922 -0
  31. data/lib/occi/api/client/http/httparty_fix.rb +53 -0
  32. data/lib/occi/api/client/http/net_http_fix.rb +46 -0
  33. data/lib/occi/api/dsl.rb +77 -73
  34. data/lib/occi/bin/helpers.rb +91 -0
  35. data/lib/occi/bin/occi_opts.rb +251 -0
  36. data/lib/occi/bin/resource_output_factory.rb +90 -0
  37. data/lib/occi/bin/templates/compute.erb +15 -0
  38. data/lib/occi/bin/templates/network.erb +11 -0
  39. data/lib/occi/bin/templates/os_tpl.erb +9 -0
  40. data/lib/occi/bin/templates/resource_tpl.erb +9 -0
  41. data/lib/occi/bin/templates/storage.erb +10 -0
  42. data/lib/occi/collection.rb +122 -25
  43. data/lib/occi/core.rb +18 -9
  44. data/lib/occi/core/action.rb +20 -4
  45. data/lib/occi/core/action_instance.rb +24 -0
  46. data/lib/occi/core/actions.rb +22 -0
  47. data/lib/occi/core/attribute_properties.rb +33 -84
  48. data/lib/occi/core/attributes.rb +32 -14
  49. data/lib/occi/core/categories.rb +46 -0
  50. data/lib/occi/core/category.rb +94 -20
  51. data/lib/occi/core/entities.rb +50 -0
  52. data/lib/occi/core/entity.rb +130 -89
  53. data/lib/occi/core/kind.rb +28 -35
  54. data/lib/occi/core/kinds.rb +22 -0
  55. data/lib/occi/core/link.rb +43 -40
  56. data/lib/occi/core/links.rb +34 -0
  57. data/lib/occi/core/mixin.rb +28 -23
  58. data/lib/occi/core/mixins.rb +22 -0
  59. data/lib/occi/core/related.rb +20 -0
  60. data/lib/occi/core/resource.rb +40 -40
  61. data/lib/occi/core/resources.rb +14 -0
  62. data/lib/occi/infrastructure.rb +27 -0
  63. data/lib/occi/infrastructure/compute.rb +159 -0
  64. data/lib/occi/infrastructure/network.rb +131 -0
  65. data/lib/occi/infrastructure/network/ipnetwork.rb +34 -0
  66. data/lib/occi/infrastructure/networkinterface.rb +124 -0
  67. data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +34 -0
  68. data/lib/occi/infrastructure/os_tpl.rb +19 -0
  69. data/lib/occi/infrastructure/resource_tpl.rb +19 -0
  70. data/lib/occi/infrastructure/storage.rb +96 -0
  71. data/lib/occi/infrastructure/storagelink.rb +73 -0
  72. data/lib/occi/log.rb +6 -2
  73. data/lib/occi/model.rb +38 -70
  74. data/lib/occi/parser.rb +108 -88
  75. data/lib/occi/version.rb +2 -2
  76. data/lib/occiantlr/OCCIANTLR.g +6 -5
  77. data/lib/occiantlr/OCCIANTLRLexer.rb +52 -52
  78. data/lib/occiantlr/OCCIANTLRParser.rb +678 -569
  79. data/lib/occiantlr/README.md +1 -1
  80. data/occi.gemspec +2 -1
  81. data/spec/cassettes/client_http_text_plain.yml +1066 -0
  82. data/spec/occi/api/client/client_amqp_spec.rb +148 -0
  83. data/spec/occi/api/client/client_http_0.5_spec.rb +292 -0
  84. data/spec/occi/api/client/client_http_spec.rb +259 -0
  85. data/spec/occi/api/dsl_spec.rb +0 -0
  86. data/spec/occi/collection_spec.rb +23 -10
  87. data/spec/occi/core/categories_spec.rb +30 -0
  88. data/spec/occi/core/category_spec.rb +41 -0
  89. data/spec/occi/core/entity_spec.rb +52 -0
  90. data/spec/occi/core/resource_spec.rb +21 -0
  91. data/spec/occi/infrastructure/compute_spec.rb +32 -0
  92. data/spec/occi/log_spec.rb +10 -10
  93. data/spec/occi/model_spec.rb +24 -24
  94. data/spec/occi/parser_spec.rb +89 -39
  95. data/spec/occi/test.json +22 -58
  96. data/spec/occiantlr/parser_spec.rb +5 -7
  97. data/spec/spec_helper.rb +13 -3
  98. metadata +116 -19
  99. data/etc/model/infrastructure/compute.json +0 -108
  100. data/etc/model/infrastructure/ipnetwork.json +0 -40
  101. data/etc/model/infrastructure/ipnetworkinterface.json +0 -40
  102. data/etc/model/infrastructure/network.json +0 -55
  103. data/etc/model/infrastructure/networkinterface.json +0 -38
  104. data/etc/model/infrastructure/os_template.json +0 -9
  105. data/etc/model/infrastructure/resource_template.json +0 -9
  106. data/etc/model/infrastructure/storage.json +0 -72
  107. data/etc/model/infrastructure/storagelink.json +0 -38
  108. data/lib/occi/api/client.rb +0 -596
  109. data/lib/occi/client/occiopts.rb +0 -146
  110. data/spec/occi/client_spec.rb +0 -12
@@ -0,0 +1,53 @@
1
+ module HTTParty
2
+ class ConnectionAdapter
3
+
4
+ private
5
+
6
+ def attach_ssl_certificates(http, options)
7
+ if http.use_ssl?
8
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
9
+
10
+ # Client certificate authentication
11
+ if options[:pem]
12
+ http.cert = OpenSSL::X509::Certificate.new(options[:pem])
13
+ http.key = OpenSSL::PKey::RSA.new(options[:pem], options[:pem_password])
14
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
15
+ end
16
+
17
+ # Set chain of client certificates
18
+ if options[:ssl_extra_chain_cert]
19
+ http.extra_chain_cert = []
20
+
21
+ options[:ssl_extra_chain_cert].each do |p_ca|
22
+ http.extra_chain_cert << OpenSSL::X509::Certificate.new(p_ca)
23
+ end
24
+ end
25
+
26
+ # SSL certificate authority file and/or directory
27
+ if options[:ssl_ca_file]
28
+ http.ca_file = options[:ssl_ca_file]
29
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
30
+ end
31
+
32
+ if options[:ssl_ca_path]
33
+ http.ca_path = options[:ssl_ca_path]
34
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
35
+ end
36
+
37
+ # This is only Ruby 1.9+
38
+ if options[:ssl_version] && http.respond_to?(:ssl_version=)
39
+ http.ssl_version = options[:ssl_version]
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ module ClassMethods
47
+
48
+ def ssl_extra_chain_cert(ary_of_certs)
49
+ default_options[:ssl_extra_chain_cert] = ary_of_certs
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,46 @@
1
+ ##############################################################################
2
+ ## Net::HTTP hack allowing the use of X.509 proxy certificates.
3
+ ##############################################################################
4
+
5
+ # When running Ruby 1.8.x, RUBY_ENGINE is not defined
6
+ RUBY_ENGINE = "ruby" unless defined? RUBY_ENGINE
7
+
8
+ # detect jRuby
9
+ if RUBY_ENGINE == 'jruby'
10
+ #TODO: add jRuby support, this doesn't work
11
+ module Net
12
+ class HTTP
13
+
14
+ SSL_ATTRIBUTES = SSL_ATTRIBUTES.concat %w(extra_chain_cert)
15
+
16
+ # An Array of certificates that will be sent to the client.
17
+ attr_accessor :extra_chain_cert
18
+
19
+ end
20
+ end
21
+ else
22
+ net_http_fix_rby_ver = RUBY_VERSION.split('.')
23
+
24
+ # detect old Rubies, tested with 1.8.7-p371
25
+ if net_http_fix_rby_ver[1] == "8"
26
+ module Net
27
+ class HTTP
28
+
29
+ # An Array of certificates that will be sent to the client.
30
+ ssl_context_accessor :extra_chain_cert
31
+
32
+ end
33
+ end
34
+ else
35
+ module Net
36
+ class HTTP
37
+
38
+ SSL_ATTRIBUTES = SSL_ATTRIBUTES.concat %w(extra_chain_cert)
39
+
40
+ # An Array of certificates that will be sent to the client.
41
+ attr_accessor :extra_chain_cert
42
+
43
+ end
44
+ end
45
+ end
46
+ end
data/lib/occi/api/dsl.rb CHANGED
@@ -1,112 +1,116 @@
1
- module OCCI
2
- module DSL
1
+ module Occi
2
+ module Api
3
+ module Dsl
3
4
 
4
- def connect(*args)
5
- @client = OCCI::Client.new(*args)
5
+ def connect(protocol, *args)
6
6
 
7
- true
8
- end
7
+ case protocol
8
+ when :http
9
+ @client = Occi::Api::Client::ClientHttp.new(*args)
10
+ when :amqp
11
+ @client = Occi::Api::Client::ClientAmqp.new(*args)
12
+ else
13
+ raise "Protocol #{protocol.to_s} is not supported!"
14
+ end
9
15
 
10
- def list(*args)
11
- check
16
+ true
17
+ end
12
18
 
13
- @client.list(*args)
14
- end
19
+ def list(*args)
20
+ check
15
21
 
16
- def describe(*args)
17
- check
22
+ @client.list(*args)
23
+ end
18
24
 
19
- @client.describe(*args)
20
- end
25
+ def describe(*args)
26
+ check
21
27
 
22
- def create(*args)
23
- check
28
+ @client.describe(*args)
29
+ end
24
30
 
25
- @client.create(*args)
26
- end
31
+ def create(*args)
32
+ check
27
33
 
28
- def delete(*args)
29
- check
34
+ @client.create(*args)
35
+ end
30
36
 
31
- @client.delete(*args)
32
- end
37
+ def delete(*args)
38
+ check
33
39
 
34
- def trigger(*args)
35
- check
40
+ @client.delete(*args)
41
+ end
36
42
 
37
- @client.trigger(*args)
38
- end
43
+ def trigger(*args)
44
+ check
39
45
 
40
- def refresh
41
- check
46
+ @client.trigger(*args)
47
+ end
42
48
 
43
- @client.refresh
44
- end
49
+ def refresh
50
+ check
45
51
 
46
- def storagelink(*args)
47
- check
52
+ @client.refresh
53
+ end
48
54
 
49
- @client.storagelink(*args)
50
- end
55
+ def model
56
+ check
51
57
 
52
- def networkinterface(*args)
53
- check
58
+ @client.model
59
+ end
54
60
 
55
- @client.networkinterface(*args)
56
- end
61
+ ###
57
62
 
58
- ###
63
+ def resource_types
64
+ check
59
65
 
60
- def resource_types
61
- check
66
+ @client.get_resource_types
67
+ end
62
68
 
63
- @client.get_resource_types
64
- end
69
+ def resource_type_identifiers
70
+ check
65
71
 
66
- def resource_type_identifiers
67
- check
72
+ @client.get_resource_type_identifiers
73
+ end
68
74
 
69
- @client.get_resource_type_identifiers
70
- end
75
+ def mixin_type_identifiers
76
+ check
71
77
 
72
- def mixin_type_identifiers
73
- check
78
+ @client.get_mixin_type_identifiers
79
+ end
74
80
 
75
- @client.get_mixin_type_identifiers
76
- end
81
+ def mixin_types
82
+ check
77
83
 
78
- def mixin_types
79
- check
84
+ @client.get_mixin_types
85
+ end
80
86
 
81
- @client.get_mixin_types
82
- end
87
+ def mixins(*args)
88
+ check
83
89
 
84
- def mixins(*args)
85
- check
90
+ @client.get_mixins(*args)
91
+ end
86
92
 
87
- @client.get_mixins(*args)
88
- end
93
+ ###
89
94
 
90
- ###
95
+ def resource(*args)
96
+ check
91
97
 
92
- def resource(*args)
93
- check
98
+ @client.get_resource(*args)
99
+ end
94
100
 
95
- @client.get_resource(*args)
96
- end
101
+ def mixin(*args)
102
+ check
97
103
 
98
- def mixin(*args)
99
- check
104
+ @client.find_mixin(*args)
105
+ end
100
106
 
101
- @client.find_mixin(*args)
102
- end
107
+ private
103
108
 
104
- private
109
+ def check
110
+ raise "You have to issue 'connect' first!" if @client.nil?
111
+ raise "Client is disconnected!" unless @client.connected
112
+ end
105
113
 
106
- def check
107
- raise "You have to issue 'connect' first!" if @client.nil?
108
- raise "Client is disconnected!" unless @client.connected
109
114
  end
110
-
111
115
  end
112
116
  end
@@ -0,0 +1,91 @@
1
+ # a bunch of OCCI client helpers for bin/occi
2
+
3
+ def helper_list(options)
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.debug "I have no idea what #{options.resource} is ..."
14
+ puts "Unknown resource #{options.resource}, there is nothing to list here!"
15
+ end
16
+
17
+ found
18
+ end
19
+
20
+ def helper_describe(options)
21
+ found = []
22
+
23
+ if resource_types.include? options.resource or options.resource.start_with? options.endpoint
24
+ Occi::Log.debug "#{options.resource} is a resource type or an actual resource."
25
+
26
+ found = describe(options.resource)
27
+ elsif mixin_types.include? options.resource
28
+ Occi::Log.debug "#{options.resourcre} is a mixin type."
29
+
30
+ mixins(options.resource).each do |mxn|
31
+ mxn = mxn.split("#").last
32
+ found << mixin(mxn, options.resource, true)
33
+ end
34
+ elsif mixin_types.include? options.resource.split('#').first
35
+ Occi::Log.debug "#{options.resource} is a specific mixin type."
36
+
37
+ mxn_type,mxn = options.resource.split('#')
38
+ found << mixin(mxn, mxn_type, true)
39
+ else
40
+ Occi::Log.debug "I have no idea what #{options.resource} is ..."
41
+
42
+ puts "Unknown resource #{options.resource}, there is nothing to describe here!"
43
+ end
44
+
45
+ found
46
+ end
47
+
48
+ def helper_create(options)
49
+ location = nil
50
+
51
+ if resource_types.include? options.resource
52
+ Occi::Log.debug "#{options.resource} is a resource type."
53
+ raise "Not yet implemented!" unless options.resource.include? "compute"
54
+
55
+ res = resource options.resource
56
+
57
+ Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"
58
+ Occi::Log.debug "with mixins:#{options.mixin}"
59
+
60
+ options.mixin.keys.each do |type|
61
+ Occi::Log.debug "Adding mixins of type #{type} to #{options.resource}"
62
+ options.mixin[type].each do |name|
63
+ mxn = mixin name, type
64
+
65
+ raise "Unknown mixin #{type}##{name}, stopping here!" if mxn.nil?
66
+ Occi::Log.debug "Adding mixin #{mxn} to #{options.resource}"
67
+ res.mixins << mxn
68
+ end
69
+ end
70
+
71
+ #TODO: set other attributes
72
+ res.title = options.resource_title
73
+
74
+ Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"
75
+
76
+ location = create res
77
+ else
78
+ Occi::Log.debug "I have no idea what #{options.resource} is ..."
79
+ puts "Unknown resource #{options.resource}, there is nothing to create here!"
80
+ end
81
+
82
+ location
83
+ end
84
+
85
+ def helper_delete(options)
86
+ delete options.resource
87
+ end
88
+
89
+ def helper_trigger(options)
90
+ raise "Not yet implemented!"
91
+ end
@@ -0,0 +1,251 @@
1
+ require 'ostruct'
2
+ require 'optparse'
3
+ require 'occi/bin/resource_output_factory'
4
+
5
+ module Occi
6
+ module Bin
7
+
8
+ class OcciOpts
9
+
10
+ AUTH_METHODS = [:x509, :basic, :digest, :keystone, :none].freeze
11
+ MEDIA_TYPES = ["application/occi+json", "application/occi+xml", "text/plain,text/occi", "text/plain"].freeze
12
+ ACTIONS = [:list, :describe, :create, :delete, :trigger].freeze
13
+ LOG_OUTPUTS = [:stdout, :stderr].freeze
14
+
15
+ def self.parse(args)
16
+
17
+ options = OpenStruct.new
18
+
19
+ options.debug = false
20
+ options.verbose = false
21
+
22
+ options.log = {}
23
+ options.log[:out] = STDERR
24
+ options.log[:level] = Occi::Log::WARN
25
+
26
+ options.dump_model = false
27
+
28
+ options.interactive = false
29
+
30
+ options.endpoint = "https://localhost:3300/"
31
+
32
+ options.auth = {}
33
+ options.auth[:type] = "none"
34
+ options.auth[:user_cert] = ENV['HOME'] + "/.globus/usercred.pem"
35
+ options.auth[:ca_path] = "/etc/grid-security/certificates"
36
+ options.auth[:username] = "anonymous"
37
+ options.auth[:ca_file] = nil
38
+
39
+ options.output_format = :plain
40
+
41
+ # TODO: change media type back to occi+json after the rOCCI-server update
42
+ #options.media_type = "application/occi+json"
43
+ options.media_type = "text/plain,text/occi"
44
+
45
+ opts = OptionParser.new do |opts|
46
+ opts.banner = "Usage: occi [OPTIONS]"
47
+
48
+ opts.separator ""
49
+ opts.separator "Options:"
50
+
51
+ opts.on("-i",
52
+ "--interactive",
53
+ "Run as an interactive client without additional arguments") do |interactive|
54
+ options.interactive = interactive
55
+ end
56
+
57
+ opts.on("-e",
58
+ "--endpoint URI",
59
+ String,
60
+ "OCCI server URI, defaults to '#{options.endpoint}'") do |endpoint|
61
+ options.endpoint = endpoint
62
+ end
63
+
64
+ opts.on("-n",
65
+ "--auth METHOD",
66
+ AUTH_METHODS,
67
+ "Authentication method, defaults to '#{options.auth[:type]}'") do |auth|
68
+ options.auth[:type] = auth.to_s
69
+ end
70
+
71
+ opts.on("-u",
72
+ "--username USER",
73
+ String,
74
+ "Username for basic or digest authentication, defaults to '#{options.auth[:username]}'") do |username|
75
+ options.auth[:username] = username
76
+ end
77
+
78
+ opts.on("-p",
79
+ "--password PASSWORD",
80
+ String,
81
+ "Password for basic, digest or x509 authentication") do |password|
82
+ options.auth[:password] = password
83
+ options.auth[:user_cert_password] = password
84
+ end
85
+
86
+ opts.on("-c",
87
+ "--ca-path PATH", String, "Path to CA certificates directory, defaults to '#{options.auth[:ca_path]}'") do |ca_path|
88
+ options.auth[:ca_path] = ca_path
89
+ end
90
+
91
+ opts.on("-f",
92
+ "--ca-file PATH", String, "Path to CA certificates in a file") do |ca_file|
93
+ options.auth[:ca_file] = ca_file
94
+ end
95
+
96
+ opts.on("-x",
97
+ "--user-cred PATH",
98
+ String,
99
+ "Path to user's x509 credentials, defaults to '#{options.auth[:user_cert]}'") do |user_cred|
100
+ options.auth[:user_cert] = user_cred
101
+ end
102
+
103
+ opts.on("-X",
104
+ "--proxy-ca PATH", String, "Path to a file with GSI proxy's CA certificate(s)") do |proxy_ca|
105
+ options.auth[:proxy_ca] = proxy_ca
106
+ end
107
+
108
+ opts.on("-y",
109
+ "--media-type MEDIA_TYPE",
110
+ MEDIA_TYPES,
111
+ "Media type for client <-> server communication, defaults to '#{options.media_type}'") do |media_type|
112
+ options.media_type = media_type
113
+ end
114
+
115
+ opts.on("-r",
116
+ "--resource RESOURCE",
117
+ String,
118
+ "Resource to be queried (e.g. network, compute, storage etc.), required") do |resource|
119
+ options.resource = resource
120
+ end
121
+
122
+ opts.on("-t",
123
+ "--resource-title TITLE",
124
+ String,
125
+ "Resource title for new resources") do |resource_title|
126
+ options.resource_title = resource_title
127
+ end
128
+
129
+ opts.on("-a",
130
+ "--action ACTION",
131
+ ACTIONS,
132
+ "Action to be performed on the resource, required") do |action|
133
+ options.action = action
134
+ end
135
+
136
+ opts.on("-M",
137
+ "--mixin NAME",
138
+ String,
139
+ "Type and name of the mixin as TYPE#NAME (e.g. os_tpl#monitoring, resource_tpl#medium)") do |mixin|
140
+ parts = mixin.split("#")
141
+
142
+ raise "Unknown mixin format! Use TYPE#NAME!" unless parts.length == 2
143
+
144
+ options.mixin = {} if options.mixin.nil?
145
+ options.mixin[parts[0]] = [] if options.mixin[parts[0]].nil?
146
+ options.mixin[parts[0]] << parts[1]
147
+ end
148
+
149
+ opts.on("-g",
150
+ "--trigger-action TRIGGER",
151
+ String,
152
+ "Action to be triggered on the resource") do |trigger_action|
153
+ options.trigger_action = trigger_action
154
+ end
155
+
156
+ opts.on("-l",
157
+ "--log-to OUTPUT",
158
+ LOG_OUTPUTS,
159
+ "Log to the specified device, defaults to 'STDERR'") do |log_to|
160
+ options.log[:out] = STDOUT if log_to == :stdout or log_to == :STDOUT
161
+ end
162
+
163
+ opts.on("-o",
164
+ "--output-format FORMAT",
165
+ Occi::Bin::ResourceOutputFactory.allowed_formats,
166
+ "Output format, defaults to human-readable 'plain'") do |output_format|
167
+ options.output_format = output_format
168
+ end
169
+
170
+ opts.on_tail("-m",
171
+ "--dump-model",
172
+ "Contact the endpoint and dump its model") do |dump_model|
173
+ options.dump_model = dump_model
174
+ end
175
+
176
+ opts.on_tail("-d",
177
+ "--debug",
178
+ "Enable debugging messages") do |debug|
179
+ options.debug = debug
180
+ options.log[:level] = Occi::Log::DEBUG
181
+ end
182
+
183
+ opts.on_tail("-b",
184
+ "--verbose",
185
+ "Be more verbose, less intrusive than debug mode") do |verbose|
186
+ options.verbose = verbose
187
+ options.log[:level] = Occi::Log::INFO unless options.log[:level] == Occi::Log::DEBUG
188
+ end
189
+
190
+ opts.on_tail("-h",
191
+ "--help",
192
+ "Show this message") do
193
+ puts opts
194
+ exit!(true)
195
+ end
196
+
197
+ opts.on_tail("-v",
198
+ "--version",
199
+ "Show version") do
200
+ puts Occi::VERSION
201
+ exit!(true)
202
+ end
203
+
204
+ end
205
+
206
+ begin
207
+ opts.parse!(args)
208
+ rescue Exception => ex
209
+ puts ex.message.capitalize
210
+ puts opts
211
+ exit!
212
+ end
213
+
214
+ if options.interactive && options.dump_model
215
+ puts "You cannot use '--dump-model' and '--interactive' at the same time!"
216
+ puts opts
217
+
218
+ exit!
219
+ end
220
+
221
+ if !(options.interactive or options.dump_model)
222
+ mandatory = []
223
+
224
+ if options.action == :trigger
225
+ mandatory << :trigger_action
226
+ end
227
+
228
+ if options.action == :create
229
+ mandatory << :mixin << :resource_title
230
+ end
231
+
232
+ mandatory.concat [:resource, :action]
233
+
234
+ options_hash = options.marshal_dump
235
+
236
+ missing = mandatory.select{ |param| options_hash[param].nil? }
237
+ if not missing.empty?
238
+ puts "Missing required arguments: #{missing.join(', ')}"
239
+ puts opts
240
+
241
+ exit!
242
+ end
243
+ end
244
+
245
+ options
246
+ end
247
+
248
+ end
249
+
250
+ end
251
+ end