~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/volume/nexenta/jsonrpc.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
#
3
 
# Copyright 2011 Nexenta Systems, Inc.
4
 
# All Rights Reserved.
5
 
#
6
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
7
 
#    not use this file except in compliance with the License. You may obtain
8
 
#    a copy of the License at
9
 
#
10
 
#         http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
#    Unless required by applicable law or agreed to in writing, software
13
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 
#    License for the specific language governing permissions and limitations
16
 
#    under the License.
17
 
"""
18
 
:mod:`nexenta.jsonrpc` -- Nexenta-specific JSON RPC client
19
 
=====================================================================
20
 
 
21
 
.. automodule:: nexenta.jsonrpc
22
 
.. moduleauthor:: Yuriy Taraday <yorik.sar@gmail.com>
23
 
"""
24
 
 
25
 
import urllib2
26
 
 
27
 
from nova.openstack.common import jsonutils
28
 
from nova.openstack.common import log as logging
29
 
from nova.volume import nexenta
30
 
 
31
 
LOG = logging.getLogger(__name__)
32
 
 
33
 
 
34
 
class NexentaJSONException(nexenta.NexentaException):
35
 
    pass
36
 
 
37
 
 
38
 
class NexentaJSONProxy(object):
39
 
    def __init__(self, url, user, password, auto=False, obj=None, method=None):
40
 
        self.url = url
41
 
        self.user = user
42
 
        self.password = password
43
 
        self.auto = auto
44
 
        self.obj = obj
45
 
        self.method = method
46
 
 
47
 
    def __getattr__(self, name):
48
 
        if not self.obj:
49
 
            obj, method = name, None
50
 
        elif not self.method:
51
 
            obj, method = self.obj, name
52
 
        else:
53
 
            obj, method = '%s.%s' % (self.obj, self.method), name
54
 
        return NexentaJSONProxy(self.url, self.user, self.password, self.auto,
55
 
                                obj, method)
56
 
 
57
 
    def __call__(self, *args):
58
 
        data = jsonutils.dumps({'object': self.obj,
59
 
                                'method': self.method,
60
 
                                'params': args})
61
 
        auth = ('%s:%s' % (self.user, self.password)).encode('base64')[:-1]
62
 
        headers = {'Content-Type': 'application/json',
63
 
                   'Authorization': 'Basic %s' % (auth,)}
64
 
        LOG.debug(_('Sending JSON data: %s'), data)
65
 
        request = urllib2.Request(self.url, data, headers)
66
 
        response_obj = urllib2.urlopen(request)
67
 
        if response_obj.info().status == 'EOF in headers':
68
 
            if self.auto and self.url.startswith('http://'):
69
 
                LOG.info(_('Auto switching to HTTPS connection to %s'),
70
 
                                                                      self.url)
71
 
                self.url = 'https' + self.url[4:]
72
 
                request = urllib2.Request(self.url, data, headers)
73
 
                response_obj = urllib2.urlopen(request)
74
 
            else:
75
 
                LOG.error(_('No headers in server response'))
76
 
                raise NexentaJSONException(_('Bad response from server'))
77
 
 
78
 
        response_data = response_obj.read()
79
 
        LOG.debug(_('Got response: %s'), response_data)
80
 
        response = jsonutils.loads(response_data)
81
 
        if response.get('error') is not None:
82
 
            raise NexentaJSONException(response['error'].get('message', ''))
83
 
        else:
84
 
            return response.get('result')