occi 2.5.3 → 2.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +1 -0
- data/README.md +5 -1
- data/bin/occi +29 -0
- data/examples/dsl_example.rb +158 -0
- data/examples/x509auth_example.rb +90 -60
- data/lib/occi.rb +23 -10
- data/lib/occi/api/client.rb +595 -0
- data/lib/occi/api/dsl.rb +112 -0
- data/lib/occi/collection.rb +0 -3
- data/lib/occi/core.rb +21 -0
- data/lib/occi/core/entity.rb +3 -2
- data/lib/occi/log.rb +1 -2
- data/lib/occi/parser.rb +0 -11
- data/lib/occi/version.rb +1 -1
- data/lib/occiantlr/OCCIANTLR.g +10 -7
- data/lib/occiantlr/OCCIANTLR.tokens +14 -2
- data/lib/occiantlr/OCCIANTLRLexer.rb +584 -348
- data/lib/occiantlr/OCCIANTLRParser.rb +296 -221
- data/occi.gemspec +2 -1
- data/spec/occiantlr/parser_spec.rb +8 -8
- metadata +26 -5
- data/lib/occi/client.rb +0 -308
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -77,7 +77,11 @@ To get all resources (as a list of OCCI::Resources) currently managed by the end
|
|
77
77
|
|
78
78
|
client.get resources
|
79
79
|
|
80
|
-
To get only compute, storage or network resources use
|
80
|
+
To get only compute, storage or network resources use
|
81
|
+
|
82
|
+
client.get compute
|
83
|
+
client.get storage
|
84
|
+
client.get network
|
81
85
|
|
82
86
|
To get the location of all resources use
|
83
87
|
|
data/bin/occi
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# -------------------------------------------------------------------------- #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
+
# not use this file except in compliance with the License. You may obtain #
|
6
|
+
# a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
#--------------------------------------------------------------------------- #
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'occi'
|
19
|
+
require 'pp'
|
20
|
+
require 'logger'
|
21
|
+
|
22
|
+
include OCCI::DSL
|
23
|
+
|
24
|
+
begin
|
25
|
+
puts "This is an OCCI client utility."
|
26
|
+
rescue Exception => ex
|
27
|
+
puts "An error occurred!"
|
28
|
+
exit!
|
29
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
# load and include rOCCI client DSL
|
5
|
+
require 'occi'
|
6
|
+
extend OCCI::DSL
|
7
|
+
|
8
|
+
## options
|
9
|
+
use_os_temlate = true # use OS_TEMPLATE or NETWORK + STORAGE + INSTANCE TYPE
|
10
|
+
OS_TEMPLATE = 'monitoring' # name of the VM template in ON
|
11
|
+
|
12
|
+
clean_up_compute = true # issue DELETE <RESOURCE> after we are done
|
13
|
+
|
14
|
+
USER_CERT = ENV['HOME'] + '/.globus/usercred.pem'
|
15
|
+
USER_CERT_PASSWORD = 'mypassphrase'
|
16
|
+
CA_PATH = '/etc/grid-security/certificates'
|
17
|
+
ENDPOINT = 'https://localhost:3300'
|
18
|
+
|
19
|
+
## establish a connection
|
20
|
+
connect(ENDPOINT,
|
21
|
+
{ :type => "x509",
|
22
|
+
:user_cert => USER_CERT,
|
23
|
+
:user_cert_password => USER_CERT_PASSWORD,
|
24
|
+
:ca_path => CA_PATH },
|
25
|
+
{ :out => STDERR,
|
26
|
+
:level => OCCI::Log::DEBUG })
|
27
|
+
|
28
|
+
puts "\n\nListing all available resource types:"
|
29
|
+
resource_types.each do |type|
|
30
|
+
puts "\n#{type}"
|
31
|
+
end
|
32
|
+
|
33
|
+
puts "\n\nListing all available resource type identifiers:"
|
34
|
+
resource_type_identifiers.each do |type_id|
|
35
|
+
puts "\n#{type_id}"
|
36
|
+
end
|
37
|
+
|
38
|
+
puts "\n\nListing all available mixin types:"
|
39
|
+
mixin_types.each do |mixin_type|
|
40
|
+
puts "\n#{mixin_type}"
|
41
|
+
end
|
42
|
+
|
43
|
+
puts "\n\nListing all available mixin type identifiers:"
|
44
|
+
mixin_type_identifiers.each do |mixin_typeid|
|
45
|
+
puts "\n#{mixin_typeid}"
|
46
|
+
end
|
47
|
+
|
48
|
+
puts "\n\nListing all available mixins:"
|
49
|
+
mixins.each do |mixin|
|
50
|
+
puts "\n#{mixin}"
|
51
|
+
end
|
52
|
+
|
53
|
+
samples = [OS_TEMPLATE, "medium", "large", "small"]
|
54
|
+
|
55
|
+
puts "\n\nFind mixins using their names:"
|
56
|
+
samples.each do |mxn|
|
57
|
+
puts "\n#{mxn}:\n"
|
58
|
+
pp mixin mxn
|
59
|
+
end
|
60
|
+
|
61
|
+
puts "\n\nFind mixins using their names and a type:"
|
62
|
+
samples.each do |mxn|
|
63
|
+
puts "\n#{mxn}:\n"
|
64
|
+
pp mixin(mxn, "os_tpl")
|
65
|
+
end
|
66
|
+
|
67
|
+
puts "\n\nFind mixins using their names and a type:"
|
68
|
+
samples.each do |mxn|
|
69
|
+
puts "\n#{mxn}:\n"
|
70
|
+
pp mixin(mxn, "resource_tpl")
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "\n\nFind mixins using their names (showing detailed descriptions):"
|
74
|
+
samples.each do |mxn|
|
75
|
+
puts "\n#{mxn}:\n"
|
76
|
+
pp mixin(mxn, nil, true)
|
77
|
+
end
|
78
|
+
|
79
|
+
## get links of all available resources
|
80
|
+
puts "\n\nListing storage resources"
|
81
|
+
pp list "storage"
|
82
|
+
|
83
|
+
puts "\n\nListing network resources"
|
84
|
+
pp list "network"
|
85
|
+
|
86
|
+
puts "\n\nListing compute resources"
|
87
|
+
pp list "compute"
|
88
|
+
|
89
|
+
## get detailed information about all available resources
|
90
|
+
puts "\n\nDescribing storage resources"
|
91
|
+
pp describe "storage"
|
92
|
+
|
93
|
+
puts "\n\nDescribing compute resources"
|
94
|
+
pp describe "compute"
|
95
|
+
|
96
|
+
puts "\n\nDescribing network resources"
|
97
|
+
pp describe "network"
|
98
|
+
|
99
|
+
## create a compute resource using the chosen method (os_tpl|strg+ntwrk)
|
100
|
+
puts "\n\nCreate compute resources"
|
101
|
+
cmpt = resource "compute"
|
102
|
+
|
103
|
+
unless use_os_temlate
|
104
|
+
## without OS template, we have to manually select and attach
|
105
|
+
## network, storage and resource template (instance type)
|
106
|
+
|
107
|
+
## select instance type medium
|
108
|
+
cmpt.mixins << mixin('medium', "resource_tpl")
|
109
|
+
|
110
|
+
## list network/storage locations and select the appropriate ones (the first ones in this case)
|
111
|
+
puts "\nUsing:"
|
112
|
+
pp storage_loc = list("storage")[0]
|
113
|
+
pp network_loc = list("network")[0]
|
114
|
+
|
115
|
+
## create links and attach them to the compure resource
|
116
|
+
puts "\n Connecting to our compute:"
|
117
|
+
storagelink cmpt, storage_loc
|
118
|
+
networkinterface cmpt, network_loc
|
119
|
+
else
|
120
|
+
## with OS template, we have to find the template by name
|
121
|
+
## optionally we can change its "size" by choosing an instance type
|
122
|
+
puts "\nUsing:"
|
123
|
+
pp os = mixin(OS_TEMPLATE, "os_tpl")
|
124
|
+
pp size = mixin('medium', "resource_tpl")
|
125
|
+
|
126
|
+
## attach chosen resources to the compute resource
|
127
|
+
cmpt.mixins << os << size
|
128
|
+
## we can change some of the values manually
|
129
|
+
cmpt.attributes.occi!.core!.title = "My rOCCI x509 VM"
|
130
|
+
end
|
131
|
+
|
132
|
+
## create the compute resource and print its location
|
133
|
+
cmpt_loc = create cmpt
|
134
|
+
pp "Location of new compute resource: #{cmpt_loc}"
|
135
|
+
|
136
|
+
## get links of all available compute resouces again
|
137
|
+
puts "\n\nListing locations of compute resources (should now contain #{cmpt_loc})"
|
138
|
+
pp list "compute"
|
139
|
+
|
140
|
+
## get detailed information about the new compute resource
|
141
|
+
puts "\n\nListing information about compute resource #{cmpt_loc}"
|
142
|
+
cmpt_data = describe cmpt_loc
|
143
|
+
pp cmpt_data
|
144
|
+
|
145
|
+
## wait until the resource is "active"
|
146
|
+
while cmpt_data.resources.first.attributes.occi.compute.state == "inactive"
|
147
|
+
puts "\nCompute resource #{cmpt_loc} is inactive, waiting ..."
|
148
|
+
sleep 1
|
149
|
+
cmpt_data = describe cmpt_loc
|
150
|
+
end
|
151
|
+
|
152
|
+
puts "\nCompute resource #{cmpt_loc} is #{cmpt_data.resources.first.attributes.occi.compute.state}"
|
153
|
+
|
154
|
+
## delete the resource and exit
|
155
|
+
if clean_up_compute
|
156
|
+
puts "\n\nDeleting compute resource #{cmpt_loc}"
|
157
|
+
pp delete cmpt_loc
|
158
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'occi'
|
3
3
|
require 'pp'
|
4
|
-
require 'hashie/mash'
|
5
4
|
|
6
5
|
## options
|
7
6
|
use_os_temlate = true # use OS_TEMPLATE or NETWORK + STORAGE + INSTANCE TYPE
|
@@ -9,88 +8,121 @@ OS_TEMPLATE = 'monitoring' # name of the VM template in ON
|
|
9
8
|
|
10
9
|
clean_up_compute = true # issue DELETE <RESOURCE> after we are done
|
11
10
|
|
12
|
-
USER_CERT = ENV['HOME'] + '/.globus/
|
11
|
+
USER_CERT = ENV['HOME'] + '/.globus/usercred.pem'
|
13
12
|
USER_CERT_PASSWORD = 'mypassphrase'
|
14
13
|
CA_PATH = '/etc/grid-security/certificates'
|
15
14
|
|
16
15
|
## get an OCCI::Client instance
|
17
16
|
client = OCCI::Client.new('https://localhost:3300',
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
{ :type => "x509",
|
18
|
+
:user_cert => USER_CERT,
|
19
|
+
:user_cert_password => USER_CERT_PASSWORD,
|
20
|
+
:ca_path => CA_PATH },
|
21
|
+
{ :out => STDERR,
|
22
|
+
:level => OCCI::Log::DEBUG})
|
23
|
+
|
24
|
+
puts "\n\nListing all available resource types:"
|
25
|
+
client.get_resource_types.each do |type|
|
26
|
+
puts "\n#{type}"
|
27
|
+
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
puts "\n
|
26
|
-
|
29
|
+
puts "\n\nListing all available resource type identifiers:"
|
30
|
+
client.get_resource_type_identifiers.each do |type_id|
|
31
|
+
puts "\n#{type_id}"
|
32
|
+
end
|
27
33
|
|
28
|
-
puts "\n\
|
29
|
-
|
34
|
+
puts "\n\nListing all available mixin types:"
|
35
|
+
client.get_mixin_types.each do |mixin_type|
|
36
|
+
puts "\n#{mixin_type}"
|
37
|
+
end
|
30
38
|
|
31
|
-
puts "\n\
|
32
|
-
|
39
|
+
puts "\n\nListing all available mixin type identifiers:"
|
40
|
+
client.get_mixin_type_identifiers.each do |mixin_typeid|
|
41
|
+
puts "\n#{mixin_typeid}"
|
42
|
+
end
|
33
43
|
|
34
|
-
puts "\n\
|
35
|
-
|
44
|
+
puts "\n\nListing all available mixins:"
|
45
|
+
client.get_mixins.each do |mixin|
|
46
|
+
puts "\n#{mixin}"
|
47
|
+
end
|
48
|
+
|
49
|
+
samples = [OS_TEMPLATE, "medium", "large", "small"]
|
50
|
+
|
51
|
+
puts "\n\nFind mixins using their names:"
|
52
|
+
samples.each do |mixin|
|
53
|
+
puts "\n#{mixin}:\n"
|
54
|
+
pp client.find_mixin mixin
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "\n\nFind mixins using their names and a type:"
|
58
|
+
samples.each do |mixin|
|
59
|
+
puts "\n#{mixin}:\n"
|
60
|
+
pp client.find_mixin(mixin, "os_tpl")
|
61
|
+
end
|
62
|
+
|
63
|
+
puts "\n\nFind mixins using their names and a type:"
|
64
|
+
samples.each do |mixin|
|
65
|
+
puts "\n#{mixin}:\n"
|
66
|
+
pp client.find_mixin(mixin, "resource_tpl")
|
67
|
+
end
|
68
|
+
|
69
|
+
puts "\n\nFind mixins using their names (showing detailed descriptions):"
|
70
|
+
samples.each do |mixin|
|
71
|
+
puts "\n#{mixin}:\n"
|
72
|
+
pp client.find_mixin(mixin, nil, true)
|
73
|
+
end
|
36
74
|
|
37
75
|
## get links of all available resources
|
38
|
-
|
39
|
-
|
40
|
-
pp client.list resources
|
76
|
+
puts "\n\nListing storage resources"
|
77
|
+
pp client.list "storage"
|
41
78
|
|
42
|
-
puts "\n\
|
43
|
-
pp client.list
|
79
|
+
puts "\n\nListing network resources"
|
80
|
+
pp client.list "network"
|
44
81
|
|
45
|
-
puts "\n\
|
46
|
-
pp client.list compute
|
82
|
+
puts "\n\nListing compute resources"
|
83
|
+
pp client.list "compute"
|
47
84
|
|
48
|
-
|
49
|
-
|
85
|
+
## get detailed information about all available resources
|
86
|
+
puts "\n\nDescribing storage resources"
|
87
|
+
pp client.describe "storage"
|
50
88
|
|
51
|
-
|
52
|
-
|
53
|
-
puts "\n\nPrinting OS templates"
|
54
|
-
pp client.get_os_templates
|
89
|
+
puts "\n\nDescribing compute resources"
|
90
|
+
pp client.describe "compute"
|
55
91
|
|
56
|
-
puts "\n\
|
57
|
-
pp client.
|
92
|
+
puts "\n\nDescribing network resources"
|
93
|
+
pp client.describe "network"
|
58
94
|
|
59
|
-
## create a compute resource using the chosen method
|
95
|
+
## create a compute resource using the chosen method (os_tpl|strg+ntwrk)
|
60
96
|
puts "\n\nCreate compute resources"
|
61
|
-
|
62
|
-
cmpt = OCCI::Core::Resource.new compute
|
97
|
+
cmpt = client.get_resource "compute"
|
63
98
|
|
64
99
|
unless use_os_temlate
|
65
100
|
## without OS template, we have to manually select and attach
|
66
101
|
## network, storage and resource template (instance type)
|
67
102
|
|
68
103
|
## select instance type medium
|
69
|
-
cmpt.mixins << '
|
104
|
+
cmpt.mixins << client.find_mixin('medium', "resource_tpl")
|
70
105
|
|
71
|
-
## list network/storage locations and select the appropriate ones (the first ones in this case)
|
72
|
-
puts "\nUsing"
|
73
|
-
pp storage_loc = client.list(storage)[0]
|
74
|
-
pp network_loc = client.list(network)[0]
|
106
|
+
## list network/storage locations and select the appropriate ones (the first ones in this case)
|
107
|
+
puts "\nUsing:"
|
108
|
+
pp storage_loc = client.list("storage")[0]
|
109
|
+
pp network_loc = client.list("network")[0]
|
75
110
|
|
76
111
|
## create links and attach them to the compure resource
|
112
|
+
puts "\n Connecting to our compute:"
|
77
113
|
client.storagelink cmpt, storage_loc
|
78
114
|
client.networkinterface cmpt, network_loc
|
79
115
|
else
|
80
116
|
## with OS template, we have to find the template by name
|
81
|
-
## optionally we can change its "size" by choosing an instance type
|
82
|
-
puts "\nUsing"
|
83
|
-
pp os = client.
|
84
|
-
pp size = client.
|
85
|
-
|
86
|
-
puts "\nGetting identifiers"
|
87
|
-
pp os_id = os.first.type_identifier
|
88
|
-
pp size_id = size.first.type_identifier
|
117
|
+
## optionally we can change its "size" by choosing an instance type
|
118
|
+
puts "\nUsing:"
|
119
|
+
pp os = client.find_mixin(OS_TEMPLATE, "os_tpl")
|
120
|
+
pp size = client.find_mixin('medium', "resource_tpl")
|
89
121
|
|
90
122
|
## attach chosen resources to the compute resource
|
91
|
-
cmpt.mixins <<
|
123
|
+
cmpt.mixins << os << size
|
92
124
|
## we can change some of the values manually
|
93
|
-
cmpt.attributes.occi!.core!.title = "My rOCCI VM"
|
125
|
+
cmpt.attributes.occi!.core!.title = "My rOCCI x509 VM"
|
94
126
|
end
|
95
127
|
|
96
128
|
## create the compute resource and print its location
|
@@ -98,27 +130,25 @@ cmpt_loc = client.create cmpt
|
|
98
130
|
pp "Location of new compute resource: #{cmpt_loc}"
|
99
131
|
|
100
132
|
## get links of all available compute resouces again
|
101
|
-
puts "\n\
|
102
|
-
pp client.list compute
|
133
|
+
puts "\n\nListing locations of compute resources (should now contain #{cmpt_loc})"
|
134
|
+
pp client.list "compute"
|
103
135
|
|
104
136
|
## get detailed information about the new compute resource
|
105
|
-
|
106
|
-
|
107
|
-
cmpt_data
|
108
|
-
pp cmpt_hashie = Hashie::Mash.new(JSON.parse(cmpt_data.to_json))
|
137
|
+
puts "\n\nListing information about compute resource #{cmpt_loc}"
|
138
|
+
cmpt_data = client.describe cmpt_loc
|
139
|
+
pp cmpt_data
|
109
140
|
|
110
141
|
## wait until the resource is "active"
|
111
|
-
while
|
142
|
+
while cmpt_data.resources.first.attributes.occi.compute.state == "inactive"
|
112
143
|
puts "\nCompute resource #{cmpt_loc} is inactive, waiting ..."
|
113
144
|
sleep 1
|
114
|
-
cmpt_data = client.
|
115
|
-
cmpt_hashie = Hashie::Mash.new(JSON.parse(cmpt_data.to_json))
|
145
|
+
cmpt_data = client.describe cmpt_loc
|
116
146
|
end
|
117
147
|
|
118
|
-
puts "\nCompute resource #{cmpt_loc} is #{
|
148
|
+
puts "\nCompute resource #{cmpt_loc} is #{cmpt_data.resources.first.attributes.occi.compute.state}"
|
119
149
|
|
120
150
|
## delete the resource and exit
|
121
151
|
if clean_up_compute
|
122
152
|
puts "\n\nDeleting compute resource #{cmpt_loc}"
|
123
|
-
pp client.delete cmpt_loc
|
153
|
+
pp client.delete cmpt_loc
|
124
154
|
end
|
data/lib/occi.rb
CHANGED
@@ -1,18 +1,31 @@
|
|
1
|
+
require 'hashie/mash'
|
2
|
+
|
3
|
+
require 'active_support/json'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
require 'active_support/notifications'
|
6
|
+
|
7
|
+
require 'logger'
|
8
|
+
|
9
|
+
require 'uuidtools'
|
10
|
+
|
11
|
+
require 'httparty'
|
12
|
+
|
13
|
+
require 'nokogiri'
|
14
|
+
|
15
|
+
require 'rubygems/package'
|
16
|
+
|
17
|
+
require 'zlib'
|
18
|
+
|
19
|
+
require 'tempfile'
|
20
|
+
|
1
21
|
require 'occi/version'
|
2
22
|
require 'occi/parser'
|
3
23
|
require 'occi/model'
|
4
24
|
require 'occi/log'
|
5
|
-
require 'occi/
|
25
|
+
require 'occi/api/dsl'
|
26
|
+
require 'occi/api/client'
|
6
27
|
require 'occi/collection'
|
7
|
-
require 'occi/core
|
8
|
-
require 'occi/core/attribute_properties'
|
9
|
-
require 'occi/core/attributes'
|
10
|
-
require 'occi/core/category'
|
11
|
-
require 'occi/core/entity'
|
12
|
-
require 'occi/core/kind'
|
13
|
-
require 'occi/core/link'
|
14
|
-
require 'occi/core/mixin'
|
15
|
-
require 'occi/core/resource'
|
28
|
+
require 'occi/core'
|
16
29
|
|
17
30
|
require 'occiantlr/OCCIANTLRLexer'
|
18
31
|
require 'occiantlr/OCCIANTLRParser'
|