# License for the specific language governing permissions and limitations
# under the License.
+from heat.openstack.common import log as logging
+
+logger = logging.getLogger(__name__)
-from novaclient.v1_1 import client as nc
-# swiftclient not available in all distributions - make s3 an optional
-# feature
+from heat.common import heat_keystoneclient as hkc
+from novaclient.v1_1 import client as novaclient
try:
from swiftclient import client as swiftclient
- swiftclient_present = True
except ImportError:
- swiftclient_present = False
-# quantumclient not available in all distributions - make quantum an optional
-# feature
+ swiftclient = None
+ logger.info('swiftclient not available')
try:
from quantumclient.v2_0 import client as quantumclient
- quantumclient_present = True
except ImportError:
- quantumclient_present = False
-
-from heat.common import heat_keystoneclient as kc
-from heat.openstack.common import log as logging
-
-logger = logging.getLogger(__name__)
+ quantumclient = None
+ logger.info('quantumclient not available')
class Clients(object):
if self._keystone:
return self._keystone
- self._keystone = kc.KeystoneClient(self.context)
+ self._keystone = hkc.KeystoneClient(self.context)
return self._keystone
def nova(self, service_type='compute'):
# Workaround for issues with python-keyring, need no_cache=True
# ref https://bugs.launchpad.net/python-novaclient/+bug/1020238
# TODO(shardy): May be able to remove when the bug above is fixed
- client = nc.Client(no_cache=True, **args)
+ client = novaclient.Client(no_cache=True, **args)
client.authenticate()
self._nova[service_type] = client
except TypeError:
# for compatibility with essex, which doesn't have no_cache=True
# TODO(shardy): remove when we no longer support essex
- client = nc.Client(**args)
+ client = novaclient.Client(**args)
client.authenticate()
self._nova[service_type] = client
return client
def swift(self):
- if swiftclient_present == False:
+ if swiftclient is None:
return None
if self._swift:
return self._swift
return self._swift
def quantum(self):
- if quantumclient_present == False:
+ if quantumclient is None:
return None
if self._quantum:
logger.debug('using existing _quantum')
# License for the specific language governing permissions and limitations
# under the License.
+from heat.engine import clients
from heat.common import exception
from heat.engine import resource
-from novaclient.exceptions import NotFound
from heat.openstack.common import log as logging
if self.resource_id is not None:
try:
ips = self.nova().floating_ips.get(self.resource_id)
- except NotFound as ex:
+ except clients.novaclient.exceptions.NotFound as ex:
logger.warn("Floating IPs not found: %s" % str(ex))
else:
self.ipaddress = ips.ip
server = self.nova().servers.get(self.properties['InstanceId'])
if server:
server.remove_floating_ip(self.properties['EIP'])
- except NotFound as ex:
+ except clients.novaclient.exceptions.NotFound as ex:
pass
import json
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
-from novaclient.exceptions import NotFound
import pkgutil
from urlparse import urlparse
+from heat.engine import clients
from heat.engine import resource
from heat.common import exception
if self.ipaddress is None:
try:
server = self.nova().servers.get(self.resource_id)
- except NotFound as ex:
+ except clients.novaclient.exceptions.NotFound as ex:
logger.warn('Instance IP address not found (%s)' % str(ex))
else:
self._set_ipaddress(server.networks)
return
try:
server = self.nova().servers.get(self.resource_id)
- except NotFound:
+ except clients.novaclient.exceptions.NotFound:
pass
else:
server.delete()
while server.status == 'ACTIVE':
try:
server.get()
- except NotFound:
+ except clients.novaclient.exceptions.NotFound:
break
eventlet.sleep(0.2)
self.resource_id = None
# License for the specific language governing permissions and limitations
# under the License.
+from heat.engine import clients
from heat.common import exception
from heat.common import template_format
from heat.engine.resources import stack
-from novaclient.exceptions import NotFound
from heat.openstack.common import log as logging
'''
try:
server = self.nova().servers.get(inst)
- except NotFound as ex:
+ except clients.novaclient.exceptions.NotFound as ex:
logger.warn('Instance (%s) not found: %s' % (inst, str(ex)))
else:
for n in server.networks:
from heat.common import exception
from heat.engine import resource
from heat.openstack.common import log as logging
-try:
- from swiftclient.client import ClientException
- swiftclient_present = True
-except ImportError:
- swiftclient_present = False
+from heat.engine import clients
logger = logging.getLogger(__name__)
Validate any of the provided params
'''
#check if swiftclient is installed
- if swiftclient_present == False:
+ if clients.swiftclient is None:
return {'Error':
- 'S3 services unavaialble because of missing swiftclient.'}
+ 'S3 services unavailable because of missing swiftclient.'}
@staticmethod
def _create_container_name(resource_name):
if self.resource_id is not None:
try:
self.swift().delete_container(self.resource_id)
- except ClientException as ex:
+ except clients.swiftclient.ClientException as ex:
logger.warn("Delete container failed: %s" % str(ex))
def FnGetRefId(self):
# License for the specific language governing permissions and limitations
# under the License.
-from novaclient.exceptions import BadRequest
-from novaclient.exceptions import NotFound
+from heat.engine import clients
from heat.engine import resource
from heat.openstack.common import log as logging
i['FromPort'],
i['ToPort'],
i['CidrIp'])
- except BadRequest as ex:
+ except clients.novaclient.exceptions.BadRequest as ex:
if ex.message.find('already exists') >= 0:
# no worries, the rule is already there
pass
if self.resource_id is not None:
try:
sec = self.nova().security_groups.get(self.resource_id)
- except NotFound:
+ except clients.novaclient.exceptions.NotFound:
pass
else:
for rule in sec.rules:
try:
self.nova().security_group_rules.delete(rule['id'])
- except NotFound:
+ except clients.novaclient.exceptions.NotFound:
pass
self.nova().security_groups.delete(sec)
import eventlet
from heat.openstack.common import log as logging
+from heat.engine import clients
from heat.common import exception
from heat.engine import resource
-from novaclient.exceptions import NotFound
logger = logging.getLogger(__name__)
except Exception:
pass
vol.get()
- except NotFound as e:
+ except clients.novaclient.exceptions.NotFound as e:
logger.warning('Deleting VolumeAttachment %s %s - not found' %
(server_id, volume_id))
- return
def resource_mapping():