24
from nova.virt import xenapi
27
class NetworkHelper(xenapi.HelperBase):
29
The class that wraps the helper methods together.
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:
36
elif len(networks) > 1:
37
raise Exception(_('Found non-unique network'
38
' for name_label %s') % name_label)
43
def find_network_with_bridge(cls, session, bridge):
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.
49
expr = ('field "name__label" = "%s" or field "bridge" = "%s"' %
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)
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:
28
elif len(networks) > 1:
29
raise Exception(_('Found non-unique network for name_label %s') %
35
def find_network_with_bridge(session, bridge):
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.
41
expr = ('field "name__label" = "%s" or field "bridge" = "%s"' %
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)
49
raise Exception(_('Found no network for bridge %s') % bridge)