コード例 #1
0
    def _handle_backup_edge(self, context, binding):
        dist = (binding['edge_type'] == nsxv_constants.VDR_EDGE)
        result = True
        az = self.azs.get_availability_zone(binding['availability_zone'])
        try:
            update_result = self.plugin.nsx_v.update_edge(
                context,
                binding['router_id'],
                binding['edge_id'],
                binding['router_id'],
                None,
                appliance_size=binding['appliance_size'],
                dist=dist,
                availability_zone=az)

            if update_result:
                nsxv_db.update_nsxv_router_binding(context.session,
                                                   binding['router_id'],
                                                   status=constants.ACTIVE)
        except Exception as e:
            LOG.error(
                'Housekeeping: failed to recover Edge '
                'appliance %s with exception %s', binding['edge_id'], e)
            update_result = False

        if not update_result:
            LOG.warning(
                'Housekeeping: failed to recover Edge '
                'appliance %s, trying to delete', binding['edge_id'])
            result = self._delete_edge(context, binding, dist)

        return result
コード例 #2
0
    def _handle_backup_edge(self, context, binding):
        dist = (binding['edge_type'] == nsxv_constants.VDR_EDGE)
        result = True
        az = self.azs.get_availability_zone(
            binding['availability_zone'])
        try:
            update_result = self.plugin.nsx_v.update_edge(
                context, binding['router_id'], binding['edge_id'],
                binding['router_id'], None,
                appliance_size=binding['appliance_size'],
                dist=dist, availability_zone=az)

            if update_result:
                nsxv_db.update_nsxv_router_binding(
                    context.session, binding['router_id'],
                    status=constants.ACTIVE)
        except Exception as e:
            LOG.error('Housekeeping: failed to recover Edge '
                      'appliance %s with exception %s',
                      binding['edge_id'], e)
            update_result = False

        if not update_result:
            LOG.warning('Housekeeping: failed to recover Edge '
                        'appliance %s, trying to delete', binding['edge_id'])
            result = self._delete_edge(context, binding, dist)

        return result
コード例 #3
0
    def _update_router_bindings(self, context, edge_id):
        edge_router_binds = nsxv_db.get_nsxv_router_bindings_by_edge(
            context.session, edge_id)

        for b in edge_router_binds:
            nsxv_db.update_nsxv_router_binding(context.session,
                                               b['router_id'],
                                               status='ACTIVE')
コード例 #4
0
    def _delete_edge(self, context, binding, dist):
        try:
            nsxv_db.update_nsxv_router_binding(
                context.session, binding['router_id'],
                status=constants.PENDING_DELETE)
        except sa_exc.NoResultFound:
            LOG.debug("Housekeeping: Router binding %s does not exist.",
                      binding['router_id'])

        try:
            self.plugin.nsx_v.delete_edge(context, binding['router_id'],
                                          binding['edge_id'], dist=dist)
            return True

        except Exception as e:
            LOG.warning('Housekeeping: Failed to delete edge %s with '
                        'exception %s', binding['edge_id'], e)
コード例 #5
0
    def _delete_edge(self, context, binding, dist):
        try:
            nsxv_db.update_nsxv_router_binding(context.session,
                                               binding['router_id'],
                                               status=constants.PENDING_DELETE)
        except sa_exc.NoResultFound:
            LOG.debug("Housekeeping: Router binding %s does not exist.",
                      binding['router_id'])

        try:
            self.plugin.nsx_v.delete_edge(context,
                                          binding['router_id'],
                                          binding['edge_id'],
                                          dist=dist)
        except Exception as e:
            LOG.warning(
                'Housekeeping: Failed to delete edge %s with '
                'exception %s', binding['edge_id'], e)
コード例 #6
0
    def update_router(self, context, router_id, router):
        r = router['router']
        is_routes_update = True if 'routes' in r else False

        gw_info = self.plugin._extract_external_gw(context,
                                                   router,
                                                   is_extract=True)
        super(nsx_v.NsxVPluginV2,
              self.plugin).update_router(context, router_id, router)
        if gw_info != n_consts.ATTR_NOT_SPECIFIED:
            self.plugin._update_router_gw_info(context, router_id, gw_info,
                                               is_routes_update)
        elif is_routes_update:
            # here is used to handle routes which tenant updates.
            router_db = self.plugin._get_router(context, router_id)
            nexthop = self.plugin._get_external_attachment_info(
                context, router_db)[2]
            self.plugin._update_subnets_and_dnat_firewall(context, router_db)
            self.update_routes(context, router_id, nexthop)
        if 'admin_state_up' in r:
            self.plugin._update_router_admin_state(context, router_id,
                                                   self.get_type(),
                                                   r['admin_state_up'])
        if 'name' in r:
            self.edge_manager.rename_lrouter(context, router_id, r['name'])
        if r.get('router_size'):
            edge_id = edge_utils.get_router_edge_id(context, router_id)
            with locking.LockManager.get_lock(edge_id):
                edge_cfg = self.vcns.get_edge(edge_id)[1]
                if edge_cfg.get('appliances'):
                    edge_cfg['appliances']['applianceSize'] = r['router_size']
                    self.vcns.update_edge(edge_id, edge_cfg)
                    nsxv_db.update_nsxv_router_binding(
                        context.session,
                        router_id,
                        appliance_size=r['router_size'])
        return self.plugin.get_router(context, router_id)
コード例 #7
0
    def deploy_edge(self,
                    context,
                    router_id,
                    name,
                    internal_network,
                    dist=False,
                    loadbalancer_enable=True,
                    appliance_size=nsxv_constants.LARGE,
                    availability_zone=None):

        edge_name = name
        edge = self._assemble_edge(
            edge_name,
            datacenter_moid=self.datacenter_moid,
            deployment_container_id=self.deployment_container_id,
            appliance_size=appliance_size,
            remote_access=False,
            dist=dist,
            edge_ha=availability_zone.edge_ha)
        appliances = self._assemble_edge_appliances(availability_zone)
        if appliances:
            edge['appliances']['appliances'] = appliances

        if not dist:
            vnic_external = self._assemble_edge_vnic(
                constants.EXTERNAL_VNIC_NAME,
                constants.EXTERNAL_VNIC_INDEX,
                self.external_network,
                type="uplink")
            edge['vnics']['vnics'].append(vnic_external)
        else:
            edge['mgmtInterface'] = {
                'connectedToId': self.external_network,
                'name': "mgmtInterface"
            }
        if internal_network:
            vnic_inside = self._assemble_edge_vnic(
                constants.INTERNAL_VNIC_NAME,
                constants.INTERNAL_VNIC_INDEX,
                internal_network,
                constants.INTEGRATION_EDGE_IPADDRESS,
                constants.INTEGRATION_SUBNET_NETMASK,
                type="internal")
            edge['vnics']['vnics'].append(vnic_inside)

        # If default login credentials for Edge are set, configure accordingly
        if (cfg.CONF.nsxv.edge_appliance_user
                and cfg.CONF.nsxv.edge_appliance_password):
            edge['cliSettings'].update({
                'userName':
                cfg.CONF.nsxv.edge_appliance_user,
                'password':
                cfg.CONF.nsxv.edge_appliance_password
            })

        if not dist and loadbalancer_enable:
            self._enable_loadbalancer(edge)

        edge_id = None
        try:
            header = self.vcns.deploy_edge(edge)[0]
            edge_id = header.get('location', '/').split('/')[-1]

            if edge_id:
                nsxv_db.update_nsxv_router_binding(context.session,
                                                   router_id,
                                                   edge_id=edge_id)
                if not dist:
                    # Init Edge vnic binding
                    nsxv_db.init_edge_vnic_binding(context.session, edge_id)
            else:
                if router_id:
                    nsxv_db.update_nsxv_router_binding(
                        context.session, router_id, status=plugin_const.ERROR)
                error = _('Failed to deploy edge')
                raise nsxv_exc.NsxPluginException(err_msg=error)

            self.callbacks.complete_edge_creation(context, edge_id, name,
                                                  router_id, dist, True)

        except exceptions.VcnsApiException:
            self.callbacks.complete_edge_creation(context, edge_id, name,
                                                  router_id, dist, False)
            with excutils.save_and_reraise_exception():
                LOG.exception(_LE("NSXv: deploy edge failed."))
        return edge_id
コード例 #8
0
    def deploy_edge(self, context, router_id, name, internal_network,
                    dist=False, loadbalancer_enable=True,
                    appliance_size=nsxv_constants.LARGE,
                    availability_zone=None, deploy_metadata=False):

        edge_name = name
        edge = self._assemble_edge(
            edge_name, datacenter_moid=availability_zone.datacenter_moid,
            deployment_container_id=self.deployment_container_id,
            appliance_size=appliance_size, remote_access=False, dist=dist,
            edge_ha=availability_zone.edge_ha)
        appliances = self._assemble_edge_appliances(availability_zone)
        if appliances:
            edge['appliances']['appliances'] = appliances

        if not dist:
            vnic_external = self._assemble_edge_vnic(
                constants.EXTERNAL_VNIC_NAME, constants.EXTERNAL_VNIC_INDEX,
                availability_zone.external_network, type="uplink")
            edge['vnics']['vnics'].append(vnic_external)
        else:
            edge['mgmtInterface'] = {
                'connectedToId': availability_zone.external_network,
                'name': "mgmtInterface"}
        if internal_network:
            vnic_inside = self._assemble_edge_vnic(
                constants.INTERNAL_VNIC_NAME, constants.INTERNAL_VNIC_INDEX,
                internal_network,
                edge_utils.get_vdr_transit_network_plr_address(),
                edge_utils.get_vdr_transit_network_netmask(),
                type="internal")
            edge['vnics']['vnics'].append(vnic_inside)

        # If default login credentials for Edge are set, configure accordingly
        if (cfg.CONF.nsxv.edge_appliance_user and
            cfg.CONF.nsxv.edge_appliance_password):
            edge['cliSettings'].update({
                'userName': cfg.CONF.nsxv.edge_appliance_user,
                'password': cfg.CONF.nsxv.edge_appliance_password})

        if not dist and loadbalancer_enable:
            self._enable_loadbalancer(edge)

        edge_id = None
        try:
            header = self.vcns.deploy_edge(edge)[0]
            edge_id = header.get('location', '/').split('/')[-1]

            if edge_id:
                nsxv_db.update_nsxv_router_binding(
                    context.session, router_id, edge_id=edge_id)
                if not dist:
                    # Init Edge vnic binding
                    nsxv_db.init_edge_vnic_binding(
                        context.session, edge_id)
            else:
                if router_id:
                    nsxv_db.update_nsxv_router_binding(
                        context.session, router_id,
                        status=lib_const.ERROR)
                error = _('Failed to deploy edge')
                raise nsxv_exc.NsxPluginException(err_msg=error)

            self.callbacks.complete_edge_creation(
                context, edge_id, name, router_id, dist, True,
                availability_zone=availability_zone,
                deploy_metadata=deploy_metadata)

        except exceptions.VcnsApiException:
            self.callbacks.complete_edge_creation(
                context, edge_id, name, router_id, dist, False,
                availability_zone=availability_zone)
            with excutils.save_and_reraise_exception():
                LOG.exception("NSXv: deploy edge failed.")
        return edge_id