~openstack-gd/nova/lp783478

« back to all changes in this revision

Viewing changes to nova/network/xenapi_net.py

  • Committer: Eldar Nugaev
  • Date: 2011-05-20 09:29:54 UTC
  • mfrom: (1072.2.20 nova)
  • Revision ID: enugaev@griddynamics.com-20110520092954-1pp1aly9c2rtv5br
Merge and conflict resolving

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    License for the specific language governing permissions and limitations
16
16
#    under the License.
17
17
 
18
 
"""
19
 
Implements vlans, bridges, and iptables rules using linux utilities.
20
 
"""
 
18
"""Implements vlans, bridges, and iptables rules using linux utilities."""
21
19
 
22
20
import os
23
21
 
26
24
from nova import flags
27
25
from nova import log as logging
28
26
from nova import utils
29
 
from nova.virt.xenapi_conn import XenAPISession
 
27
from nova.virt import xenapi_conn
30
28
from nova.virt.xenapi import network_utils
31
29
 
 
30
 
32
31
LOG = logging.getLogger("nova.xenapi_net")
33
32
 
 
33
 
34
34
FLAGS = flags.FLAGS
35
35
 
36
36
 
37
37
def ensure_vlan_bridge(vlan_num, bridge, net_attrs=None):
38
38
    """Create a vlan and bridge unless they already exist."""
39
39
    # Open xenapi session
40
 
    LOG.debug("ENTERING ensure_vlan_bridge in xenapi net")
 
40
    LOG.debug('ENTERING ensure_vlan_bridge in xenapi net')
41
41
    url = FLAGS.xenapi_connection_url
42
42
    username = FLAGS.xenapi_connection_username
43
43
    password = FLAGS.xenapi_connection_password
44
 
    session = XenAPISession(url, username, password)
 
44
    session = xenapi_conn.XenAPISession(url, username, password)
45
45
    # Check whether bridge already exists
46
46
    # Retrieve network whose name_label is "bridge"
47
47
    network_ref = network_utils.NetworkHelper.find_network_with_name_label(
50
50
    if network_ref is None:
51
51
        # If bridge does not exists
52
52
        # 1 - create network
53
 
        description = "network for nova bridge %s" % bridge
 
53
        description = 'network for nova bridge %s' % bridge
54
54
        network_rec = {'name_label': bridge,
55
55
                       'name_description': description,
56
56
                       'other_config': {}}
57
57
        network_ref = session.call_xenapi('network.create', network_rec)
58
58
        # 2 - find PIF for VLAN
59
 
        expr = 'field "device" = "%s" and \
60
 
                field "VLAN" = "-1"' % FLAGS.vlan_interface
 
59
        expr = "field 'device' = '%s' and \
 
60
                field 'VLAN' = '-1'" % FLAGS.vlan_interface
61
61
        pifs = session.call_xenapi('PIF.get_all_records_where', expr)
62
62
        pif_ref = None
63
63
        # Multiple PIF are ok: we are dealing with a pool