occi 2.5.1 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -20,50 +20,84 @@ Installation
20
20
  Usage
21
21
  -----
22
22
 
23
+ Use the Interactive Ruby Shell (IRB) to interact with an OCCI server. If you have the occi gem installed, you just have
24
+ to start irb from the command line:
25
+
26
+ irb
27
+
28
+ If you want to test newer versions of rOCCI, you have to tell irb from where it
29
+ should load occi:
30
+
31
+ cd rOCCI
32
+ irb -I lib
33
+
23
34
  First require the gem, for Ruby 1.8.7 you also have to require rubygems
35
+
24
36
  require 'rubygems'
25
37
  require 'occi'
26
38
 
27
39
  ### Client
28
40
 
29
- The OCCI gem includes a Client to simplify the usage of an OCCI endpoint.
41
+ The OCCI gem includes a Client to simplify the usage of an OCCI endpoint. If you want to use authentication then you
42
+ should create a hash with information either on username and password for basic authentication or with a X.509 user
43
+ certificate, the user certificate password and the path to the Root CAs which are used to verify the certificate of the
44
+ OCCI server.
45
+
46
+ For Basic auth use
47
+
48
+ auth = Hashie::Mash.new
49
+ auth.type = 'basic'
50
+ auth.username = 'user'
51
+ auth.password = 'mypass'
30
52
 
31
- To connect to an OCCI endpoint/server (e.g. running at http://localhost:3000/ ) use
53
+ For Digest auth use
32
54
 
33
- client = OCCI::Client.new('http://occi.cloud.gwdg.de:3300')
55
+ auth = Hashie::Mash.new
56
+ auth.type = 'digest'
57
+ auth.username = 'user'
58
+ auth.password = 'mypass'
59
+
60
+ For X.509 auth use
61
+
62
+ auth = Hashie::Mash.new
63
+ auth.type = 'x509'
64
+ auth.user_cert = '/Path/To/My/usercert.pem'
65
+ auth.user_cert_password = 'MyPassword'
66
+ auth.ca_path = '/Path/To/root-certificates'
67
+
68
+ To connect to an OCCI endpoint/server (e.g. running on http://localhost:3000/ )
69
+
70
+ client = OCCI::Client.new('http://occi.cloud.gwdg.de:3300',auth||=nil)
34
71
 
35
72
  All available categories are automatically registered to the OCCI model during client initialization. You can get them via
36
73
 
37
- OCCI::Model.get
74
+ client.model
38
75
 
39
76
  To get all resources (as a list of OCCI::Resources) currently managed by the endpoint use
40
77
 
41
- client.get_resources
78
+ client.get resources
42
79
 
43
80
  To get only compute, storage or network resources use get_compute_resources, ...
44
81
 
45
82
  To get the location of all resources use
46
83
 
47
- client.get_resource_list
84
+ client.list resources
48
85
 
49
- Analogue for compute, storage, network via get_compute_list, ...
86
+ Analogue for compute, storage, network.
50
87
 
51
88
  To get a list of all OS / resource templates use
52
89
 
53
90
  client.get_os_templates
54
91
  client.get_resource_templates
55
92
 
56
- To get all attributes with their default values for a given category use
57
-
58
- client.get_attributes(client.compute)
59
-
60
93
  To create a new compute resource use
61
94
 
62
95
  os = client.get_os_templates.select { |template| template.term.include? 'my_os' }
63
96
  size = client.get_resource_templates.select { |template| template.term.include? 'large' }
64
- attributes = client.get_attributes([client.compute,os,size])
65
- attributes['occi.core.title'] = "My VM"
66
- client.post_compute(attributes,os,size)
97
+ cmpt = OCCI::Core::Resource.new compute
98
+ cmpt.mixins << os << size
99
+ cmpt.attributes.occi!.core!.title = "My VM"
100
+ client.create cmpt
67
101
 
68
102
  ### Logging
69
103
 
@@ -136,6 +170,12 @@ The OCCI gem includes all OCCI Core classes necessary to handly arbitrary OCCI o
136
170
  Changelog
137
171
  ---------
138
172
 
173
+ ### version 2.5
174
+
175
+ * improved OCCI Client
176
+ * improved documentation
177
+ * several bugfixes
178
+
139
179
  ### Version 2.4
140
180
 
141
181
  * Changed OCCI attribute properties from lowercase to first letter uppercase (e.g. type -> Type, default -> Default, ...)
@@ -1,17 +1,27 @@
1
1
  require 'rubygems'
2
2
  require 'occi'
3
3
  require 'pp'
4
+ require 'hashie/mash'
5
+
6
+ ## options
7
+ use_os_temlate = true # use OS_TEMPLATE or NETWORK + STORAGE + INSTANCE TYPE
8
+ OS_TEMPLATE = 'monitoring' # name of the VM template in ON
9
+
10
+ clean_up_compute = true # issue DELETE <RESOURCE> after we are done
4
11
 
5
12
  USER_CERT = ENV['HOME'] + '/.globus/usercert.pem'
6
- USER_CERT_PASSPWORD = 'mypassphrase'
13
+ USER_CERT_PASSWORD = 'mypassphrase'
7
14
  CA_PATH = '/etc/grid-security/certificates'
8
15
 
16
+ ## get an OCCI::Client instance
9
17
  client = OCCI::Client.new('https://localhost:3300',
10
18
  { :type => "x509",
11
19
  :user_cert => USER_CERT,
12
20
  :user_cert_password => USER_CERT_PASSWORD,
13
21
  :ca_path => CA_PATH })
14
22
 
23
+ ## get detailed information about all available resources
24
+ ## then query each resource category in turn
15
25
  puts "\n\nPrinting all resources"
16
26
  pp client.get resources
17
27
 
@@ -24,6 +34,8 @@ pp client.get network
24
34
  puts "\n\nPrinting compute resources"
25
35
  pp client.get compute
26
36
 
37
+ ## get links of all available resources
38
+ ## then get links for each category in turn
27
39
  puts "\n\nPrinting locations of all resources"
28
40
  pp client.list resources
29
41
 
@@ -36,7 +48,73 @@ pp client.list compute
36
48
  puts "\n\nPrinting locations of network resources"
37
49
  pp client.list network
38
50
 
51
+ ## get detailed information about available OS templates (== VM templates in ON)
52
+ ## and resource templates (== INSTANCE TYPES, e.g. small, medium, large etc.)
53
+ puts "\n\nPrinting OS templates"
54
+ pp client.get_os_templates
55
+
56
+ puts "\n\nPrinting resource templates"
57
+ pp client.get_resource_templates
58
+
59
+ ## create a compute resource using the chosen method
39
60
  puts "\n\nCreate compute resources"
61
+
40
62
  cmpt = OCCI::Core::Resource.new compute
63
+
64
+ unless use_os_temlate
65
+ ## without OS template, we have to manually select and attach
66
+ ## network, storage and resource template (instance type)
67
+
68
+ ## select instance type medium
69
+ cmpt.mixins << 'http://my.occi.service//occi/infrastructure/resource_tpl#medium'
70
+
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]
75
+
76
+ ## create links and attach them to the compure resource
77
+ client.storagelink cmpt, storage_loc
78
+ client.networkinterface cmpt, network_loc
79
+ else
80
+ ## 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.get_os_templates.select { |template| template.term.include? OS_TEMPLATE }
84
+ pp size = client.get_resource_templates.select { |template| template.term.include? 'medium' }
85
+
86
+ ## attach chosen resources to the compute resource
87
+ cmpt.mixins << os << size
88
+ ## we can change some of the values manually
89
+ cmpt.attributes.occi!.core!.title = "My rOCCI VM"
90
+ end
91
+
92
+ ## create the compute resource and print its location
41
93
  cmpt_loc = client.create cmpt
42
- pp "Location of new compute resource: #{cmpt_loc}"
94
+ pp "Location of new compute resource: #{cmpt_loc}"
95
+
96
+ ## get links of all available compute resouces again
97
+ puts "\n\nPrinting locations of compute resources (should now contain #{cmpt_loc})"
98
+ pp client.list compute
99
+
100
+ ## get detailed information about the new compute resource
101
+ ## using Hashie simplifies access to its attributes
102
+ puts "\n\nPrinting information about compute resource #{cmpt_loc}"
103
+ cmpt_data = client.get cmpt_loc.to_s.split('/')[3] + '/' + cmpt_loc.to_s.split('/')[4]
104
+ cmpt_hashie = Hashie::Mash.new(JSON.parse(cmpt_data.to_json))
105
+
106
+ ## wait until the resource is "active"
107
+ while cmpt_hashie.resources.first.attributes.occi.compute.state == "inactive"
108
+ puts "\nCompute resource #{cmpt_loc} is inactive, waiting ..."
109
+ sleep 1
110
+ cmpt_data = client.get cmpt_loc.to_s.split('/')[3] + '/' + cmpt_loc.to_s.split('/')[4]
111
+ cmpt_hashie = Hashie::Mash.new(JSON.parse(cmpt_data.to_json))
112
+ end
113
+
114
+ puts "\nCompute resource #{cmpt_loc} is #{cmpt_hashie.resources.first.attributes.occi.compute.state}"
115
+
116
+ ## delete the resource and exit
117
+ if clean_up_compute
118
+ puts "\n\nDeleting compute resource #{cmpt_loc}"
119
+ pp client.delete cmpt_loc.to_s.split('/')[3] + '/' + cmpt_loc.to_s.split('/')[4]
120
+ end
data/lib/occi/client.rb CHANGED
@@ -142,7 +142,9 @@ module OCCI
142
142
  # @param [String] path
143
143
  # @return [Array] list of URIs
144
144
  def list(path='')
145
- self.class.get(path, :headers => { "Accept" => 'text/uri-list' }).split("\n").compact
145
+ path = path.split('#').last + '/' if path.start_with? 'http://'
146
+ path = path.reverse.chomp('/').reverse
147
+ self.class.get(@endpoint + path, :headers => { "Accept" => 'text/uri-list' }).body.split("\n").compact
146
148
  end
147
149
 
148
150
  # @param [OCCI::Core::Entity] entity
@@ -303,4 +305,4 @@ module OCCI
303
305
  end
304
306
 
305
307
  end
306
- end
308
+ end
@@ -40,10 +40,10 @@ module OCCI
40
40
  @checked = false
41
41
  raise "Kind #{kind} not of type String" unless kind.kind_of? String
42
42
  @kind = kind
43
- @mixins = mixins.to_a
43
+ @mixins = mixins.to_a.flatten
44
44
  @attributes = OCCI::Core::Attributes.new(attributes)
45
45
  @attributes.occi!.core![:id] ||= UUIDTools::UUID.random_create.to_s
46
- @actions = actions.to_a
46
+ @actions = actions.to_a.flatten
47
47
  end
48
48
 
49
49
  # @param [Array] mixins
data/lib/occi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OCCI
2
- VERSION = "2.5.1" unless defined?(::OCCI::VERSION)
2
+ VERSION = "2.5.2" unless defined?(::OCCI::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-09 00:00:00.000000000 Z
13
+ date: 2012-08-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json