occi-api 4.2.0.beta.8 → 4.2.0.beta.9
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/.travis.yml +6 -0
- data/lib/occi/api/client/authn_utils.rb +3 -3
- data/lib/occi/api/client/base/action_methods.rb +62 -0
- data/lib/occi/api/client/base/category_methods.rb +1 -0
- data/lib/occi/api/client/base/entity_methods.rb +4 -1
- data/lib/occi/api/client/base/helpers.rb +3 -3
- data/lib/occi/api/client/base/kind_methods.rb +2 -1
- data/lib/occi/api/client/base/mixin_methods.rb +15 -14
- data/lib/occi/api/client/base/protected_helpers.rb +3 -3
- data/lib/occi/api/client/base/protected_stubs.rb +3 -2
- data/lib/occi/api/client/base/stubs.rb +9 -9
- data/lib/occi/api/client/client_base.rb +4 -1
- data/lib/occi/api/client/client_http.rb +1 -1
- data/lib/occi/api/client/http/code_helpers.rb +1 -1
- data/lib/occi/api/client/http/helpers.rb +1 -1
- data/lib/occi/api/client/http/party_wrappers.rb +73 -80
- data/lib/occi/api/dsl/type_methods.rb +15 -0
- data/lib/occi/api/version.rb +1 -1
- metadata +2 -1
data/.travis.yml
CHANGED
|
@@ -3,6 +3,7 @@ language: ruby
|
|
|
3
3
|
rvm:
|
|
4
4
|
- 1.9.3
|
|
5
5
|
- 2.0.0
|
|
6
|
+
- 2.1.0
|
|
6
7
|
- ruby-head
|
|
7
8
|
- jruby-19mode
|
|
8
9
|
- jruby-head
|
|
@@ -25,10 +26,15 @@ matrix:
|
|
|
25
26
|
jdk: openjdk7
|
|
26
27
|
- rvm: 2.0.0
|
|
27
28
|
jdk: oraclejdk7
|
|
29
|
+
- rvm: 2.1.0
|
|
30
|
+
jdk: openjdk7
|
|
31
|
+
- rvm: 2.1.0
|
|
32
|
+
jdk: oraclejdk7
|
|
28
33
|
- rvm: ruby-head
|
|
29
34
|
jdk: openjdk7
|
|
30
35
|
- rvm: ruby-head
|
|
31
36
|
jdk: oraclejdk7
|
|
37
|
+
fast_finish: true
|
|
32
38
|
|
|
33
39
|
branches:
|
|
34
40
|
only:
|
|
@@ -18,8 +18,8 @@ module Occi::Api::Client
|
|
|
18
18
|
# AuthnUtils.extract_pem_from_pkcs12 "~/.globus/usercert.p12", "123456"
|
|
19
19
|
# # => #<String>
|
|
20
20
|
#
|
|
21
|
-
# @param [String] Path to a PKCS#12 file with credentials
|
|
22
|
-
# @param [String] Password needed to unlock the PKCS#12 file
|
|
21
|
+
# @param path_to_p12_file [String] Path to a PKCS#12 file with credentials
|
|
22
|
+
# @param p12_password [String] Password needed to unlock the PKCS#12 file
|
|
23
23
|
# @return [String] Decrypted credentials in a PEM formatted string
|
|
24
24
|
def self.extract_pem_from_pkcs12(path_to_p12_file, p12_password)
|
|
25
25
|
# decode certificate and its private key
|
|
@@ -80,7 +80,7 @@ module Occi::Api::Client
|
|
|
80
80
|
# AuthnUtils.certs_to_file_ary "~/.globus/usercert.pem"
|
|
81
81
|
# # => [#<String>, #<String>, ...]
|
|
82
82
|
#
|
|
83
|
-
# @param [String] Path to a PEM file containing certificates
|
|
83
|
+
# @param ca_file [String] Path to a PEM file containing certificates
|
|
84
84
|
# @return [Array<String>] An array of read certificates
|
|
85
85
|
def self.certs_to_file_ary(ca_file)
|
|
86
86
|
# TODO: read and separate multiple certificates
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Occi::Api::Client
|
|
2
|
+
module Base
|
|
3
|
+
|
|
4
|
+
module ActionMethods
|
|
5
|
+
|
|
6
|
+
# Retrieves all available action types.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# client.get_action_types # => [ "stop", "start", "up", "down" ]
|
|
10
|
+
#
|
|
11
|
+
# @return [Array<String>] list of available action types in a human-readable format
|
|
12
|
+
def get_action_types
|
|
13
|
+
@model.actions.to_a.collect { |action| action.term }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Retrieves all available action type identifiers.
|
|
17
|
+
#
|
|
18
|
+
# @example
|
|
19
|
+
# client.get_action_type_identifiers
|
|
20
|
+
# # => [ "http://schemas.ogf.org/occi/infrastructure/compute/action#start",
|
|
21
|
+
# # "http://schemas.ogf.org/occi/infrastructure/compute/action#stop",
|
|
22
|
+
# # "http://schemas.ogf.org/occi/infrastructure/compute/action#suspend" ]
|
|
23
|
+
#
|
|
24
|
+
# @return [Array<String>] list of available action type identifiers
|
|
25
|
+
def get_action_type_identifiers
|
|
26
|
+
@model.actions.to_a.collect { |action| action.type_identifier }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Retrieves available action type identifier for the given action type.
|
|
30
|
+
#
|
|
31
|
+
# @example
|
|
32
|
+
# client.get_action_type_identifier("start")
|
|
33
|
+
# # => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start'
|
|
34
|
+
# client.get_action_type_identifier("start", "compute")
|
|
35
|
+
# # => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start'
|
|
36
|
+
# client.get_action_type_identifier("start", "storage")
|
|
37
|
+
# # => nil
|
|
38
|
+
#
|
|
39
|
+
# @param type [String] short action type
|
|
40
|
+
# @param for_kind_w_term [String] kind the action belongs to (e.g. "compute", "network", ...)
|
|
41
|
+
# @return [String, nil] action type identifier for the given action type
|
|
42
|
+
def get_action_type_identifier(type, for_kind_w_term = nil)
|
|
43
|
+
return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))
|
|
44
|
+
|
|
45
|
+
acts = @model.actions.to_a.select { |k| k.term == type }
|
|
46
|
+
tis = acts.collect { |c| c.type_identifier }
|
|
47
|
+
tis.uniq!
|
|
48
|
+
|
|
49
|
+
tis.keep_if { |ti| ti.include? "/#{for_kind_w_term}/" } unless for_kind_w_term.blank?
|
|
50
|
+
|
|
51
|
+
if tis.length > 1
|
|
52
|
+
raise Occi::Api::Client::Errors::AmbiguousNameError,
|
|
53
|
+
"Category type #{type.inspect} is ambiguous, use a type identifier!"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
tis.first
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -32,6 +32,7 @@ module Occi::Api::Client
|
|
|
32
32
|
# client.get_category_type_identifier("compute")
|
|
33
33
|
# # => 'http://schemas.ogf.org/occi/infrastructure#compute'
|
|
34
34
|
#
|
|
35
|
+
# @param type [String] short category type
|
|
35
36
|
# @return [String, nil] category type identifier for the given category type
|
|
36
37
|
def get_category_type_identifier(type)
|
|
37
38
|
return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))
|
|
@@ -12,7 +12,7 @@ module Occi::Api::Client
|
|
|
12
12
|
# client.get_resource "http://schemas.ogf.org/occi/infrastructure#network"
|
|
13
13
|
# # => Occi::Core::Resource
|
|
14
14
|
#
|
|
15
|
-
# @param [String] resource name or resource identifier
|
|
15
|
+
# @param resource_type [String] resource name or resource identifier
|
|
16
16
|
# @return [Occi::Core::Resource] new resource instance
|
|
17
17
|
def get_resource(resource_type)
|
|
18
18
|
Occi::Log.debug("Instantiating #{resource_type.inspect}")
|
|
@@ -56,6 +56,7 @@ module Occi::Api::Client
|
|
|
56
56
|
# client.get_entity_type_identifier("compute")
|
|
57
57
|
# # => 'http://schemas.ogf.org/occi/infrastructure#compute'
|
|
58
58
|
#
|
|
59
|
+
# @param type [String] short entity type
|
|
59
60
|
# @return [String, nil] entity type identifier for the given entity type
|
|
60
61
|
def get_entity_type_identifier(type)
|
|
61
62
|
return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))
|
|
@@ -103,6 +104,7 @@ module Occi::Api::Client
|
|
|
103
104
|
# client.get_resource_type_identifier("compute")
|
|
104
105
|
# # => 'http://schemas.ogf.org/occi/infrastructure#compute'
|
|
105
106
|
#
|
|
107
|
+
# @param type [String] short resource type
|
|
106
108
|
# @return [String, nil] resource type identifier for the given resource type
|
|
107
109
|
def get_resource_type_identifier(type)
|
|
108
110
|
return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))
|
|
@@ -149,6 +151,7 @@ module Occi::Api::Client
|
|
|
149
151
|
# client.get_link_type_identifier("storagelink")
|
|
150
152
|
# # => 'http://schemas.ogf.org/occi/infrastructure#storagelink'
|
|
151
153
|
#
|
|
154
|
+
# @param type [String] short link type
|
|
152
155
|
# @return [String, nil] link type identifier for the given link type
|
|
153
156
|
def get_link_type_identifier(type)
|
|
154
157
|
return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))
|
|
@@ -11,7 +11,7 @@ module Occi::Api::Client
|
|
|
11
11
|
# path_for_kind_type_identifier "http://localhost:3300/compute/35ad4f45gsf-gsfg524s6gsfg-sfgsf4gsfg"
|
|
12
12
|
# # => "/compute/35ad4f45gsf-gsfg524s6gsfg-sfgsf4gsfg"
|
|
13
13
|
#
|
|
14
|
-
# @param [String] kind type identifier
|
|
14
|
+
# @param kind_type_identifier [String] kind type identifier
|
|
15
15
|
# @return [String]
|
|
16
16
|
def path_for_kind_type_identifier(kind_type_identifier)
|
|
17
17
|
raise ArgumentError,
|
|
@@ -45,7 +45,7 @@ module Occi::Api::Client
|
|
|
45
45
|
# path_for_instance Occi::Infrastructure::Storagelink.new
|
|
46
46
|
# # => "/link/storagelink/35ad4f45gsf-gsfg524s6gsfg-sfgsf4gsfg"
|
|
47
47
|
#
|
|
48
|
-
# @param [Object] instance
|
|
48
|
+
# @param instance [Object] instance
|
|
49
49
|
# @return [String] path for the given instance
|
|
50
50
|
def path_for_instance(instance)
|
|
51
51
|
unless instance.respond_to?(:location)
|
|
@@ -72,7 +72,7 @@ module Occi::Api::Client
|
|
|
72
72
|
# sanitize_instance_link "/compute/35ad4f45gsf-gsfg524s6gsfg-sfgsf4gsfg"
|
|
73
73
|
# # => "/compute/35ad4f45gsf-gsfg524s6gsfg-sfgsf4gsfg"
|
|
74
74
|
#
|
|
75
|
-
# @param [String] string containing the full instance link
|
|
75
|
+
# @param instance_link [String] string containing the full instance link
|
|
76
76
|
# @return [String] extracted path, with a leading slash
|
|
77
77
|
def sanitize_instance_link(instance_link)
|
|
78
78
|
# everything starting with '/' is considered to be a resource path
|
|
@@ -10,7 +10,7 @@ module Occi::Api::Client
|
|
|
10
10
|
# # => [ "http://schemas.ogf.org/occi/infrastructure#network",
|
|
11
11
|
# # "http://schemas.ogf.org/occi/infrastructure#ipnetwork" ]
|
|
12
12
|
#
|
|
13
|
-
# @param [String] type identifier
|
|
13
|
+
# @param type_identifier [String] type identifier
|
|
14
14
|
# @return [Array<String>] list of available kind type identifiers related to
|
|
15
15
|
# the given type identifier
|
|
16
16
|
def get_kind_type_identifiers_related_to(type_identifier)
|
|
@@ -48,6 +48,7 @@ module Occi::Api::Client
|
|
|
48
48
|
# client.get_kind_type_identifier("compute")
|
|
49
49
|
# # => 'http://schemas.ogf.org/occi/infrastructure#compute'
|
|
50
50
|
#
|
|
51
|
+
# @param type [String] short kind type
|
|
51
52
|
# @return [String, nil] kind type identifier for the given kind type
|
|
52
53
|
def get_kind_type_identifier(type)
|
|
53
54
|
return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))
|
|
@@ -15,9 +15,9 @@ module Occi::Api::Client
|
|
|
15
15
|
# # => "http://my.occi.service/occi/infrastructure/resource_tpl#large"
|
|
16
16
|
# client.get_mixin "debian6", "resource_tpl" # => nil
|
|
17
17
|
#
|
|
18
|
-
# @param [String] name of the mixin
|
|
19
|
-
# @param [String] type of the mixin
|
|
20
|
-
# @param [Boolean] should we describe the mixin or return its link?
|
|
18
|
+
# @param name [String] name of the mixin
|
|
19
|
+
# @param type [String] type of the mixin
|
|
20
|
+
# @param describe [Boolean] should we describe the mixin or return its link?
|
|
21
21
|
# @return [String, Occi::Core::Mixin, nil] link, mixin description or nothing found
|
|
22
22
|
def get_mixin(name, type = nil, describe = false)
|
|
23
23
|
# TODO: mixin fix
|
|
@@ -41,8 +41,8 @@ module Occi::Api::Client
|
|
|
41
41
|
# # => #<Occi::Core::Mixin>
|
|
42
42
|
# client.describe_mixin "debian6", "resource_tpl" # => nil
|
|
43
43
|
#
|
|
44
|
-
# @param [String] name of the mixin
|
|
45
|
-
# @param [String] type of the mixin
|
|
44
|
+
# @param name [String] name of the mixin
|
|
45
|
+
# @param type [String] type of the mixin
|
|
46
46
|
# @return [Occi::Core::Mixin, nil] mixin description or nothing found
|
|
47
47
|
def describe_mixin(name, type = nil)
|
|
48
48
|
mixins = get_mixins(type)
|
|
@@ -54,8 +54,8 @@ module Occi::Api::Client
|
|
|
54
54
|
# Looks up a mixin with a specific type, will return
|
|
55
55
|
# mixin's full description.
|
|
56
56
|
#
|
|
57
|
-
# @param [String] name of the mixin
|
|
58
|
-
# @param [String] type of the mixin
|
|
57
|
+
# @param name [String] name of the mixin
|
|
58
|
+
# @param type [String] type of the mixin
|
|
59
59
|
# @return [Occi::Core::Mixin] mixin description
|
|
60
60
|
def describe_mixin_w_type(name, type)
|
|
61
61
|
describe_mixin(name, type)
|
|
@@ -65,7 +65,7 @@ module Occi::Api::Client
|
|
|
65
65
|
# return mixin's full description. Returns always the
|
|
66
66
|
# first match found, search will start in os_tpl.
|
|
67
67
|
#
|
|
68
|
-
# @param [String] name of the mixin
|
|
68
|
+
# @param name [String] name of the mixin
|
|
69
69
|
# @return [Occi::Core::Mixin] mixin description
|
|
70
70
|
def describe_mixin_wo_type(name)
|
|
71
71
|
describe_mixin(name, nil)
|
|
@@ -83,8 +83,8 @@ module Occi::Api::Client
|
|
|
83
83
|
# # => "http://my.occi.service/occi/infrastructure/resource_tpl#large"
|
|
84
84
|
# client.list_mixin "debian6", "resource_tpl" # => nil
|
|
85
85
|
#
|
|
86
|
-
# @param [String] name of the mixin
|
|
87
|
-
# @param [String] type of the mixin
|
|
86
|
+
# @param name [String] name of the mixin
|
|
87
|
+
# @param type [String] type of the mixin
|
|
88
88
|
# @return [String, nil] link or nothing found
|
|
89
89
|
def list_mixin(name, type = nil)
|
|
90
90
|
mixin = describe_mixin(name, type)
|
|
@@ -103,8 +103,8 @@ module Occi::Api::Client
|
|
|
103
103
|
# client.get_mixins "resource_tpl"
|
|
104
104
|
# # => #<Occi::Core::Mixins>
|
|
105
105
|
#
|
|
106
|
-
# @param [String] type of mixins
|
|
107
|
-
# @param [Boolean] include type itself as a mixin
|
|
106
|
+
# @param type [String] type of mixins
|
|
107
|
+
# @param include_self [Boolean] include type itself as a mixin
|
|
108
108
|
# @return [Occi::Core::Mixins] collection of available mixins
|
|
109
109
|
def get_mixins(type = nil, include_self = false)
|
|
110
110
|
unless type.blank?
|
|
@@ -145,8 +145,8 @@ module Occi::Api::Client
|
|
|
145
145
|
# client.list_mixins "resource_tpl"
|
|
146
146
|
# # => #<Array<String>>
|
|
147
147
|
#
|
|
148
|
-
# @param [String] type of mixins
|
|
149
|
-
# @param [Boolean] include type itself as a mixin
|
|
148
|
+
# @param type [String] type of mixins
|
|
149
|
+
# @param include_self [Boolean] include type itself as a mixin
|
|
150
150
|
# @return [Array<String>] collection of available mixin identifiers
|
|
151
151
|
def list_mixins(type = nil, include_self = false)
|
|
152
152
|
mixins = get_mixins(type, include_self)
|
|
@@ -182,6 +182,7 @@ module Occi::Api::Client
|
|
|
182
182
|
# client.get_mixin_type_identifier("os_tpl")
|
|
183
183
|
# # => 'http://schemas.ogf.org/occi/infrastructure#os_tpl'
|
|
184
184
|
#
|
|
185
|
+
# @param type [String] short mixin type
|
|
185
186
|
# @return [String, nil] mixin type identifier for the given mixin type
|
|
186
187
|
def get_mixin_type_identifier(type)
|
|
187
188
|
return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))
|
|
@@ -9,7 +9,7 @@ module Occi::Api::Client
|
|
|
9
9
|
# @example
|
|
10
10
|
# get_logger { :out => STDERR, :level => Occi::Log::WARN, :logger => nil }
|
|
11
11
|
#
|
|
12
|
-
# @param [Hash] logger options
|
|
12
|
+
# @param log_options [Hash] logger options
|
|
13
13
|
# @return [Occi::Log] instance of the logger
|
|
14
14
|
def get_logger(log_options)
|
|
15
15
|
unless log_options[:logger].kind_of?(Occi::Log)
|
|
@@ -28,7 +28,7 @@ module Occi::Api::Client
|
|
|
28
28
|
# @example
|
|
29
29
|
# get_endpoint_uri "http://localhost:3300" # => #<URI::*>
|
|
30
30
|
#
|
|
31
|
-
# @param [String] endpoint URI in a non-canonical string
|
|
31
|
+
# @param endpoint [String] endpoint URI in a non-canonical string
|
|
32
32
|
# @return [URI] canonical endpoint URI
|
|
33
33
|
def get_endpoint_uri(endpoint)
|
|
34
34
|
unless endpoint =~ URI::ABS_URI
|
|
@@ -48,7 +48,7 @@ module Occi::Api::Client
|
|
|
48
48
|
# model_collection = get('/-/')
|
|
49
49
|
# get_model model_collection # => #<Occi::Model>
|
|
50
50
|
#
|
|
51
|
-
# @param [Occi::Collection] parsed representation of server's model
|
|
51
|
+
# @param model_collection [Occi::Collection] parsed representation of server's model
|
|
52
52
|
# @return [Occi::Model] Model instance
|
|
53
53
|
def get_model(model_collection)
|
|
54
54
|
# build model
|
|
@@ -13,8 +13,8 @@ module Occi::Api::Client
|
|
|
13
13
|
# get_auth { :type => "x509", :user_cert => "~/cert.pem",
|
|
14
14
|
# :user_cert_password => "321", :ca_path => nil }
|
|
15
15
|
#
|
|
16
|
-
# @param [Hash] authentication options
|
|
17
|
-
# @param [Boolean] allow fallback-only options
|
|
16
|
+
# @param auth_options [Hash] authentication options
|
|
17
|
+
# @param fallback [Boolean] allow fallback-only options
|
|
18
18
|
# @return [Hash] transformed hash with authN information
|
|
19
19
|
def get_auth(auth_options, fallback = false)
|
|
20
20
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -33,6 +33,7 @@ module Occi::Api::Client
|
|
|
33
33
|
# @example
|
|
34
34
|
# get_media_type # => 'application/occi+json'
|
|
35
35
|
#
|
|
36
|
+
# @param force_type [String] type to be forcibly chosen
|
|
36
37
|
# @return [String] chosen media type
|
|
37
38
|
def get_media_type(force_type = nil)
|
|
38
39
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -18,7 +18,7 @@ module Occi::Api::Client
|
|
|
18
18
|
# client.list "http://schemas.ogf.org/occi/infrastructure#compute"
|
|
19
19
|
# # => [ "http://localhost:3300/compute/jh425jhj3h413-7dj29d7djd9e3-djh2jh4j4j" ]
|
|
20
20
|
#
|
|
21
|
-
# @param [String] resource type identifier or just type name
|
|
21
|
+
# @param resource_type_identifier [String] resource type identifier or just type name
|
|
22
22
|
# @return [Array<String>] list of links
|
|
23
23
|
def list(resource_type_identifier=nil)
|
|
24
24
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -39,7 +39,7 @@ module Occi::Api::Client
|
|
|
39
39
|
# client.describe "http://localhost:3300/compute/j5hk1234jk2524-2j3j2k34jjh234-adfaf1234"
|
|
40
40
|
# # => #<Occi::Core::Resources>
|
|
41
41
|
#
|
|
42
|
-
# @param [String] resource type identifier, type name or resource location
|
|
42
|
+
# @param resource_type_identifier [String] resource type identifier, type name or resource location
|
|
43
43
|
# @return [Occi::Core::Resources] list of resource descriptions
|
|
44
44
|
def describe(resource_type_identifier=nil)
|
|
45
45
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -58,7 +58,7 @@ module Occi::Api::Client
|
|
|
58
58
|
#
|
|
59
59
|
# client.create res # => "http://localhost:3300/compute/df7698...f987fa"
|
|
60
60
|
#
|
|
61
|
-
# @param [Occi::Core::Entity] resource to be created on the server
|
|
61
|
+
# @param entity [Occi::Core::Entity] resource to be created on the server
|
|
62
62
|
# @return [String] URI of the new resource
|
|
63
63
|
def create(entity)
|
|
64
64
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -70,7 +70,7 @@ module Occi::Api::Client
|
|
|
70
70
|
# @example
|
|
71
71
|
# client.deploy "~/MyVMs/rOcciVM.ovf" # => "http://localhost:3300/compute/343423...42njhdafa"
|
|
72
72
|
#
|
|
73
|
-
# @param [String] location of an OVF/OVA file
|
|
73
|
+
# @param location [String] location of an OVF/OVA file
|
|
74
74
|
# @return [String] URI of the new resource
|
|
75
75
|
def deploy(location)
|
|
76
76
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -82,7 +82,7 @@ module Occi::Api::Client
|
|
|
82
82
|
# @example
|
|
83
83
|
# client.deploy_ovf "OVF DESCRIPTOR HERE" # => "http://localhost:3300/compute/343423...42njhdafa"
|
|
84
84
|
#
|
|
85
|
-
# @param [String] OVF descriptor (e.g., already read from a file or generated)
|
|
85
|
+
# @param descriptor [String] OVF descriptor (e.g., already read from a file or generated)
|
|
86
86
|
# @return [String] URI of the new resource
|
|
87
87
|
def deploy_ovf(descriptor)
|
|
88
88
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -94,7 +94,7 @@ module Occi::Api::Client
|
|
|
94
94
|
# @example
|
|
95
95
|
# client.deploy_ova "OVA DESCRIPTOR HERE" # => "http://localhost:3300/compute/343423...42njhdafa"
|
|
96
96
|
#
|
|
97
|
-
# @param [String] OVA descriptor (e.g., already read from a file or generated)
|
|
97
|
+
# @param descriptor [String] OVA descriptor (e.g., already read from a file or generated)
|
|
98
98
|
# @return [String] URI of the new resource
|
|
99
99
|
def deploy_ova(descriptor)
|
|
100
100
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -108,7 +108,7 @@ module Occi::Api::Client
|
|
|
108
108
|
# client.delete "http://schemas.ogf.org/occi/infrastructure#compute" # => true
|
|
109
109
|
# client.delete "http://localhost:3300/compute/245j42594...98s9df8s9f" # => true
|
|
110
110
|
#
|
|
111
|
-
# @param [String] resource type identifier, type name or location
|
|
111
|
+
# @param resource_type_identifier [String] resource type identifier, type name or location
|
|
112
112
|
# @return [Boolean] status
|
|
113
113
|
def delete(resource_type_identifier)
|
|
114
114
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -119,8 +119,8 @@ module Occi::Api::Client
|
|
|
119
119
|
# @example
|
|
120
120
|
# TODO: add examples
|
|
121
121
|
#
|
|
122
|
-
# @param [String] resource type or type identifier
|
|
123
|
-
# @param [Occi::Core::ActionInstance] type of action
|
|
122
|
+
# @param resource_type_identifier [String] resource type or type identifier
|
|
123
|
+
# @param action_instance [Occi::Core::ActionInstance] type of action
|
|
124
124
|
# @return [Boolean] status
|
|
125
125
|
def trigger(resource_type_identifier, action_instance)
|
|
126
126
|
raise Occi::Api::Client::Errors::NotImplementedError, "#{__method__} is just a stub!"
|
|
@@ -53,7 +53,7 @@ module Occi::Api::Client
|
|
|
53
53
|
# @example
|
|
54
54
|
# client.connect # => true
|
|
55
55
|
#
|
|
56
|
-
# @param [Boolean] force re-connect on already connected client
|
|
56
|
+
# @param force [Boolean] force re-connect on already connected client
|
|
57
57
|
# @return [Boolean] true on successful connect
|
|
58
58
|
def connect(force = false)
|
|
59
59
|
raise "Client already connected!" if @connected && !force
|
|
@@ -63,6 +63,9 @@ module Occi::Api::Client
|
|
|
63
63
|
# include stuff
|
|
64
64
|
include Occi::Api::Client::Base::Stubs
|
|
65
65
|
|
|
66
|
+
# include action-related stuff
|
|
67
|
+
include Occi::Api::Client::Base::ActionMethods
|
|
68
|
+
|
|
66
69
|
# include category-related stuff
|
|
67
70
|
include Occi::Api::Client::Base::CategoryMethods
|
|
68
71
|
|
|
@@ -34,7 +34,7 @@ module Occi::Api::Client
|
|
|
34
34
|
#
|
|
35
35
|
# Occi::Api::Client::ClientHttp.new options # => #<Occi::Api::Client::ClientHttp>
|
|
36
36
|
#
|
|
37
|
-
# @param [Hash] options, for available options and defaults see examples
|
|
37
|
+
# @param options [Hash] options, for available options and defaults see examples
|
|
38
38
|
# @return [Occi::Api::Client::ClientHttp] client instance
|
|
39
39
|
def initialize(options = {})
|
|
40
40
|
super options
|
|
@@ -52,7 +52,7 @@ module Occi::Api::Client
|
|
|
52
52
|
# @example
|
|
53
53
|
# reason_phrase(500) # => "Internal Server Error"
|
|
54
54
|
#
|
|
55
|
-
# @param [Integer] HTTP response code
|
|
55
|
+
# @param code [Integer] HTTP response code
|
|
56
56
|
# @return [String] human-readable phrase
|
|
57
57
|
def reason_phrase(code)
|
|
58
58
|
HTTP_CODES[code.to_s]
|
|
@@ -86,7 +86,7 @@ module Occi::Api::Client
|
|
|
86
86
|
# response_message self.class.delete(path)
|
|
87
87
|
# # => 'HTTP Response status: [200] OK'
|
|
88
88
|
#
|
|
89
|
-
# @param [HTTParty::Response] HTTParty response object
|
|
89
|
+
# @param response [HTTParty::Response] HTTParty response object
|
|
90
90
|
# @return [String] message
|
|
91
91
|
def response_message(response)
|
|
92
92
|
@last_response = response
|
|
@@ -10,51 +10,28 @@ module Occi::Api::Client
|
|
|
10
10
|
# get "/compute/" # => #<Occi::Collection>
|
|
11
11
|
# get "/compute/fs65g4fs6g-sf54g54gsf-aa12faddf52" # => #<Occi::Collection>
|
|
12
12
|
#
|
|
13
|
-
# @param [String] path for the GET request
|
|
14
|
-
# @param [Occi::Collection] collection of filters
|
|
13
|
+
# @param path [String] path for the GET request
|
|
14
|
+
# @param filter [Occi::Collection] collection of filters
|
|
15
15
|
# @return [Occi::Collection] parsed result of the request
|
|
16
16
|
def get(path='/', filter=nil)
|
|
17
|
+
raise ArgumentError, "Path is a required argument!" if path.blank?
|
|
18
|
+
|
|
17
19
|
# apply filters if present
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}.join(',')
|
|
20
|
+
headers = self.class.headers.clone
|
|
21
|
+
unless filter.blank?
|
|
22
|
+
categories = filter.categories.to_a.collect { |category| category.to_string_short }.join(',')
|
|
23
|
+
attributes = filter.entities.to_a.collect { |entity| entity.attributes.to_header }.join(',')
|
|
23
24
|
|
|
24
|
-
headers = self.class.headers.clone
|
|
25
25
|
headers['Content-Type'] = 'text/occi'
|
|
26
26
|
headers['Category'] = categories unless categories.empty?
|
|
27
|
-
headers['X-OCCI-
|
|
28
|
-
|
|
29
|
-
self.class.get(path, :headers => headers)
|
|
30
|
-
else
|
|
31
|
-
self.class.get(path)
|
|
27
|
+
headers['X-OCCI-Attribute'] = attributes unless attributes.empty?
|
|
32
28
|
end
|
|
33
29
|
|
|
30
|
+
response = self.class.get(path, :headers => headers)
|
|
34
31
|
response_msg = response_message response
|
|
35
32
|
raise "HTTP GET failed! #{response_msg}" unless response.code == 200
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
kind = @model.get_by_location(path) if @model
|
|
39
|
-
|
|
40
|
-
Occi::Log.debug "Response kind: #{kind.inspect}"
|
|
41
|
-
|
|
42
|
-
entity_type = nil
|
|
43
|
-
if kind && kind.related_to?(Occi::Core::Link)
|
|
44
|
-
entity_type = Occi::Core::Link
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
entity_type = Occi::Core::Resource unless entity_type
|
|
48
|
-
|
|
49
|
-
Occi::Log.debug "Parser call: #{response.content_type} #{path.include?('/-/')} " \
|
|
50
|
-
"#{entity_type} #{response.headers.inspect}"
|
|
51
|
-
collection = Occi::Parser.parse(
|
|
52
|
-
response.content_type, response.body,
|
|
53
|
-
path.include?('/-/'), entity_type, response.headers
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
Occi::Log.debug "Parsed collection: empty? #{collection.empty?}"
|
|
57
|
-
collection
|
|
34
|
+
get_process_response(path, response)
|
|
58
35
|
end
|
|
59
36
|
|
|
60
37
|
# Performs POST requests and returns URI locations. Resource data must be provided
|
|
@@ -69,29 +46,14 @@ module Occi::Api::Client
|
|
|
69
46
|
# post "/network/", collection # => "http://localhost:3300/network/23sf4g65as-asdgsg2-sdfgsf2g"
|
|
70
47
|
# post "/storage/", collection # => "http://localhost:3300/storage/23sf4g65as-asdgsg2-sdfgsf2g"
|
|
71
48
|
#
|
|
72
|
-
# @param [String] path for the POST request
|
|
73
|
-
# @param [Occi::Collection] resource data to be POSTed
|
|
49
|
+
# @param path [String] path for the POST request
|
|
50
|
+
# @param collection [Occi::Collection] resource data to be POSTed
|
|
74
51
|
# @return [Occi::Collection, String, Boolean] Collection, URI location or action result (if ActionInstance is passed)
|
|
75
52
|
def post(path, collection)
|
|
76
53
|
raise ArgumentError, "Path is a required argument!" if path.blank?
|
|
54
|
+
raise ArgumentError, "Collection is a required argument!" if collection.blank?
|
|
77
55
|
|
|
78
|
-
|
|
79
|
-
headers['Content-Type'] = @media_type
|
|
80
|
-
|
|
81
|
-
response = case @media_type
|
|
82
|
-
when 'application/occi+json'
|
|
83
|
-
self.class.post(path,
|
|
84
|
-
:body => collection.to_json,
|
|
85
|
-
:headers => headers)
|
|
86
|
-
when 'text/occi'
|
|
87
|
-
self.class.post(path,
|
|
88
|
-
:headers => collection.to_header.merge(headers))
|
|
89
|
-
else
|
|
90
|
-
self.class.post(path,
|
|
91
|
-
:body => collection.to_text,
|
|
92
|
-
:headers => headers)
|
|
93
|
-
end
|
|
94
|
-
|
|
56
|
+
response = send_coll_request(path, collection)
|
|
95
57
|
response_msg = response_message(response)
|
|
96
58
|
raise "HTTP POST failed! #{response_msg}" unless response.code.between? 200, 201
|
|
97
59
|
|
|
@@ -103,33 +65,18 @@ module Occi::Api::Client
|
|
|
103
65
|
# @example
|
|
104
66
|
# TODO: add examples
|
|
105
67
|
#
|
|
106
|
-
# @param [String] path for the PUT request
|
|
107
|
-
# @param [Occi::Collection] resource data to send
|
|
68
|
+
# @param path [String] path for the PUT request
|
|
69
|
+
# @param collection [Occi::Collection] resource data to send
|
|
108
70
|
# @return [Occi::Collection] parsed result of the request
|
|
109
71
|
def put(path, collection)
|
|
110
72
|
raise ArgumentError, "Path is a required argument!" if path.blank?
|
|
73
|
+
raise ArgumentError, "Collection is a required argument!" if collection.blank?
|
|
111
74
|
|
|
112
|
-
|
|
113
|
-
headers['Content-Type'] = @media_type
|
|
114
|
-
|
|
115
|
-
response = case @media_type
|
|
116
|
-
when 'application/occi+json'
|
|
117
|
-
self.class.post(path,
|
|
118
|
-
:body => collection.to_json,
|
|
119
|
-
:headers => headers)
|
|
120
|
-
when 'text/occi'
|
|
121
|
-
self.class.post(path,
|
|
122
|
-
:headers => collection.to_header.merge(headers))
|
|
123
|
-
else
|
|
124
|
-
self.class.post(path,
|
|
125
|
-
:body => collection.to_text,
|
|
126
|
-
:headers => headers)
|
|
127
|
-
end
|
|
128
|
-
|
|
75
|
+
response = send_coll_request(path, collection, :put)
|
|
129
76
|
response_msg = response_message(response)
|
|
130
77
|
|
|
131
78
|
if response.code.between? 200, 201
|
|
132
|
-
Occi::Parser.parse(response.header["content-type"]
|
|
79
|
+
Occi::Parser.parse(response.header["content-type"], response.body)
|
|
133
80
|
else
|
|
134
81
|
raise "HTTP POST failed! #{response_msg}"
|
|
135
82
|
end
|
|
@@ -140,8 +87,8 @@ module Occi::Api::Client
|
|
|
140
87
|
# @example
|
|
141
88
|
# del "/compute/65sf4g65sf4g-sf6g54sf5g-sfgsf32g3" # => true
|
|
142
89
|
#
|
|
143
|
-
# @param [String] path for the DELETE request
|
|
144
|
-
# @param [Occi::Collection] collection of filters (currently NOT used)
|
|
90
|
+
# @param path [String] path for the DELETE request
|
|
91
|
+
# @param filter [Occi::Collection] collection of filters (currently NOT used)
|
|
145
92
|
# @return [Boolean] status
|
|
146
93
|
def del(path, filter=nil)
|
|
147
94
|
raise ArgumentError, "Path is a required argument!" if path.blank?
|
|
@@ -156,6 +103,54 @@ module Occi::Api::Client
|
|
|
156
103
|
|
|
157
104
|
private
|
|
158
105
|
|
|
106
|
+
def get_process_response(path, response)
|
|
107
|
+
Occi::Log.debug "Response from location: #{path.inspect}"
|
|
108
|
+
kind = @model.get_by_location(path) if @model
|
|
109
|
+
|
|
110
|
+
Occi::Log.debug "Response should contain kind: #{kind.inspect}"
|
|
111
|
+
entity_type = nil
|
|
112
|
+
if kind && kind.related_to?(Occi::Core::Link)
|
|
113
|
+
entity_type = Occi::Core::Link
|
|
114
|
+
end
|
|
115
|
+
entity_type = Occi::Core::Resource unless entity_type
|
|
116
|
+
|
|
117
|
+
Occi::Log.debug "Parser call: #{response.content_type} #{path.include?('/-/')} " \
|
|
118
|
+
"#{entity_type} #{response.headers.inspect}"
|
|
119
|
+
collection = Occi::Parser.parse(
|
|
120
|
+
response.content_type, response.body,
|
|
121
|
+
path.include?('/-/'), entity_type, response.headers
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
Occi::Log.debug "Parsed collection: empty? #{collection.empty?}"
|
|
125
|
+
collection
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def send_coll_request(path, collection, type = :post)
|
|
129
|
+
type ||= :post
|
|
130
|
+
raise ArgumentError, "Unsupported send " \
|
|
131
|
+
"type #{type.to_s.inspect}!" unless [:post, :put].include?(type)
|
|
132
|
+
|
|
133
|
+
headers = self.class.headers.clone
|
|
134
|
+
headers['Content-Type'] = @media_type
|
|
135
|
+
|
|
136
|
+
case @media_type
|
|
137
|
+
when 'application/occi+json'
|
|
138
|
+
self.class.send type,
|
|
139
|
+
path,
|
|
140
|
+
:body => collection.to_json,
|
|
141
|
+
:headers => headers
|
|
142
|
+
when 'text/occi'
|
|
143
|
+
self.class.send type,
|
|
144
|
+
path,
|
|
145
|
+
:headers => collection.to_header.merge(headers)
|
|
146
|
+
else
|
|
147
|
+
self.class.send type,
|
|
148
|
+
path,
|
|
149
|
+
:body => collection.to_text,
|
|
150
|
+
:headers => headers
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
159
154
|
def post_action(response)
|
|
160
155
|
true
|
|
161
156
|
end
|
|
@@ -163,13 +158,13 @@ module Occi::Api::Client
|
|
|
163
158
|
def post_create(response)
|
|
164
159
|
if response.code == 200
|
|
165
160
|
collection = Occi::Parser.parse(
|
|
166
|
-
response.header["content-type"]
|
|
161
|
+
response.header["content-type"],
|
|
167
162
|
response.body
|
|
168
163
|
)
|
|
169
164
|
|
|
170
165
|
if collection.empty?
|
|
171
166
|
Occi::Parser.locations(
|
|
172
|
-
response.header["content-type"]
|
|
167
|
+
response.header["content-type"],
|
|
173
168
|
response.body,
|
|
174
169
|
response.headers
|
|
175
170
|
).first
|
|
@@ -180,15 +175,13 @@ module Occi::Api::Client
|
|
|
180
175
|
end
|
|
181
176
|
else
|
|
182
177
|
Occi::Parser.locations(
|
|
183
|
-
response.header["content-type"]
|
|
178
|
+
response.header["content-type"],
|
|
184
179
|
response.body,
|
|
185
180
|
response.headers
|
|
186
181
|
).first
|
|
187
182
|
end
|
|
188
183
|
end
|
|
189
184
|
|
|
190
|
-
def post_update(response); end
|
|
191
|
-
|
|
192
185
|
end
|
|
193
186
|
|
|
194
187
|
end
|
|
@@ -37,6 +37,21 @@ module Occi::Api::Dsl
|
|
|
37
37
|
@client.get_category_type_identifiers
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
def action_types
|
|
41
|
+
check
|
|
42
|
+
@client.get_action_types
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def action_type_identifier(*args)
|
|
46
|
+
check
|
|
47
|
+
@client.get_action_type_identifier(*args)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def action_type_identifiers
|
|
51
|
+
check
|
|
52
|
+
@client.get_action_type_identifiers
|
|
53
|
+
end
|
|
54
|
+
|
|
40
55
|
def resource_types
|
|
41
56
|
check
|
|
42
57
|
@client.get_resource_types
|
data/lib/occi/api/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: occi-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.2.0.beta.
|
|
4
|
+
version: 4.2.0.beta.9
|
|
5
5
|
prerelease: 6
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- examples/x509auth_example.rb
|
|
85
85
|
- lib/occi-api.rb
|
|
86
86
|
- lib/occi/api/client/authn_utils.rb
|
|
87
|
+
- lib/occi/api/client/base/action_methods.rb
|
|
87
88
|
- lib/occi/api/client/base/category_methods.rb
|
|
88
89
|
- lib/occi/api/client/base/entity_methods.rb
|
|
89
90
|
- lib/occi/api/client/base/helpers.rb
|