~ubuntu-branches/ubuntu/saucy/neutron/saucy

« back to all changes in this revision

Viewing changes to neutron/plugins/nicira/vshield/edge_appliance_driver.py

  • Committer: Package Import Robot
  • Author(s): James Page, Yolanda Robla, Chuck Short, James Page
  • Date: 2013-10-03 15:18:04 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131003151804-ho3t21wv16l8402y
Tags: 1:2013.2~rc1-0ubuntu1
[ Yolanda Robla ]
* debian/tests: added testing agents

[ Chuck Short ]
* debian/patches/disable-udev-tests.patch: Refreshed.
* debian/patches/disable-ml2-notification-tests.patch: Refreshed.
* debian/control:
  - Dropped python-setuptools-git python-netifaces, and python-nose from
    build dependencies.
  - Dropped python-configobj, python-gflags from binary dependencies.
  - Added build python-requests python-six, and python-jinja2 build
    dependencies.
  - Added versioned dependencies for python-amqplib,
    python-pbr, python-novaclient, python-cliff,
    python-testtools, and python-eventlet.
  - Bumped versioned depends for python-stevedore, pyhton-novaclient,
    python-oslo.config, and testrepository

[ James Page ]
* New upstream release candidate:
  - d/patches: Refreshed.
* d/rules: unpatch/patch neutron.conf around test execution to ensure that
  as many tests as possible actually pass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# @author: Kaiwei Fan, VMware, Inc.
18
18
# @author: Bo Link, VMware, Inc.
19
19
 
 
20
from neutron.openstack.common import excutils
20
21
from neutron.openstack.common import jsonutils
21
22
from neutron.openstack.common import log as logging
 
23
from neutron.plugins.nicira.common import utils
22
24
from neutron.plugins.nicira.vshield.common import (
23
25
    constants as vcns_const)
24
26
from neutron.plugins.nicira.vshield.common.constants import RouterStatus
100
102
            }
101
103
            if secondary:
102
104
                address_group['secondaryAddresses'] = {
103
 
                    'ipAddress': secondary
 
105
                    'ipAddress': secondary,
 
106
                    'type': 'IpAddressesDto'
104
107
                }
105
108
 
106
109
            vnic['addressGroups'] = {
118
121
            status_level = RouterStatus.ROUTER_STATUS_ERROR
119
122
        return status_level
120
123
 
 
124
    def _enable_loadbalancer(self, edge):
 
125
        if not edge.get('featureConfigs') or (
 
126
            not edge['featureConfigs'].get('features')):
 
127
            edge['featureConfigs'] = {'features': []}
 
128
        edge['featureConfigs']['features'].append(
 
129
            {'featureType': 'loadbalancer_4.0',
 
130
             'enabled': True})
 
131
 
121
132
    def get_edge_status(self, edge_id):
122
133
        try:
123
134
            response = self.vcns.get_edge_status(edge_id)[1]
295
306
            raise e
296
307
 
297
308
    def deploy_edge(self, router_id, name, internal_network, jobdata=None,
298
 
                    wait_for_exec=False):
 
309
                    wait_for_exec=False, loadbalancer_enable=True):
299
310
        task_name = 'deploying-%s' % name
300
311
        edge_name = name
301
312
        edge = self._assemble_edge(
318
329
            vcns_const.INTEGRATION_SUBNET_NETMASK,
319
330
            type="internal")
320
331
        edge['vnics']['vnics'].append(vnic_inside)
 
332
        if loadbalancer_enable:
 
333
            self._enable_loadbalancer(edge)
321
334
        userdata = {
322
335
            'request': edge,
323
336
            'router_name': name,
506
519
        LOG.debug(_("VCNS: start updating nat rules: %s"), rules)
507
520
 
508
521
        nat = {
 
522
            'featureType': 'nat',
509
523
            'rules': {
510
524
                'natRulesDtos': rules
511
525
            }
565
579
        static_routes = []
566
580
        for route in routes:
567
581
            static_routes.append({
568
 
                "route": {
569
 
                    "description": "",
570
 
                    "vnic": vcns_const.INTERNAL_VNIC_INDEX,
571
 
                    "network": route['cidr'],
572
 
                    "nextHop": route['nexthop']
573
 
                }
 
582
                "description": "",
 
583
                "vnic": vcns_const.INTERNAL_VNIC_INDEX,
 
584
                "network": route['cidr'],
 
585
                "nextHop": route['nexthop']
574
586
            })
575
587
        request = {
576
 
            "staticRouting": {
577
 
                "staticRoutes": static_routes,
 
588
            "staticRoutes": {
 
589
                "staticRoutes": static_routes
578
590
            }
579
591
        }
580
592
        if gateway:
581
 
            request["staticRouting"]["defaultRoute"] = {
 
593
            request["defaultRoute"] = {
582
594
                "description": "default-gateway",
583
595
                "gatewayAddress": gateway,
584
596
                "vnic": vcns_const.EXTERNAL_VNIC_INDEX
613
625
        self.task_manager.add(task)
614
626
        return task
615
627
 
616
 
    def create_lswitch(self, name, tz_config):
 
628
    def create_lswitch(self, name, tz_config, tags=None,
 
629
                       port_isolation=False, replication_mode="service"):
617
630
        lsconfig = {
618
 
            'display_name': name,
619
 
            "tags": [],
 
631
            'display_name': utils.check_and_truncate(name),
 
632
            "tags": tags or [],
620
633
            "type": "LogicalSwitchConfig",
621
634
            "_schema": "/ws.v1/schema/LogicalSwitchConfig",
622
 
            "port_isolation_enabled": False,
623
 
            "replication_mode": "service",
624
635
            "transport_zones": tz_config
625
636
        }
 
637
        if port_isolation is bool:
 
638
            lsconfig["port_isolation_enabled"] = port_isolation
 
639
        if replication_mode:
 
640
            lsconfig["replication_mode"] = replication_mode
626
641
 
627
642
        response = self.vcns.create_lswitch(lsconfig)[1]
628
643
        return response
629
644
 
630
645
    def delete_lswitch(self, lswitch_id):
631
646
        self.vcns.delete_lswitch(lswitch_id)
 
647
 
 
648
    def get_loadbalancer_config(self, edge_id):
 
649
        try:
 
650
            header, response = self.vcns.get_loadbalancer_config(
 
651
                edge_id)
 
652
        except exceptions.VcnsApiException:
 
653
            with excutils.save_and_reraise_exception():
 
654
                LOG.exception(_("Failed to get service config"))
 
655
        return response
 
656
 
 
657
    def enable_service_loadbalancer(self, edge_id):
 
658
        config = self.get_loadbalancer_config(
 
659
            edge_id)
 
660
        if not config['enabled']:
 
661
            config['enabled'] = True
 
662
        try:
 
663
            self.vcns.enable_service_loadbalancer(edge_id, config)
 
664
        except exceptions.VcnsApiException:
 
665
            with excutils.save_and_reraise_exception():
 
666
                LOG.exception(_("Failed to enable loadbalancer "
 
667
                                "service config"))