~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/network/quantum/client.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import socket
22
22
import urllib
23
23
 
24
 
from nova import utils
 
24
from nova.openstack.common import jsonutils
25
25
 
26
26
 
27
27
# FIXME(danwent): All content in this file should be removed once the
35
35
    the standard serializer from the quantum library.
36
36
    """
37
37
    def serialize(self, data, content_type):
38
 
        try:
39
 
            return json.dumps(data)
40
 
        except TypeError:
41
 
            pass
42
 
        return json.dumps(utils.to_primitive(data))
 
38
        return jsonutils.dumps(data)
43
39
 
44
40
    def deserialize(self, data, content_type):
45
 
        return json.loads(data)
 
41
        return jsonutils.loads(data)
 
42
 
46
43
 
47
44
# Quantum API v1.0 uses 420 + 430 for network + port not found
48
45
# Quantum API v1.1 uses 404 for network + port not found
103
100
 
104
101
    def __init__(self, host="127.0.0.1", port=9696, use_ssl=False, tenant=None,
105
102
                 format="xml", testing_stub=None, key_file=None,
106
 
                 cert_file=None, logger=None):
 
103
                 cert_file=None, logger=None, timeout=None):
107
104
        """Creates a new client to some service.
108
105
 
109
106
        :param host: The host where service resides
126
123
        self.key_file = key_file
127
124
        self.cert_file = cert_file
128
125
        self.logger = logger
 
126
        self.timeout = timeout
129
127
 
130
128
    def get_connection_type(self):
131
129
        """Returns the proper connection type"""
167
165
                                      "application/%s" % self.format}
168
166
 
169
167
            # Open connection and send request, handling SSL certs
170
 
            certs = {'key_file': self.key_file, 'cert_file': self.cert_file}
171
 
            certs = dict((x, certs[x]) for x in certs if certs[x] is not None)
172
 
 
173
 
            if self.use_ssl and len(certs):
174
 
                c = connection_type(self.host, self.port, **certs)
175
 
            else:
176
 
                c = connection_type(self.host, self.port)
 
168
            kwargs = {}
 
169
            if self.use_ssl:
 
170
                if self.key_file:
 
171
                    kwargs['key_file'] = self.key_file
 
172
                if self.cert_file:
 
173
                    kwargs['cert_file'] = self.cert_file
 
174
 
 
175
            if self.timeout:
 
176
                kwargs['timeout'] = self.timeout
 
177
 
 
178
            c = connection_type(self.host, self.port, **kwargs)
177
179
 
178
180
            if self.logger:
179
181
                self.logger.debug(
180
 
                    _("Quantum Client Request: %(method)s %(action)s") %
181
 
                                    locals())
 
182
                    _("Quantum Client Request: %(method)s %(action)s"),
 
183
                    locals())
182
184
                if body:
183
185
                    self.logger.debug(body)
184
186
 
193
195
 
194
196
            if status_code in NOT_FOUND_CODES:
195
197
                raise QuantumNotFoundException(
196
 
                    _("Quantum entity not found: %s") % data)
 
198
                    _("Quantum entity not found: %s"), data)
197
199
 
198
200
            if status_code in (httplib.OK,
199
201
                               httplib.CREATED,