occi 3.1.3 → 4.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. metadata +16 -448
  2. data/.gitignore +0 -15
  3. data/.rspec +0 -1
  4. data/.travis.yml +0 -35
  5. data/.yardopts +0 -1
  6. data/AUTHORS +0 -9
  7. data/Gemfile +0 -13
  8. data/LICENSE +0 -13
  9. data/README.md +0 -471
  10. data/Rakefile +0 -37
  11. data/bin/occi +0 -356
  12. data/config/warble.rb +0 -151
  13. data/doc/macosx.md +0 -27
  14. data/examples/dsl_example.rb +0 -167
  15. data/examples/x509auth_example.rb +0 -161
  16. data/ext/mkrf_conf.rb +0 -30
  17. data/features/cassettes/Create_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
  18. data/features/cassettes/Delete_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
  19. data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__application_json_200_.yml +0 -333
  20. data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__text_plain_200_.yml +0 -529
  21. data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__text_plain_200_action_.yml +0 -288
  22. data/features/cassettes/Miscellaneous_operation_on_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
  23. data/features/cassettes/Read_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
  24. data/features/cassettes/Update_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
  25. data/features/common/step_definitions/common_steps.rb +0 -32
  26. data/features/occi/core/create/create.feature +0 -18
  27. data/features/occi/core/create/step_definitions/create_steps.rb +0 -0
  28. data/features/occi/core/delete/delete.feature +0 -18
  29. data/features/occi/core/delete/step_definitions/delete_steps.rb +0 -0
  30. data/features/occi/core/discovery_interface/discovery_interface.feature +0 -37
  31. data/features/occi/core/discovery_interface/step_definitions/discovery_interface_steps.rb +0 -19
  32. data/features/occi/core/miscellaneous/miscellaneous.feature +0 -18
  33. data/features/occi/core/miscellaneous/step_definitions/miscellaneous_steps.rb +0 -0
  34. data/features/occi/core/read/read.feature +0 -18
  35. data/features/occi/core/read/step_definitions/read_steps.rb +0 -0
  36. data/features/occi/core/update/step_definitions/update_steps.rb +0 -0
  37. data/features/occi/core/update/update.feature +0 -18
  38. data/features/occi/infrastructure/create/create.feature +0 -18
  39. data/features/occi/infrastructure/create/step_definitions/create_steps.rb +0 -0
  40. data/features/support/env.rb +0 -16
  41. data/lib/occi.rb +0 -57
  42. data/lib/occi/api/client/client_amqp.rb +0 -767
  43. data/lib/occi/api/client/client_http.rb +0 -1100
  44. data/lib/occi/api/client/http/authn_utils.rb +0 -82
  45. data/lib/occi/api/client/http/httparty_fix.rb +0 -53
  46. data/lib/occi/api/client/http/net_http_fix.rb +0 -21
  47. data/lib/occi/api/dsl.rb +0 -146
  48. data/lib/occi/bin/helpers.rb +0 -149
  49. data/lib/occi/bin/occi_opts.rb +0 -384
  50. data/lib/occi/bin/resource_output_factory.rb +0 -97
  51. data/lib/occi/bin/templates/compute.erb +0 -18
  52. data/lib/occi/bin/templates/network.erb +0 -9
  53. data/lib/occi/bin/templates/os_tpl.erb +0 -7
  54. data/lib/occi/bin/templates/resource_tpl.erb +0 -7
  55. data/lib/occi/bin/templates/storage.erb +0 -8
  56. data/lib/occi/collection.rb +0 -186
  57. data/lib/occi/core.rb +0 -30
  58. data/lib/occi/core/action.rb +0 -32
  59. data/lib/occi/core/action_instance.rb +0 -24
  60. data/lib/occi/core/actions.rb +0 -22
  61. data/lib/occi/core/attribute_properties.rb +0 -52
  62. data/lib/occi/core/attributes.rb +0 -61
  63. data/lib/occi/core/categories.rb +0 -54
  64. data/lib/occi/core/category.rb +0 -149
  65. data/lib/occi/core/entities.rb +0 -50
  66. data/lib/occi/core/entity.rb +0 -246
  67. data/lib/occi/core/kind.rb +0 -58
  68. data/lib/occi/core/kinds.rb +0 -22
  69. data/lib/occi/core/link.rb +0 -100
  70. data/lib/occi/core/links.rb +0 -34
  71. data/lib/occi/core/mixin.rb +0 -55
  72. data/lib/occi/core/mixins.rb +0 -22
  73. data/lib/occi/core/related.rb +0 -20
  74. data/lib/occi/core/resource.rb +0 -76
  75. data/lib/occi/core/resources.rb +0 -14
  76. data/lib/occi/infrastructure.rb +0 -27
  77. data/lib/occi/infrastructure/compute.rb +0 -159
  78. data/lib/occi/infrastructure/network.rb +0 -131
  79. data/lib/occi/infrastructure/network/ipnetwork.rb +0 -34
  80. data/lib/occi/infrastructure/networkinterface.rb +0 -124
  81. data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +0 -34
  82. data/lib/occi/infrastructure/os_tpl.rb +0 -19
  83. data/lib/occi/infrastructure/resource_tpl.rb +0 -19
  84. data/lib/occi/infrastructure/storage.rb +0 -96
  85. data/lib/occi/infrastructure/storagelink.rb +0 -73
  86. data/lib/occi/log.rb +0 -66
  87. data/lib/occi/model.rb +0 -86
  88. data/lib/occi/parser.rb +0 -413
  89. data/lib/occi/version.rb +0 -3
  90. data/lib/occiantlr/.gitignore +0 -18
  91. data/lib/occiantlr/OCCIANTLR.g +0 -191
  92. data/lib/occiantlr/OCCIANTLR.tokens +0 -57
  93. data/lib/occiantlr/OCCIANTLRLexer.rb +0 -1868
  94. data/lib/occiantlr/OCCIANTLRParser.rb +0 -2906
  95. data/lib/occiantlr/README.md +0 -2
  96. data/occi.gemspec +0 -45
  97. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_compute_resource.yml +0 -266
  98. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_network_resource.yml +0 -266
  99. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_storage_resource.yml +0 -266
  100. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_compute_resource.yml +0 -266
  101. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_network_resource.yml +0 -266
  102. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_storage_resource.yml +0 -266
  103. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deploys_an_instance_based_on_OVF_OVA_file.yml +0 -266
  104. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_all_available_mixins.yml +0 -266
  105. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_compute_resources.yml +0 -368
  106. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_network_resources.yml +0 -370
  107. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_os_tpl_mixins.yml +0 -266
  108. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_resource_tpl_mixins.yml +0 -266
  109. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_storage_resources.yml +0 -430
  110. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/establishes_connection.yml +0 -266
  111. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_compute_resource_using_type_identifier.yml +0 -266
  112. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_compute_resource_using_type_name.yml +0 -266
  113. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_network_resource_using_type_identifier.yml +0 -266
  114. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_network_resource_using_type_name.yml +0 -266
  115. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_storage_resource_using_type_identifier.yml +0 -266
  116. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_storage_resource_using_type_name.yml +0 -266
  117. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_entity_type_identifiers.yml +0 -266
  118. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_entity_types.yml +0 -266
  119. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_link_type_identifiers.yml +0 -266
  120. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_link_types.yml +0 -266
  121. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixin_type_identifiers.yml +0 -266
  122. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixin_types.yml +0 -266
  123. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixins.yml +0 -266
  124. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_resource_type_identifiers.yml +0 -266
  125. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_resource_types.yml +0 -266
  126. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_compute_resources.yml +0 -308
  127. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_network_resources.yml +0 -308
  128. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_os_tpl_mixins.yml +0 -266
  129. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_resource_tpl_mixins.yml +0 -266
  130. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_storage_resources.yml +0 -310
  131. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/refreshes_its_model.yml +0 -485
  132. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_compute_resource.yml +0 -266
  133. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_network_resource.yml +0 -266
  134. data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_storage_resource.yml +0 -266
  135. data/spec/occi/api/client/client_amqp_spec.rb +0 -159
  136. data/spec/occi/api/client/client_http_spec.rb +0 -253
  137. data/spec/occi/api/client/http/authn_utils_spec.rb +0 -55
  138. data/spec/occi/api/client/http/httparty_fix_spec.rb +0 -0
  139. data/spec/occi/api/client/http/net_http_fix_spec.rb +0 -0
  140. data/spec/occi/api/client/http/rocci-cred-cert.pem +0 -3
  141. data/spec/occi/api/client/http/rocci-cred-key-jruby.pem +0 -3
  142. data/spec/occi/api/client/http/rocci-cred-key.pem +0 -3
  143. data/spec/occi/api/client/http/rocci-cred.p12 +0 -0
  144. data/spec/occi/api/dsl_spec.rb +0 -22
  145. data/spec/occi/bin/helpers_spec.rb +0 -12
  146. data/spec/occi/bin/occi_opts_spec.rb +0 -60
  147. data/spec/occi/bin/resource_output_factory_spec.rb +0 -12
  148. data/spec/occi/collection_spec.rb +0 -41
  149. data/spec/occi/core/categories_spec.rb +0 -30
  150. data/spec/occi/core/category_spec.rb +0 -41
  151. data/spec/occi/core/entity_spec.rb +0 -52
  152. data/spec/occi/core/resource_spec.rb +0 -21
  153. data/spec/occi/infrastructure/compute_spec.rb +0 -32
  154. data/spec/occi/log_spec.rb +0 -17
  155. data/spec/occi/model_spec.rb +0 -51
  156. data/spec/occi/parser_spec.rb +0 -114
  157. data/spec/occi/test.json +0 -33
  158. data/spec/occi/test.ova +0 -0
  159. data/spec/occi/test.ovf +0 -198
  160. data/spec/occiantlr/parser_spec.rb +0 -82
  161. data/spec/spec_helper.rb +0 -43
@@ -1,384 +0,0 @@
1
- require 'ostruct'
2
- require 'optparse'
3
- require 'uri'
4
-
5
- require 'occi/bin/resource_output_factory'
6
-
7
- module Occi
8
- module Bin
9
-
10
- class OcciOpts
11
-
12
- AUTH_METHODS = [:x509, :basic, :digest, :keystone, :none].freeze
13
- MEDIA_TYPES = ["application/occi+json", "application/occi+xml", "text/plain,text/occi", "text/plain"].freeze
14
- ACTIONS = [:list, :describe, :create, :delete, :trigger].freeze
15
- LOG_OUTPUTS = [:stdout, :stderr].freeze
16
-
17
- def self.parse(args, test_env = false)
18
-
19
- @@quiet = test_env
20
-
21
- options = OpenStruct.new
22
-
23
- options.debug = false
24
- options.verbose = false
25
-
26
- options.log = {}
27
- options.log[:out] = STDERR
28
- options.log[:level] = Occi::Log::WARN
29
-
30
- options.filter = nil
31
- options.dump_model = false
32
-
33
- options.interactive = false
34
-
35
- options.endpoint = "https://localhost:3300/"
36
-
37
- options.auth = {}
38
- options.auth[:type] = "none"
39
- options.auth[:user_cert] = ENV['HOME'] + "/.globus/usercred.pem"
40
- options.auth[:ca_path] = "/etc/grid-security/certificates"
41
- options.auth[:username] = "anonymous"
42
- options.auth[:ca_file] = nil
43
- options.auth[:proxy_ca] = nil
44
-
45
- options.output_format = :plain
46
-
47
- options.mixins = nil
48
- options.links = nil
49
- options.attributes = nil
50
- options.context_vars = nil
51
-
52
- # TODO: change media type back to occi+json after the rOCCI-server update
53
- #options.media_type = "application/occi+json"
54
- options.media_type = "text/plain,text/occi"
55
-
56
- opts = OptionParser.new do |opts|
57
- opts.banner = %{Usage: occi [OPTIONS]
58
-
59
- Examples:
60
- occi --interactive --endpoint https://localhost:3300/ --auth x509
61
-
62
- occi --endpoint https://localhost:3300/ --action list --resource os_tpl --auth x509
63
-
64
- occi --endpoint https://localhost:3300/ --action list --resource resource_tpl --auth x509
65
-
66
- occi --endpoint https://localhost:3300/ --action describe --resource os_tpl#debian6 --auth x509
67
-
68
- occi --endpoint https://localhost:3300/ --action create --resource compute --mixin os_tpl#debian6 --mixin resource_tpl#small --attributes title="My rOCCI VM" --auth x509
69
-
70
- occi --endpoint https://localhost:3300/ --action delete --resource /compute/65sd4f654sf65g4-s5fg65sfg465sfg-sf65g46sf5g4sdfg --auth x509}
71
-
72
- opts.separator ""
73
- opts.separator "Options:"
74
-
75
- opts.on("-i",
76
- "--interactive",
77
- "Run as an interactive client without additional arguments") do |interactive|
78
- options.interactive = interactive
79
- end
80
-
81
- opts.on("-e",
82
- "--endpoint URI",
83
- String,
84
- "OCCI server URI, defaults to '#{options.endpoint}'") do |endpoint|
85
- options.endpoint = URI(endpoint).to_s
86
- end
87
-
88
- opts.on("-n",
89
- "--auth METHOD",
90
- AUTH_METHODS,
91
- "Authentication method, defaults to '#{options.auth[:type]}'") do |auth|
92
- options.auth[:type] = auth.to_s
93
- end
94
-
95
- opts.on("-u",
96
- "--username USER",
97
- String,
98
- "Username for basic or digest authentication, defaults to '#{options.auth[:username]}'") do |username|
99
- options.auth[:username] = username
100
- end
101
-
102
- opts.on("-p",
103
- "--password PASSWORD",
104
- String,
105
- "Password for basic, digest and x509 authentication or an auth. token from OS Keystone") do |password|
106
- options.auth[:password] = password
107
- options.auth[:user_cert_password] = password
108
- options.auth[:token] = password
109
- end
110
-
111
- opts.on("-c",
112
- "--ca-path PATH",
113
- String,
114
- "Path to CA certificates directory, defaults to '#{options.auth[:ca_path]}'") do |ca_path|
115
- raise ArgumentError, "Path specified in --ca-path is not a directory!" unless File.directory? ca_path
116
- raise ArgumentError, "Path specified in --ca-path is not readable!" unless File.readable? ca_path
117
-
118
- options.auth[:ca_path] = ca_path
119
- end
120
-
121
- opts.on("-f",
122
- "--ca-file PATH",
123
- String,
124
- "Path to CA certificates in a file") do |ca_file|
125
- raise ArgumentError, "File specified in --ca-file is not a file!" unless File.file? ca_file
126
- raise ArgumentError, "File specified in --ca-file is not readable!" unless File.readable? ca_file
127
-
128
- options.auth[:ca_file] = ca_file
129
- end
130
-
131
- opts.on("-F",
132
- "--filter CATEGORY",
133
- String,
134
- "Category type identifier to filter categories from model, must be used together with the -m option") do |filter|
135
- options.filter = filter
136
- end
137
-
138
- opts.on("-x",
139
- "--user-cred FILE",
140
- String,
141
- "Path to user's x509 credentials, defaults to '#{options.auth[:user_cert]}'") do |user_cred|
142
- raise ArgumentError, "File specified in --user-cred is not a file!" unless File.file? user_cred
143
- raise ArgumentError, "File specified in --user-cred is not readable!" unless File.readable? user_cred
144
-
145
- options.auth[:user_cert] = user_cred
146
- end
147
-
148
- opts.on("-X",
149
- "--proxy-ca FILE",
150
- String,
151
- "Path to a file with GSI proxy's CA certificate(s)") do |proxy_ca|
152
- raise ArgumentError, "File specified in --proxy-ca is not a file!" unless File.file? proxy_ca
153
- raise ArgumentError, "File specified in --proxy-ca is not readable!" unless File.readable? proxy_ca
154
-
155
- options.auth[:proxy_ca] = proxy_ca
156
- end
157
-
158
- opts.on("-y",
159
- "--media-type MEDIA_TYPE",
160
- MEDIA_TYPES,
161
- "Media type for client <-> server communication, defaults to '#{options.media_type}'") do |media_type|
162
- options.media_type = media_type
163
- end
164
-
165
- opts.on("-r",
166
- "--resource RESOURCE",
167
- String,
168
- "Resource to be queried (e.g. network, compute, storage etc.), required") do |resource|
169
- options.resource = resource
170
- end
171
-
172
- opts.on("-t",
173
- "--attributes ATTRS",
174
- Array,
175
- "Comma separated attributes for new resources such as title=\"Name\", required") do |attributes|
176
- options.attributes = {}
177
-
178
- attributes.each do |attribute|
179
- ary = /^(.+?)=(.+)$/.match(attribute).to_a.drop 1
180
- raise ArgumentError, "Attributes must always contain ATTR=VALUE pairs!" if ary.length != 2
181
-
182
- options.attributes[ary[0].to_sym] = ary[1]
183
- end
184
- end
185
-
186
- opts.on("-T",
187
- "--context CTX_VARS",
188
- Array,
189
- "Comma separated context variables for new compute resources such as SSH_KEY=\"ssh-rsa dfsdf...adfdf== user@localhost\"") do |context|
190
- options.context_vars = {}
191
-
192
- context.each do |ctx|
193
- ary = /^(.+?)=(.+)$/.match(ctx).to_a.drop 1
194
- raise ArgumentError, "Context variables must always contain ATTR=VALUE pairs!" if ary.length != 2
195
-
196
- options.context_vars[ary[0].to_sym] = ary[1]
197
- end
198
- end
199
-
200
- opts.on("-a",
201
- "--action ACTION",
202
- ACTIONS,
203
- "Action to be performed on the resource, required") do |action|
204
- options.action = action
205
- end
206
-
207
- opts.on("-M",
208
- "--mixin NAME",
209
- String,
210
- "Type and name of the mixin as TYPE#NAME (e.g. os_tpl#monitoring, resource_tpl#medium)") do |mixin|
211
- parts = mixin.split("#")
212
-
213
- raise "Unknown mixin format! Use TYPE#NAME!" unless parts.length == 2
214
-
215
- options.mixins = {} if options.mixins.nil?
216
- options.mixins[parts[0]] = [] if options.mixins[parts[0]].nil?
217
- options.mixins[parts[0]] << parts[1]
218
- end
219
-
220
- opts.on("-j",
221
- "--link URI",
222
- String,
223
- "Link specified resource to the resource being created, only for action CREATE and resource COMPUTE") do |link|
224
- link_relative_path = URI(link).path
225
-
226
- raise ArgumentError, "Specified link URI is not valid!" unless link_relative_path.start_with? '/'
227
-
228
- options.links = [] if options.links.nil?
229
- options.links << link_relative_path
230
- end
231
-
232
- opts.on("-g",
233
- "--trigger-action TRIGGER",
234
- String,
235
- "Action to be triggered on the resource") do |trigger_action|
236
- options.trigger_action = trigger_action
237
- end
238
-
239
- opts.on("-l",
240
- "--log-to OUTPUT",
241
- LOG_OUTPUTS,
242
- "Log to the specified device, defaults to 'STDERR'") do |log_to|
243
- options.log[:out] = STDOUT if log_to == :stdout or log_to == :STDOUT
244
- end
245
-
246
- opts.on("-o",
247
- "--output-format FORMAT",
248
- Occi::Bin::ResourceOutputFactory.allowed_formats,
249
- "Output format, defaults to human-readable 'plain'") do |output_format|
250
- options.output_format = output_format
251
- end
252
-
253
- opts.on_tail("-m",
254
- "--dump-model",
255
- "Contact the endpoint and dump its model, cannot be used with the interactive mode") do |dump_model|
256
- options.dump_model = dump_model
257
- end
258
-
259
- opts.on_tail("-d",
260
- "--debug",
261
- "Enable debugging messages") do |debug|
262
- options.debug = debug
263
- options.log[:level] = Occi::Log::DEBUG
264
- end
265
-
266
- opts.on_tail("-b",
267
- "--verbose",
268
- "Be more verbose, less intrusive than debug mode") do |verbose|
269
- options.verbose = verbose
270
- options.log[:level] = Occi::Log::INFO unless options.log[:level] == Occi::Log::DEBUG
271
- end
272
-
273
- opts.on_tail("-h",
274
- "--help",
275
- "Show this message") do
276
- if @@quiet
277
- exit true
278
- else
279
- puts opts
280
- exit! true
281
- end
282
- end
283
-
284
- opts.on_tail("-v",
285
- "--version",
286
- "Show version") do
287
- if @@quiet
288
- exit true
289
- else
290
- puts Occi::VERSION
291
- exit! true
292
- end
293
- end
294
- end
295
-
296
- begin
297
- opts.parse!(args)
298
- rescue Exception => ex
299
- if @@quiet
300
- exit false
301
- else
302
- puts ex.message.capitalize
303
- puts opts
304
- exit!
305
- end
306
- end
307
-
308
- check_restrictions options, opts
309
-
310
- options
311
- end
312
-
313
- private
314
-
315
- def self.check_restrictions(options, opts)
316
- if options.interactive && options.dump_model
317
- if @@quiet
318
- exit false
319
- else
320
- puts "You cannot use '--dump-model' and '--interactive' at the same time!"
321
- puts opts
322
- exit!
323
- end
324
- end
325
-
326
- if !options.dump_model && options.filter
327
- if @@quiet
328
- exit false
329
- else
330
- puts "You cannot use '--filter' without '--dump-model'!"
331
- puts opts
332
- exit!
333
- end
334
- end
335
-
336
- return if options.interactive || options.dump_model
337
-
338
- mandatory = []
339
-
340
- if options.action == :trigger
341
- mandatory << :trigger_action
342
- end
343
-
344
- if options.action == :create
345
- if !options.links.nil?
346
- mandatory << :links
347
- else
348
- mandatory << :mixins
349
- end
350
-
351
- mandatory << :attributes
352
- check_attrs = true
353
- end
354
-
355
- mandatory.concat [:resource, :action]
356
-
357
- check_hash options, mandatory, opts
358
-
359
- if check_attrs
360
- mandatory = [:title]
361
- check_hash options.attributes, mandatory, opts
362
- end
363
- end
364
-
365
- def self.check_hash(hash, mandatory, opts)
366
- if !hash.is_a? Hash
367
- hash = hash.marshal_dump
368
- end
369
-
370
- missing = mandatory.select{ |param| hash[param].nil? }
371
- if !missing.empty?
372
- if @@quiet
373
- exit false
374
- else
375
- puts "Missing required arguments: #{missing.join(', ')}"
376
- puts opts
377
- exit!
378
- end
379
- end
380
- end
381
- end
382
-
383
- end
384
- end
@@ -1,97 +0,0 @@
1
- require 'json'
2
- require 'erb'
3
-
4
- module Occi
5
- module Bin
6
-
7
- class ResourceOutputFactory
8
-
9
- @@allowed_formats = [:json, :plain].freeze
10
- @@allowed_resource_types = [:compute, :storage, :network, :os_tpl, :resource_tpl].freeze
11
- @@allowed_data_types = [:locations, :resources].freeze
12
-
13
- attr_reader :output_format
14
-
15
- def initialize(output_format = :plain)
16
- raise "Unsupported output format!" unless @@allowed_formats.include? output_format
17
- @output_format = output_format
18
- end
19
-
20
- def format(data, data_type, resource_type)
21
- raise "Data has to be in an array!" unless data.is_a? Array
22
- raise "Unsupported resource type! Got: #{resource_type.to_s}" unless @@allowed_resource_types.include? resource_type
23
- raise "Unsupported data type! Got: #{data_type.to_s}" unless @@allowed_data_types.include? data_type
24
-
25
- # validate incoming data
26
- if data_type == :resources
27
- data.each do |occi_collection|
28
- raise "I need the resources to be in a Collection!" unless occi_collection.respond_to? :as_json
29
- end
30
- end
31
-
32
- # construct method name from data type and output format
33
- method = (data_type.to_s + "_to_" + output_format.to_s).to_sym
34
-
35
- ResourceOutputFactory.send method, data, resource_type
36
- end
37
-
38
- def self.allowed_formats
39
- @@allowed_formats
40
- end
41
-
42
- def self.allowed_resource_types
43
- @@allowed_resource_types
44
- end
45
-
46
- def self.allowed_data_types
47
- @@allowed_data_types
48
- end
49
-
50
- def self.resources_to_json(occi_resources, resource_type)
51
- # generate JSON document from an array of JSON objects
52
- JSON.generate occi_resources
53
- end
54
-
55
- def self.resources_to_plain(occi_resources, resource_type)
56
- # using ERB templates for known resource and mixin types
57
- file = File.expand_path("..", __FILE__) + '/templates/' + resource_type.to_s + ".erb"
58
- template = ERB.new File.new(file).read
59
-
60
- formatted_output = ""
61
-
62
- occi_resources.each do |occi_resource|
63
- json_resource = occi_resource.as_json
64
- formatted_output << template.result(binding) unless json_resource.nil? || json_resource.empty?
65
- end
66
-
67
- formatted_output
68
- end
69
-
70
- def self.locations_to_json(url_locations, resource_type)
71
- # give all locatios a common key and convert to JSON
72
- locations = { resource_type => [] }
73
-
74
- url_locations.each do |location|
75
- location = location.split("/").last if [:os_tpl, :resource_tpl].include? resource_type
76
- locations[resource_type] << location
77
- end
78
-
79
- locations.to_json
80
- end
81
-
82
- def self.locations_to_plain(url_locations, resource_type)
83
- # just an attempt to make the array more readable
84
- output = "\n" + resource_type.to_s.capitalize + " locations:\n"
85
-
86
- url_locations.each do |location|
87
- location = location.split("/").last if [:os_tpl, :resource_tpl].include? resource_type
88
- output << "\t" << location << "\n"
89
- end
90
-
91
- output
92
- end
93
-
94
- end
95
-
96
- end
97
- end