17
17
# @author: Kaiwei Fan, VMware, Inc.
18
18
# @author: Bo Link, VMware, Inc.
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
118
121
status_level = RouterStatus.ROUTER_STATUS_ERROR
119
122
return status_level
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',
121
132
def get_edge_status(self, edge_id):
123
134
response = self.vcns.get_edge_status(edge_id)[1]
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
301
312
edge = self._assemble_edge(
565
579
static_routes = []
566
580
for route in routes:
567
581
static_routes.append({
570
"vnic": vcns_const.INTERNAL_VNIC_INDEX,
571
"network": route['cidr'],
572
"nextHop": route['nexthop']
583
"vnic": vcns_const.INTERNAL_VNIC_INDEX,
584
"network": route['cidr'],
585
"nextHop": route['nexthop']
577
"staticRoutes": static_routes,
589
"staticRoutes": static_routes
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)
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"):
618
'display_name': name,
631
'display_name': utils.check_and_truncate(name),
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
637
if port_isolation is bool:
638
lsconfig["port_isolation_enabled"] = port_isolation
640
lsconfig["replication_mode"] = replication_mode
627
642
response = self.vcns.create_lswitch(lsconfig)[1]
630
645
def delete_lswitch(self, lswitch_id):
631
646
self.vcns.delete_lswitch(lswitch_id)
648
def get_loadbalancer_config(self, edge_id):
650
header, response = self.vcns.get_loadbalancer_config(
652
except exceptions.VcnsApiException:
653
with excutils.save_and_reraise_exception():
654
LOG.exception(_("Failed to get service config"))
657
def enable_service_loadbalancer(self, edge_id):
658
config = self.get_loadbalancer_config(
660
if not config['enabled']:
661
config['enabled'] = True
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 "