~ubuntu-branches/ubuntu/quantal/nova/quantal-security

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/network_utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2012-06-22 12:39:57 UTC
  • mfrom: (1.1.57)
  • Revision ID: package-import@ubuntu.com-20120622123957-hbzwg84nt9rqwg8r
Tags: 2012.2~f2~20120621.14517-0ubuntu1
[ Chuck Short ]
* New upstream version.

[ Adam Gandelman ]
* debian/rules: Temporarily disable test suite while blocking
  tests are investigated. 
* debian/patches/kombu_tests_timeout.patch: Dropped.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
"""
22
22
 
23
23
 
24
 
from nova.virt import xenapi
25
 
 
26
 
 
27
 
class NetworkHelper(xenapi.HelperBase):
28
 
    """
29
 
    The class that wraps the helper methods together.
30
 
    """
31
 
    @classmethod
32
 
    def find_network_with_name_label(cls, session, name_label):
33
 
        networks = session.call_xenapi('network.get_by_name_label', name_label)
34
 
        if len(networks) == 1:
35
 
            return networks[0]
36
 
        elif len(networks) > 1:
37
 
            raise Exception(_('Found non-unique network'
38
 
                              ' for name_label %s') % name_label)
39
 
        else:
40
 
            return None
41
 
 
42
 
    @classmethod
43
 
    def find_network_with_bridge(cls, session, bridge):
44
 
        """
45
 
        Return the network on which the bridge is attached, if found.
46
 
        The bridge is defined in the nova db and can be found either in the
47
 
        'bridge' or 'name_label' fields of the XenAPI network record.
48
 
        """
49
 
        expr = ('field "name__label" = "%s" or field "bridge" = "%s"' %
50
 
                (bridge, bridge))
51
 
        networks = session.call_xenapi('network.get_all_records_where', expr)
52
 
        if len(networks) == 1:
53
 
            return networks.keys()[0]
54
 
        elif len(networks) > 1:
55
 
            raise Exception(_('Found non-unique network'
56
 
                              ' for bridge %s') % bridge)
57
 
        else:
58
 
            raise Exception(_('Found no network for bridge %s') % bridge)
 
24
def find_network_with_name_label(session, name_label):
 
25
    networks = session.call_xenapi('network.get_by_name_label', name_label)
 
26
    if len(networks) == 1:
 
27
        return networks[0]
 
28
    elif len(networks) > 1:
 
29
        raise Exception(_('Found non-unique network for name_label %s') %
 
30
                        name_label)
 
31
    else:
 
32
        return None
 
33
 
 
34
 
 
35
def find_network_with_bridge(session, bridge):
 
36
    """
 
37
    Return the network on which the bridge is attached, if found.
 
38
    The bridge is defined in the nova db and can be found either in the
 
39
    'bridge' or 'name_label' fields of the XenAPI network record.
 
40
    """
 
41
    expr = ('field "name__label" = "%s" or field "bridge" = "%s"' %
 
42
            (bridge, bridge))
 
43
    networks = session.call_xenapi('network.get_all_records_where', expr)
 
44
    if len(networks) == 1:
 
45
        return networks.keys()[0]
 
46
    elif len(networks) > 1:
 
47
        raise Exception(_('Found non-unique network for bridge %s') % bridge)
 
48
    else:
 
49
        raise Exception(_('Found no network for bridge %s') % bridge)