openstack-compute 1.1.1 → 1.1.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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -0,0 +1,38 @@
1
+ module OpenStack
2
+ module Compute
3
+
4
+ class AddressList < Array
5
+ def [](index)
6
+ addresses = Array.new
7
+ if index.class == Symbol then
8
+ self.each do |address|
9
+ if address.label == index.to_s then
10
+ addresses << address.address
11
+ end
12
+ end
13
+ addresses
14
+ else
15
+ super
16
+ end
17
+ end
18
+ end
19
+
20
+ class Address
21
+
22
+ attr_reader :address
23
+ attr_reader :label
24
+ attr_reader :version
25
+
26
+ def initialize(label, address, version = 4)
27
+ @label = label
28
+ if address.class == Hash then
29
+ @address = address["addr"]
30
+ @version = address["version"]
31
+ else
32
+ @address = address
33
+ @version = version
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -32,23 +32,35 @@ module Compute
32
32
  raise OpenStack::Compute::Exception::Connection, "Unable to connect to #{server}"
33
33
  end
34
34
 
35
- auth_data = JSON.generate({ "passwordCredentials" => { "username" => connection.authuser, "password" => connection.authkey }})
35
+ auth_data = JSON.generate({ "auth" => { "passwordCredentials" => { "username" => connection.authuser, "password" => connection.authkey }}})
36
36
  response = server.post(connection.auth_path.chomp("/")+"/tokens", auth_data, {'Content-Type' => 'application/json'})
37
37
  if (response.code =~ /^20./)
38
38
  resp_data=JSON.parse(response.body)
39
- connection.authtoken = resp_data['auth']['token']['id']
40
- if resp_data['auth']['serviceCatalog'] and resp_data['auth']['serviceCatalog'][connection.service_name] and resp_data['auth']['serviceCatalog'][connection.service_name][0] then
41
- uri = URI.parse(resp_data['auth']['serviceCatalog'][connection.service_name][0]['publicURL'])
42
- connection.svrmgmthost = uri.host
43
- connection.svrmgmtpath = uri.path
44
- # Force the path into the v1.1 URL space
45
- connection.svrmgmtpath.sub!(/\/.*\/?/, '/v1.1/')
46
- connection.svrmgmtpath += connection.authtenant
47
- connection.svrmgmtport = uri.port
48
- connection.svrmgmtscheme = uri.scheme
49
- connection.authok = true
50
- else
51
- connection.authok = false
39
+ connection.authtoken = resp_data['access']['token']['id']
40
+ resp_data['access']['serviceCatalog'].each do |service|
41
+ if service['type'] == connection.service_name
42
+ uri = String.new
43
+ endpoints = service["endpoints"]
44
+ if connection.region
45
+ endpoints.each do |ep|
46
+ if ep["region"].upcase == connection.region.upcase
47
+ uri = URI.parse(ep["publicURL"])
48
+ end
49
+ end
50
+ if uri == ''
51
+ raise OpenStack::Compute::Exception::Authentication, "No API endpoint for region #{connection.region}"
52
+ end
53
+ else
54
+ uri = URI.parse(endpoints[0]["publicURL"])
55
+ end
56
+ connection.svrmgmthost = uri.host
57
+ connection.svrmgmtpath = uri.path
58
+ connection.svrmgmtport = uri.port
59
+ connection.svrmgmtscheme = uri.scheme
60
+ connection.authok = true
61
+ else
62
+ connection.authok = false
63
+ end
52
64
  end
53
65
  else
54
66
  connection.authtoken = false
@@ -18,6 +18,7 @@ module Compute
18
18
  attr_accessor :service_name
19
19
  attr_reader :proxy_host
20
20
  attr_reader :proxy_port
21
+ attr_reader :region
21
22
 
22
23
  # Creates a new OpenStack::Compute::Connection object. Uses OpenStack::Compute::Authentication to perform the login for the connection.
23
24
  #
@@ -27,7 +28,8 @@ module Compute
27
28
  # :tenant - Your Openstack tenant *required*. Defaults to username.
28
29
  # :api_key - Your Openstack API key *required*
29
30
  # :auth_url - Configurable auth_url endpoint.
30
- # :service_name - (Optional for v2.0 auth only). The name of the compute service to use. Defaults to 'nova'.
31
+ # :service_name - (Optional for v2.0 auth only). The name of the compute service to use. Defaults to 'compute'.
32
+ # :region - (Optional for v2.0 auth only). The specific service region to use. Defaults to first returned region.
31
33
  # :retry_auth - Whether to retry if your auth token expires (defaults to true)
32
34
  # :proxy_host - If you need to connect through a proxy, supply the hostname here
33
35
  # :proxy_port - If you need to connect through a proxy, supply the port here
@@ -38,7 +40,8 @@ module Compute
38
40
  @authkey = options[:api_key] || (raise Exception::MissingArgument, "Must supply an :api_key")
39
41
  @auth_url = options[:auth_url] || (raise Exception::MissingArgument, "Must supply an :auth_url")
40
42
  @authtenant = options[:authtenant] || @authuser
41
- @service_name = options[:service_name] || "nova"
43
+ @service_name = options[:service_name] || "compute"
44
+ @region = options[:region] || @region = nil
42
45
  @is_debug = options[:is_debug]
43
46
 
44
47
  auth_uri=nil
@@ -341,7 +344,7 @@ module Compute
341
344
  data.push({:path => svrpath, :contents => b64})
342
345
  itemcount += 1
343
346
  end
344
- return data
347
+ data
345
348
  end
346
349
 
347
350
  end
@@ -8,6 +8,8 @@ module Compute
8
8
  attr_reader :name
9
9
  attr_reader :status
10
10
  attr_reader :progress
11
+ attr_reader :accessipv4
12
+ attr_reader :accessipv6
11
13
  attr_reader :addresses
12
14
  attr_reader :hostId
13
15
  attr_reader :image
@@ -51,7 +53,7 @@ module Compute
51
53
  @name = data["name"]
52
54
  @status = data["status"]
53
55
  @progress = data["progress"]
54
- @addresses = OpenStack::Compute.symbolize_keys(data["addresses"])
56
+ @addresses = get_addresses(data["addresses"])
55
57
  @metadata = OpenStack::Compute::ServerMetadata.new(@connection, @id)
56
58
  @hostId = data["hostId"]
57
59
  @image = data["image"]
@@ -222,6 +224,19 @@ module Compute
222
224
  @adminPass = password
223
225
  end
224
226
 
227
+ def get_addresses(address_info)
228
+ address_list = OpenStack::Compute::AddressList.new
229
+ address_info.each do |label, addr|
230
+ addr.each do |address|
231
+ address_list << OpenStack::Compute::Address.new(label,address)
232
+ if address_list.last.version == 4 && (!@accessipv4 || accessipv4 == "") then
233
+ @accessipv4 = address_list.last.address
234
+ end
235
+ end
236
+ end
237
+ address_list
238
+ end
239
+
225
240
  end
226
241
  end
227
242
  end
@@ -33,6 +33,7 @@ module Compute
33
33
  require 'compute/image'
34
34
  require 'compute/flavor'
35
35
  require 'compute/exception'
36
+ require 'compute/address'
36
37
 
37
38
  # Constants that set limits on server creation
38
39
  MAX_PERSONALITY_ITEMS = 5
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstack-compute
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Prince
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-14 00:00:00 -04:00
18
+ date: 2011-10-19 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,7 @@ files:
45
45
  - README.rdoc
46
46
  - VERSION
47
47
  - lib/openstack/compute.rb
48
+ - lib/openstack/compute/address.rb
48
49
  - lib/openstack/compute/authentication.rb
49
50
  - lib/openstack/compute/connection.rb
50
51
  - lib/openstack/compute/exception.rb