~ubuntu-branches/ubuntu/trusty/heat/trusty

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/engine/resources/rackspace/rackspace_resource.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short
  • Date: 2013-08-08 01:08:42 UTC
  • Revision ID: package-import@ubuntu.com-20130808010842-77cni2v4vlib7rus
Tags: 2013.2~b2-0ubuntu4
[ Chuck Short ]
* debian/rules: Enable testsuite during builds.
* debian/patches/fix-sqlalchemy-0.8.patch: Build against sqlalchemy 0.8.
* debian/patches/rename-quantumclient.patch: quantumclient -> neutronclient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
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, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
PYRAX_INSTALLED = True
 
17
try:
 
18
    import pyrax
 
19
except ImportError:
 
20
    PYRAX_INSTALLED = False
 
21
 
 
22
from heat.engine import resource
 
23
from heat.openstack.common import log as logging
 
24
 
 
25
logger = logging.getLogger(__name__)
 
26
 
 
27
 
 
28
class RackspaceResource(resource.Resource):
 
29
    '''
 
30
    Common base class for Rackspace Resource Providers
 
31
    '''
 
32
    properties_schema = {}
 
33
 
 
34
    def __init__(self, name, json_snippet, stack):
 
35
        super(RackspaceResource, self).__init__(name, json_snippet, stack)
 
36
        if PYRAX_INSTALLED:
 
37
            self.pyrax = pyrax
 
38
        self._cloud_db = None
 
39
        self._cloud_dns = None
 
40
        self._cloud_lb = None
 
41
        self._cloud_server = None
 
42
        self._cloud_nw = None
 
43
        self._cloud_blockstore = None
 
44
        self._authenticated = False
 
45
 
 
46
    def cloud_db(self):
 
47
        '''Rackspace cloud database client.'''
 
48
        if not self._cloud_db:
 
49
            self.__authenticate()
 
50
            self._cloud_db = self.pyrax.cloud_databases
 
51
 
 
52
        return self._cloud_db
 
53
 
 
54
    def cloud_lb(self):
 
55
        '''Rackspace cloud loadbalancer client.'''
 
56
        if not self._cloud_lb:
 
57
            self.__authenticate()
 
58
            self._cloud_lb = self.pyrax.cloud_loadbalancers
 
59
 
 
60
        return self._cloud_lb
 
61
 
 
62
    def cloud_dns(self):
 
63
        '''Rackspace cloud dns client.'''
 
64
        if not self._cloud_dns:
 
65
            self.__authenticate()
 
66
            self._cloud_dns = self.pyrax.cloud_dns
 
67
 
 
68
        return self._cloud_dns
 
69
 
 
70
    def nova(self):
 
71
        '''Rackspace cloudservers client.'''
 
72
        if not self._cloud_server:
 
73
            self.__authenticate()
 
74
            self._cloud_server = self.pyrax.cloudservers
 
75
 
 
76
        return self._cloud_server
 
77
 
 
78
    def cinder(self):
 
79
        '''Rackspace cinder client.'''
 
80
        if not self._cloud_blockstore:
 
81
            self.__authenticate()
 
82
            self._cloud_blockstore = self.pyrax.cloud_blockstorage
 
83
 
 
84
        return self._cloud_blockstore
 
85
 
 
86
    def quantum(self):
 
87
        '''Rackspace quantum client.'''
 
88
        if not self._cloud_nw:
 
89
            self.__authenticate()
 
90
            self._cloud_nw = self.pyrax.cloud_networks
 
91
 
 
92
        return self._cloud_nw
 
93
 
 
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