1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
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
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
16
PYRAX_INSTALLED = True
20
PYRAX_INSTALLED = False
22
from heat.engine import resource
23
from heat.openstack.common import log as logging
25
logger = logging.getLogger(__name__)
28
class RackspaceResource(resource.Resource):
30
Common base class for Rackspace Resource Providers
32
properties_schema = {}
34
def __init__(self, name, json_snippet, stack):
35
super(RackspaceResource, self).__init__(name, json_snippet, stack)
39
self._cloud_dns = None
41
self._cloud_server = None
43
self._cloud_blockstore = None
44
self._authenticated = False
47
'''Rackspace cloud database client.'''
48
if not self._cloud_db:
50
self._cloud_db = self.pyrax.cloud_databases
55
'''Rackspace cloud loadbalancer client.'''
56
if not self._cloud_lb:
58
self._cloud_lb = self.pyrax.cloud_loadbalancers
63
'''Rackspace cloud dns client.'''
64
if not self._cloud_dns:
66
self._cloud_dns = self.pyrax.cloud_dns
68
return self._cloud_dns
71
'''Rackspace cloudservers client.'''
72
if not self._cloud_server:
74
self._cloud_server = self.pyrax.cloudservers
76
return self._cloud_server
79
'''Rackspace cinder client.'''
80
if not self._cloud_blockstore:
82
self._cloud_blockstore = self.pyrax.cloud_blockstorage
84
return self._cloud_blockstore
87
'''Rackspace quantum client.'''
88
if not self._cloud_nw:
90
self._cloud_nw = self.pyrax.cloud_networks
94
def __authenticate(self):
95
# current implemenation shown below authenticates using
96
# username and password. Need make it work with auth-token
97
if not self._authenticated:
98
pyrax.set_setting("identity_type", "keystone")
99
pyrax.set_setting("auth_endpoint", self.context.auth_url)
100
pyrax.set_setting("tenant_id", self.context.tenant)
101
logger.info("Authenticating with username:%s" %
102
self.context.username)
103
pyrax.set_credentials(self.context.username,
104
password=self.context.password)
105
logger.info("User %s authenticated successfully."
106
% self.context.username)
107
self._authenticated = True