Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[openstack|compute] Add Tenants and Fix Authentication Implementation

Fixed typorgraphical errors. Authentication assumes or does not require
certain parameters that is actually needed depending on the setup or
scenario. Opted to simply make it detect it if not specified to make it
easier for first time users to use.

Conflicts:

	lib/fog/openstack.rb
  • Loading branch information...
commit 7cf6031c813e6be34ac258224bd4fb1ce352d65d 1 parent 330c28c
Nelvin Driz authored February 22, 2012

Showing 32 changed files with 325 additions and 103 deletions. Show diff stats Hide diff stats

  1. 53  .fog
  2. 1  fog.gemspec
  3. 62  lib/fog/openstack.rb
  4. 80  lib/fog/openstack/compute.rb
  5. 1  lib/fog/openstack/models/compute/addresses.rb
  6. 2  lib/fog/openstack/models/compute/key_pair.rb
  7. 12  lib/fog/openstack/models/compute/key_pairs.rb
  8. 2  lib/fog/openstack/models/compute/security_group.rb
  9. 8  lib/fog/openstack/models/compute/security_groups.rb
  10. 20  lib/fog/openstack/models/compute/server.rb
  11. 19  lib/fog/openstack/models/compute/tenant.rb
  12. 16  lib/fog/openstack/models/compute/tenants.rb
  13. 2  lib/fog/openstack/requests/compute/allocate_address.rb
  14. 6  lib/fog/openstack/requests/compute/associate_address.rb
  15. 2  lib/fog/openstack/requests/compute/create_key_pair.rb
  16. 2  lib/fog/openstack/requests/compute/create_security_group.rb
  17. 2  lib/fog/openstack/requests/compute/create_security_group_rule.rb
  18. 2  lib/fog/openstack/requests/compute/delete_key_pair.rb
  19. 2  lib/fog/openstack/requests/compute/delete_security_group.rb
  20. 2  lib/fog/openstack/requests/compute/delete_security_group_rule.rb
  21. 8  lib/fog/openstack/requests/compute/disassociate_address.rb
  22. 4  lib/fog/openstack/requests/compute/get_address.rb
  23. 2  lib/fog/openstack/requests/compute/get_security_group.rb
  24. 4  lib/fog/openstack/requests/compute/list_all_addresses.rb
  25. 2  lib/fog/openstack/requests/compute/list_key_pairs.rb
  26. 2  lib/fog/openstack/requests/compute/list_security_group.rb
  27. 23  lib/fog/openstack/requests/compute/list_security_groups.rb
  28. 43  lib/fog/openstack/requests/compute/list_tenants.rb
  29. 2  lib/fog/openstack/requests/compute/release_address.rb
  30. 21  lib/fog/openstack/requests/compute/set_tenant.rb
  31. 2  tests/helpers/mock_helper.rb
  32. 19  tests/openstack/requests/compute/tenant_tests.rb
53  .fog
... ...
@@ -0,0 +1,53 @@
  1
+:default:
  2
+  :aws_access_key_id:
  3
+  :aws_secret_access_key:
  4
+  :bluebox_api_key:
  5
+  :bluebox_customer_id:
  6
+  :brightbox_client_id:
  7
+  :brightbox_secret:
  8
+  :clodo_api_key:
  9
+  :clodo_username:
  10
+  :go_grid_api_key:
  11
+  :go_grid_shared_secret:
  12
+  :google_storage_access_key_id:
  13
+  :google_storage_secret_access_key:
  14
+  :linode_api_key:
  15
+  :local_root:
  16
+  :new_servers_password:
  17
+  :new_servers_username:
  18
+  :public_key_path:
  19
+  :private_key_path:
  20
+  :openstack_api_key:
  21
+  :openstack_username:
  22
+  :openstack_auth_url:
  23
+  :openstack_tenant:
  24
+  :ovirt_username:
  25
+  :ovirt_password:
  26
+  :ovirt_url:
  27
+  :rackspace_api_key:
  28
+  :rackspace_username:
  29
+  :rackspace_servicenet:
  30
+  :rackspace_cdn_ssl:
  31
+  :slicehost_password:
  32
+  :stormondemand_username:
  33
+  :stormondemand_password:
  34
+  :terremark_username:
  35
+  :terremark_password:
  36
+  :voxel_api_key:
  37
+  :voxel_api_secret:
  38
+  :zerigo_email:
  39
+  :zerigo_token:
  40
+  :dnsimple_email:
  41
+  :dnsimple_password:
  42
+  :dnsmadeeasy_api_key:
  43
+  :dnsmadeeasy_secret_key:
  44
+  :cloudstack_host:
  45
+  :cloudstack_api_key:
  46
+  :cloudstack_secret_access_key:
  47
+  :vsphere_server:
  48
+  :vsphere_username:
  49
+  :vsphere_password:
  50
+  :libvirt_username:
  51
+  :libvirt_password:
  52
+  :libvirt_uri:
  53
+  :libvirt_ip_command:
1  fog.gemspec
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
63 63
   s.add_development_dependency('shindo', '~>0.3.4')
64 64
   s.add_development_dependency('virtualbox', '~>0.9.1')
65 65
   s.add_development_dependency('fission')
  66
+  s.add_development_dependency('pry')
66 67
 #  s.add_development_dependency('ruby-libvirt','~>0.4.0')
67 68
 
68 69
   s.files = `git ls-files`.split("\n")
62  lib/fog/openstack.rb
@@ -45,9 +45,8 @@ def self.slurp(error)
45 45
 
46 46
     # legacy v1.0 style auth
47 47
     def self.authenticate_v1(options, connection_options = {})
48  
-      openstack_auth_url = options[:openstack_auth_url]
49  
-      uri = URI.parse(openstack_auth_url)
50  
-      connection = Fog::Connection.new(openstack_auth_url, false, connection_options)
  48
+      uri = options[:openstack_auth_uri]
  49
+      connection = Fog::Connection.new(uri.to_s, false, connection_options)
51 50
       @openstack_api_key  = options[:openstack_api_key]
52 51
       @openstack_username = options[:openstack_username]
53 52
       response = connection.request({
@@ -63,19 +62,18 @@ def self.authenticate_v1(options, connection_options = {})
63 62
 
64 63
       return {
65 64
         :token => response.headers['X-Auth-Token'],
66  
-        :server_management_url => response.headers['X-Server-Management-Url'] 
67  
-      } 
  65
+        :server_management_url => response.headers['X-Server-Management-Url']
  66
+      }
68 67
 
69 68
     end
70 69
 
71  
-   # keystone style auth
72  
-   def self.authenticate_v2(options, connection_options = {})
73  
-      openstack_auth_url = options[:openstack_auth_url]
74  
-      uri = URI.parse(openstack_auth_url)
75  
-      connection = Fog::Connection.new(openstack_auth_url, false, connection_options)
  70
+    # Keystone Style Auth
  71
+    def self.authenticate_v2(options, connection_options = {})
  72
+      uri = options[:openstack_auth_uri]
  73
+      connection = Fog::Connection.new(uri.to_s, false, connection_options)
76 74
       @openstack_api_key  = options[:openstack_api_key]
77 75
       @openstack_username = options[:openstack_username]
78  
-      @openstack_tenant = options[:openstack_tenant]
  76
+      @openstack_tenant   = options[:openstack_tenant]
79 77
       @compute_service_name = options[:openstack_compute_service_name]
80 78
 
81 79
       req_body= {
@@ -88,21 +86,47 @@ def self.authenticate_v2(options, connection_options = {})
88 86
       }
89 87
       req_body['auth']['tenantName'] = @openstack_tenant if @openstack_tenant
90 88
 
  89
+      body = retrieve_tokens_v2(connection, req_body, uri)
  90
+      svc = body['access']['serviceCatalog'].detect{|x| x['name'] == @compute_service_name}
  91
+
  92
+      unless svc
  93
+        unless @openstack_tenant
  94
+          response = connection.request({
  95
+            :expects => [200, 204],
  96
+            :headers => {'Content-Type' => 'application/json',
  97
+                         'X-Auth-Token' => body['access']['token']['id']},
  98
+            :host    => uri.host,
  99
+            :method  => 'GET',
  100
+            :path    => '/v2.0/tenants'
  101
+          })
  102
+
  103
+          body = MultiJson.decode(response.body)
  104
+          req_body['auth']['tenantName'] = body['tenants'].first['name']
  105
+        end
  106
+
  107
+        body = retrieve_tokens_v2(connection, req_body, uri)
  108
+        svc = body['access']['serviceCatalog'].
  109
+          detect {|x| x['endpoints'].detect{|y| y['publicURL'].match(/(1\.1|2\.0)/) } }
  110
+      end
  111
+
  112
+      mgmt_url = svc['endpoints'].detect{|x| x['publicURL']}['publicURL']
  113
+      token = body['access']['token']['id']
  114
+
  115
+      { :token => token,
  116
+        :server_management_url => mgmt_url }
  117
+    end
  118
+
  119
+    def self.retrieve_tokens_v2(connection, request_body, uri)
91 120
       response = connection.request({
92 121
         :expects  => [200, 204],
93  
-        :headers => {'Content-Type' => 'application/json'},
  122
+        :headers  => {'Content-Type' => 'application/json'},
94 123
         :body  => Fog::JSON.encode(req_body),
95 124
         :host     => uri.host,
96 125
         :method   => 'POST',
97 126
         :path     =>  (uri.path and not uri.path.empty?) ? uri.path : 'v2.0'
98 127
       })
99  
-      body=Fog::JSON.decode(response.body)
100  
-     
101  
-      return {
102  
-        :token => body['access']['token']['id'],
103  
-        :access => body['access']
104  
-      } 
105  
- 
  128
+
  129
+      Fog::JSON.decode(response.body)
106 130
     end
107 131
 
108 132
   end
80  lib/fog/openstack/compute.rb
@@ -24,6 +24,8 @@ class OpenStack < Fog::Service
24 24
       collection  :key_pairs
25 25
       model       :security_group
26 26
       collection  :security_groups
  27
+      model       :tenant
  28
+      collection  :tenants
27 29
 
28 30
 
29 31
       request_path 'fog/openstack/requests/compute'
@@ -33,14 +35,14 @@ class OpenStack < Fog::Service
33 35
       request :get_flavor_details
34 36
       request :get_image_details
35 37
       request :get_server_details
36  
-      
  38
+
37 39
       request :list_flavors
38 40
       request :list_flavors_detail
39 41
       request :list_images
40 42
       request :list_images_detail
41 43
       request :list_servers
42 44
       request :list_servers_detail
43  
-      
  45
+
44 46
 
45 47
       request :server_action
46 48
       request :change_password_server
@@ -61,28 +63,29 @@ class OpenStack < Fog::Service
61 63
       request :update_meta
62 64
       request :delete_meta
63 65
 
64  
-
65 66
       request :list_all_addresses
66 67
       request :list_private_addresses
67  
-      request :list_public_addresses      
  68
+      request :list_public_addresses
68 69
       request :allocate_address
69 70
       request :associate_address
70 71
       request :disassociate_address
71 72
       request :get_address
72 73
       request :list_addresses
73 74
       request :release_address
74  
-      
  75
+
75 76
       request :create_security_group
76 77
       request :create_security_group_rule
77 78
       request :delete_security_group
78 79
       request :delete_security_group_rule
79 80
       request :list_security_groups
80 81
       request :get_security_group
81  
-      
  82
+
82 83
       request :create_key_pair
83 84
       request :delete_key_pair
84 85
       request :list_key_pairs
85  
-      
  86
+
  87
+      request :list_tenants
  88
+      request :set_tenant
86 89
 
87 90
       class Mock
88 91
 
@@ -138,18 +141,24 @@ def reset_data
138 141
       class Real
139 142
 
140 143
         def initialize(options={})
141  
-          @openstack_api_key = options[:openstack_api_key]
  144
+          @openstack_api_key  = options[:openstack_api_key]
142 145
           @openstack_username = options[:openstack_username]
143  
-          @openstack_tenant = options[:openstack_tenant]
144  
-          @openstack_compute_service_name = options[:openstack_compute_service_name] || 'nova'
145  
-          @openstack_auth_url = options[:openstack_auth_url]
  146
+          @openstack_tenant   = options[:openstack_tenant]
  147
+          @openstack_auth_uri   = URI.parse(options[:openstack_auth_url])
146 148
           @openstack_auth_token = options[:openstack_auth_token]
147  
-          @openstack_management_url = options[:openstack_management_url]
148  
-          @openstack_must_reauthenticate = false
  149
+          @openstack_management_url       = options[:openstack_management_url]
  150
+          @openstack_must_reauthenticate  = false
  151
+          @openstack_compute_service_name = options[:openstack_compute_service_name] || 'nova'
  152
+
149 153
           @connection_options = options[:connection_options] || {}
  154
+
150 155
           authenticate
  156
+
151 157
           @persistent = options[:persistent] || false
152 158
           @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
  159
+          @identity_connection = Fog::Connection.new(
  160
+            "#{@openstack_auth_uri.scheme}://#{@openstack_auth_uri.host}:#{@openstack_auth_uri.port}",
  161
+            false, @connection_options)
153 162
         end
154 163
 
155 164
         def reload
@@ -164,7 +173,7 @@ def request(params)
164 173
                 'X-Auth-Token' => @auth_token
165 174
               }.merge!(params[:headers] || {}),
166 175
               :host     => @host,
167  
-              :path     => "#{@path}/#{params[:path]}",
  176
+              :path     => "#{@path}/#{@tenant_id}/#{params[:path]}",
168 177
               :query    => ('ignore_awful_caching' << Time.now.to_i.to_s)
169 178
             }))
170 179
           rescue Excon::Errors::Unauthorized => error
@@ -172,20 +181,22 @@ def request(params)
172 181
               @openstack_must_reauthenticate = true
173 182
               authenticate
174 183
               retry
175  
-            else # bad credentials
  184
+            else # Bad Credentials
176 185
               raise error
177 186
             end
178 187
           rescue Excon::Errors::HTTPStatusError => error
179 188
             raise case error
180  
-            when Excon::Errors::NotFound
181  
-              Fog::Compute::OpenStack::NotFound.slurp(error)
182  
-            else
183  
-              error
184  
-            end
  189
+              when Excon::Errors::NotFound
  190
+                Fog::Compute::OpenStack::NotFound.slurp(error)
  191
+              else
  192
+                error
  193
+              end
185 194
           end
  195
+
186 196
           unless response.body.empty?
187 197
             response.body = Fog::JSON.decode(response.body)
188 198
           end
  199
+
189 200
           response
190 201
         end
191 202
 
@@ -196,38 +207,31 @@ def authenticate
196 207
             options = {
197 208
               :openstack_api_key  => @openstack_api_key,
198 209
               :openstack_username => @openstack_username,
199  
-              :openstack_auth_url => @openstack_auth_url,
200  
-              :openstack_tenant => @openstack_tenant,
  210
+              :openstack_auth_uri => @openstack_auth_uri,
  211
+              :openstack_tenant   => @openstack_tenant,
201 212
               :openstack_compute_service_name => @openstack_compute_service_name
202 213
             }
203  
-            if @openstack_auth_url =~ /\/v2.0\//
  214
+
  215
+            if @openstack_auth_uri.path =~ /\/v2.0\//
204 216
               credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
205 217
             else
206 218
               credentials = Fog::OpenStack.authenticate_v1(options, @connection_options)
207 219
             end
208  
-            @auth_token = credentials[:token]
209  
-            
210  
-            if svc = credentials[:access]['serviceCatalog'].detect{|x| x['name'] == @openstack_compute_service_name}
211  
-              mgmt_url = svc['endpoints'].detect{|x| x['publicURL']}['publicURL']
212 220
 
213  
-              url = mgmt_url
214  
-              uri = URI.parse(url)
215  
-            else
216  
-              raise "Unable to find Compute service in Catalog."
217  
-            end
  221
+            @openstack_must_reauthenticate = false
  222
+            @auth_token = credentials[:token]
  223
+            @openstack_management_url = credentials[:server_management_url]
  224
+            uri = URI.parse(@openstack_management_url)
218 225
           else
219 226
             @auth_token = @openstack_auth_token
220 227
             uri = URI.parse(@openstack_management_url)
221 228
           end
  229
+
222 230
           @host   = uri.host
223  
-          @path   = uri.path
224  
-          @path.sub!(/\/$/, '')
225  
-          unless @path.match(/1\.1/)
226  
-            raise Fog::Compute::OpenStack::ServiceUnavailable.new(
227  
-                    "OpenStack binding only supports version 1.1")
228  
-          end
  231
+          @path, @tenant_id = uri.path.scan(/(\/.*)\/(.*)/).flatten
229 232
           @port   = uri.port
230 233
           @scheme = uri.scheme
  234
+          true
231 235
         end
232 236
 
233 237
       end
1  lib/fog/openstack/models/compute/addresses.rb
@@ -14,7 +14,6 @@ def all
14 14
         end
15 15
 
16 16
         def get(address_id)
17  
-          
18 17
           if address = connection.get_address(address_id).body['floating_ip']
19 18
             new(address)
20 19
           end
2  lib/fog/openstack/models/compute/key_pair.rb
@@ -2,7 +2,7 @@
2 2
 
3 3
 module Fog
4 4
   module Compute
5  
-    class Openstack
  5
+    class OpenStack
6 6
 
7 7
       class KeyPair < Fog::Model
8 8
 
12  lib/fog/openstack/models/compute/key_pairs.rb
@@ -3,16 +3,16 @@
3 3
 
4 4
 module Fog
5 5
   module Compute
6  
-    class HP
  6
+    class OpenStack
7 7
 
8 8
       class KeyPairs < Fog::Collection
9 9
 
10  
-        model Fog::Compute::Openstack::KeyPair
  10
+        model Fog::Compute::OpenStack::KeyPair
11 11
 
12 12
         def all
13  
-          items = []
  13
+          items = Array.new
14 14
           connection.list_key_pairs.body['keypairs'].each do |kp|
15  
-            items = items + kp.map { |key, value| value }
  15
+            items = items + kp.values
16 16
           end
17 17
           load(items)
18 18
         end
@@ -21,11 +21,11 @@ def get(key_pair_name)
21 21
           if key_pair_name
22 22
             self.all.select {|kp| kp.name == key_pair_name}.first
23 23
           end
24  
-        rescue Fog::Compute::Openstack::NotFound
  24
+        rescue Fog::Compute::OpenStack::NotFound
25 25
           nil
26 26
         end
27 27
 
28 28
       end
29 29
     end
30 30
   end
31  
-end
  31
+end
2  lib/fog/openstack/models/compute/security_group.rb
@@ -2,7 +2,7 @@
2 2
 
3 3
 module Fog
4 4
   module Compute
5  
-    class Openstack
  5
+    class OpenStack
6 6
 
7 7
       class SecurityGroup < Fog::Model
8 8
 
8  lib/fog/openstack/models/compute/security_groups.rb
@@ -3,11 +3,11 @@
3 3
 
4 4
 module Fog
5 5
   module Compute
6  
-    class Openstack
  6
+    class OpenStack
7 7
 
8 8
       class SecurityGroups < Fog::Collection
9 9
 
10  
-        model Fog::Compute::Openstack::SecurityGroup
  10
+        model Fog::Compute::OpenStack::SecurityGroup
11 11
 
12 12
         def all
13 13
           load(connection.list_security_groups.body['security_groups'])
@@ -17,11 +17,11 @@ def get(security_group_id)
17 17
           if security_group_id
18 18
             new(connection.get_security_group(security_group_id).body['security_group'])
19 19
           end
20  
-        rescue Fog::Compute::Openstack::NotFound
  20
+        rescue Fog::Compute::OpenStack::NotFound
21 21
           nil
22 22
         end
23 23
 
24 24
       end
25 25
     end
26 26
   end
27  
-end
  27
+end
20  lib/fog/openstack/models/compute/server.rb
@@ -23,24 +23,24 @@ class Server < Fog::Compute::Server
23 23
         attribute :availability_zone
24 24
         attribute :user_data_encoded
25 25
         attribute :state,       :aliases => 'status'
26  
-        
  26
+
27 27
         attribute :tenant_id
28 28
         attribute :user_id
29 29
         attribute :key_name
30  
-        
  30
+
31 31
 
32 32
         attr_reader :password
33 33
         attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username, :image_ref, :flavor_ref
34  
-        
35  
-        
  34
+
  35
+
36 36
         def initialize(attributes={})
37 37
           @connection = attributes[:connection]
38 38
           attributes[:metadata] = {}
39  
-          
  39
+
40 40
           self.security_groups = attributes.delete(:security_groups)
41 41
           self.min_count = attributes.delete(:min_count)
42 42
           self.max_count = attributes.delete(:max_count)
43  
-          
  43
+
44 44
           super
45 45
         end
46 46
 
@@ -77,7 +77,7 @@ def images
77 77
         def private_ip_address
78 78
           nil
79 79
         end
80  
-        
  80
+
81 81
         def private_key_path
82 82
           @private_key_path ||= Fog.credentials[:private_key_path]
83 83
           @private_key_path &&= File.expand_path(@private_key_path)
@@ -90,7 +90,7 @@ def private_key
90 90
         def public_ip_address
91 91
           addresses['public'].first
92 92
         end
93  
-        
  93
+
94 94
         def public_key_path
95 95
           @public_key_path ||= Fog.credentials[:public_key_path]
96 96
           @public_key_path &&= File.expand_path(@public_key_path)
@@ -149,11 +149,11 @@ def confirm_resize
149 149
           connection.confirm_resize_server(id)
150 150
           true
151 151
         end
152  
-        
  152
+
153 153
         def security_groups=(new_security_groups)
154 154
           @security_groups = new_security_groups
155 155
         end
156  
-        
  156
+
157 157
         def reboot(type = 'SOFT')
158 158
           requires :id
159 159
           connection.reboot_server(id, type)
19  lib/fog/openstack/models/compute/tenant.rb
... ...
@@ -0,0 +1,19 @@
  1
+require 'fog/core/model'
  2
+
  3
+module Fog
  4
+  module Compute
  5
+    class OpenStack
  6
+      class Tenant < Fog::Model
  7
+        identity :id
  8
+
  9
+        attribute :description
  10
+        attribute :enabled
  11
+        attribute :name
  12
+
  13
+        def to_s
  14
+          self.name
  15
+        end
  16
+      end # class Tenant
  17
+    end # class OpenStack
  18
+  end # module Compute
  19
+end # module Fog
16  lib/fog/openstack/models/compute/tenants.rb
... ...
@@ -0,0 +1,16 @@
  1
+require 'fog/core/collection'
  2
+require 'fog/openstack/models/compute/tenant'
  3
+
  4
+module Fog
  5
+  module Compute
  6
+    class OpenStack
  7
+      class Tenants < Fog::Collection
  8
+        model Fog::Compute::OpenStack::Tenant
  9
+
  10
+        def all
  11
+          load(connection.list_tenants.body['tenants'])
  12
+        end
  13
+      end # class Tenants
  14
+    end # class OpenStack
  15
+  end # module Compute
  16
+end # module Fog
2  lib/fog/openstack/requests/compute/allocate_address.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def allocate_address
6  lib/fog/openstack/requests/compute/associate_address.rb
... ...
@@ -1,18 +1,18 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def associate_address(server_id, ip_address)
7 7
           body = { 'addFloatingIp' => { 'server' => server_id, 'address' => ip_address }}
8  
-          
  8
+
9 9
           request(
10 10
             :body     => MultiJson.encode(body),
11 11
             :expects  => 202,
12 12
             :method   => 'POST',
13 13
             :path     => "servers/#{server_id}/action.json"
14 14
           )
15  
-          
  15
+
16 16
         end
17 17
 
18 18
       end
2  lib/fog/openstack/requests/compute/create_key_pair.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def create_key_pair(key_name, public_key = nil)
2  lib/fog/openstack/requests/compute/create_security_group.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def create_security_group(name, description)
2  lib/fog/openstack/requests/compute/create_security_group_rule.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
2  lib/fog/openstack/requests/compute/delete_key_pair.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def delete_key_pair(key_name)
2  lib/fog/openstack/requests/compute/delete_security_group.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def delete_security_group(security_group_id)
2  lib/fog/openstack/requests/compute/delete_security_group_rule.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def delete_security_group_rule(security_group_rule_id)
8  lib/fog/openstack/requests/compute/disassociate_address.rb
... ...
@@ -1,20 +1,20 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def disassociate_address(server_id, ip_address)
7 7
 
8 8
           body = { 'removeFloatingIp' => { 'server' => server_id, 'address' => ip_address }}
9  
-          
  9
+
10 10
           request(
11 11
             :body     => MultiJson.encode(body),
12 12
             :expects  => 202,
13 13
             :method   => 'POST',
14 14
             :path     => "servers/#{server_id}/action.json"
15 15
           )
16  
-          
17  
-          
  16
+
  17
+
18 18
         end
19 19
 
20 20
       end
4  lib/fog/openstack/requests/compute/get_address.rb
... ...
@@ -1,10 +1,10 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def get_address(address_id)
7  
-          
  7
+
8 8
           request(
9 9
             :expects  => [200],
10 10
             :method   => 'GET',
2  lib/fog/openstack/requests/compute/get_security_group.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def get_security_group(security_group_id)
4  lib/fog/openstack/requests/compute/list_all_addresses.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def list_all_addresses(server_id)
@@ -9,7 +9,7 @@ def list_all_addresses(server_id)
9 9
             :method   => 'GET',
10 10
             :path     => "os-floating-ips.json"
11 11
           )
12  
-          
  12
+
13 13
         end
14 14
 
15 15
       end
2  lib/fog/openstack/requests/compute/list_key_pairs.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def list_key_pairs
2  lib/fog/openstack/requests/compute/list_security_group.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def list_security_groups
23  lib/fog/openstack/requests/compute/list_security_groups.rb
... ...
@@ -0,0 +1,23 @@
  1
+module Fog
  2
+  module Compute
  3
+    class OpenStack
  4
+      class Real
  5
+
  6
+        def list_security_groups
  7
+          request(
  8
+            :expects  => [200],
  9
+            :method   => 'GET',
  10
+            :path     => 'os-security-groups.json'
  11
+          )
  12
+        end
  13
+
  14
+      end
  15
+
  16
+      class Mock
  17
+
  18
+
  19
+
  20
+      end
  21
+    end
  22
+  end
  23
+end
43  lib/fog/openstack/requests/compute/list_tenants.rb
... ...
@@ -0,0 +1,43 @@
  1
+module Fog
  2
+  module Compute
  3
+    class OpenStack
  4
+      class Real
  5
+        def list_tenants
  6
+          response = @identity_connection.request({
  7
+            :expects => [200, 204],
  8
+            :headers => {'Content-Type' => 'application/json',
  9
+                         'X-Auth-Token' => @auth_token},
  10
+            :method  => 'GET',
  11
+            :path    => '/v2.0/tenants'
  12
+          })
  13
+          response.body = MultiJson.decode(response.body)
  14
+          response
  15
+        end
  16
+      end
  17
+
  18
+      class Mock
  19
+        def list_tenants
  20
+          response = Excon::Response.new
  21
+          response.status = [200, 204][rand(1)]
  22
+          response.body = {
  23
+            'tenants' => [
  24
+              {'id' => '1',
  25
+               'description' => 'Has access to everything',
  26
+               'enabled' => true,
  27
+               'name' => 'admin'},
  28
+              {'id' => '2',
  29
+               'description' => 'Normal tenant',
  30
+               'enabled' => true,
  31
+               'name' => 'default'},
  32
+              {'id' => '3',
  33
+               'description' => 'Disabled tenant',
  34
+               'enabled' => false,
  35
+               'name' => 'disabled'}
  36
+            ]
  37
+          }
  38
+          response
  39
+        end
  40
+      end # class Mock
  41
+    end #class OpenStack
  42
+  end # module Compute
  43
+end # module Fog
2  lib/fog/openstack/requests/compute/release_address.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Fog
2 2
   module Compute
3  
-    class Openstack
  3
+    class OpenStack
4 4
       class Real
5 5
 
6 6
         def release_address(address_id)
21  lib/fog/openstack/requests/compute/set_tenant.rb
... ...
@@ -0,0 +1,21 @@
  1
+module Fog
  2
+  module Compute
  3
+    class OpenStack
  4
+
  5
+      class Real
  6
+        def set_tenant(tenant)
  7
+          @openstack_must_reauthenticate = true
  8
+          @openstack_tenant = tenant.to_s
  9
+          authenticate
  10
+        end
  11
+      end
  12
+
  13
+      class Mock
  14
+        def set_tenant(tenant)
  15
+          true
  16
+        end
  17
+      end
  18
+
  19
+    end # class OpenStack
  20
+  end # module Compute
  21
+end # module Fog
2  tests/helpers/mock_helper.rb
@@ -50,7 +50,7 @@
50 50
     :openstack_api_key                => 'openstack_api_key',
51 51
     :openstack_username               => 'openstack_username',
52 52
     :openstack_tenant                 => 'openstack_tenant',
53  
-    :openstack_auth_url               => 'openstack_auth_url',
  53
+    :openstack_auth_url               => 'http://openstack:35357/v2.0/tokens',
54 54
     :ovirt_url                        => 'http://ovirt:8080/api',
55 55
     :ovirt_username                   => 'admin@internal',
56 56
     :ovirt_password                   => '123123',
19  tests/openstack/requests/compute/tenant_tests.rb
... ...
@@ -0,0 +1,19 @@
  1
+Shindo.tests('Fog::Compute[:openstack] | tenant requests', ['openstack']) do
  2
+
  3
+  @tenant_format = {
  4
+    'id'    => String,
  5
+    'name'  => String,
  6
+    'enabled'    => Fog::Boolean,
  7
+    'description' => String
  8
+  }
  9
+
  10
+  tests('success') do
  11
+    tests('#list_tenants').formats({'tenants' => [@tenant_format]}) do
  12
+      Fog::Compute[:openstack].list_tenants.body
  13
+    end
  14
+
  15
+    tests('#set_tenant("admin")').succeeds do
  16
+      Fog::Compute[:openstack].set_tenant("admin")
  17
+    end
  18
+  end
  19
+end

0 notes on commit 7cf6031

Please sign in to comment.
Something went wrong with that request. Please try again.