Beispiel #1
0
def change_edge_hostgroup(properties):
    cluster_mng = dvs.ClusterManager()
    if properties.get('hostgroup').lower() == "update":
        edge_id = properties.get('edge-id')
        try:
            edge_result = nsxv.get_edge(edge_id)
        except exceptions.NeutronException as x:
            LOG.error("%s", str(x))
        else:
            # edge_result[0] is response status code
            # edge_result[1] is response body
            edge = edge_result[1]
            _update_host_group_for_edge(nsxv, cluster_mng, edge_id, edge)
    elif properties.get('hostgroup').lower() == "all":
        edges = utils.get_nsxv_backend_edges()
        for edge in edges:
            edge_id = edge['id']
            _update_host_group_for_edge(nsxv, cluster_mng, edge_id, edge)
    elif properties.get('hostgroup').lower() == "clean":
        config.register_nsxv_azs(cfg.CONF, cfg.CONF.nsxv.availability_zones)
        azs = nsx_az.NsxVAvailabilityZones()
        for az in azs.list_availability_zones_objects():
            try:
                edge_utils.clean_host_groups(cluster_mng, az)
            except Exception:
                LOG.error("Failed to clean AZ %s", az.name)
    else:
        LOG.error('Currently not supported')
Beispiel #2
0
def nsx_redo_metadata_cfg_for_edge(context, plugin, edge_id):
    binding = nsxv_db.get_nsxv_router_binding_by_edge(context.session, edge_id)
    if binding:
        az_name = binding['availability_zone']

        conf_az = nsx_az.NsxVAvailabilityZones()
        az = conf_az.availability_zones[az_name]
        if not az.supports_metadata():
            LOG.error('Edge %(edge)s belongs to az %(az)s which does not '
                      'support metadata',
                      {'az': az_name, 'edge': edge_id})

        edge_internal_ips, md_rtr_ids = _get_internal_edge_ips(context,
                                                               az_name)

        if binding['router_id'] in md_rtr_ids:
            LOG.error('Edge %s is a metadata proxy', edge_id)
            return

        if (binding['router_id'].startswith(
                vcns_constants.BACKUP_ROUTER_PREFIX) or
                binding['router_id'].startswith(
                    vcns_constants.PLR_EDGE_PREFIX)or
                binding['router_id'].startswith(
                    lb_common.RESOURCE_ID_PFX)):
            LOG.error('Edge %s is not a metadata delivery appliance', edge_id)
            return

        _handle_edge(context, plugin, az_name, edge_id, edge_internal_ips)
    else:
        LOG.error('No edge binding found for edge %s', edge_id)
Beispiel #3
0
def change_edge_appliance(edge_id):
    """Update the appliances data of an edge

    Update the edge appliances data according to its current availability zone
    and the nsx.ini config, including the resource pool, edge_ha, datastore &
    ha_datastore.
    The availability zone of the edge will not be changed.
    This can be useful when the global resource pool/datastore/edge ha
    configuration is updated, or when the configuration of a specific
    availability zone was updated.
    """
    # find out what is the current resource pool & size, so we can keep them
    az_name, size = _get_edge_az_and_size(edge_id)
    config.register_nsxv_azs(cfg.CONF, cfg.CONF.nsxv.availability_zones)
    az = nsx_az.NsxVAvailabilityZones().get_availability_zone(az_name)
    appliances = [{
        'resourcePoolId': az.resource_pool,
        'datastoreId': az.datastore_id
    }]

    if az.ha_datastore_id and az.edge_ha:
        appliances.append({
            'resourcePoolId': az.resource_pool,
            'datastoreId': az.ha_datastore_id
        })
    request = {'appliances': appliances, 'applianceSize': size}
    try:
        nsxv.change_edge_appliance(edge_id, request)
    except nsxv_exceptions.ResourceNotFound as e:
        LOG.error("Edge %s not found", edge_id)
    except exceptions.NeutronException as e:
        LOG.error("%s", str(e))
    else:
        # also update the edge_ha of the edge
        change_edge_ha(az.edge_ha, edge_id)
Beispiel #4
0
def _update_host_group_for_edge(nsxv, cluster_mng, edge_id, edge):
    if edge.get('type') == 'gatewayServices':
        try:
            az_name, size = _get_edge_az_and_size(edge_id)
            config.register_nsxv_azs(cfg.CONF,
                                     cfg.CONF.nsxv.availability_zones)
            zones = nsx_az.NsxVAvailabilityZones()
            az = zones.get_availability_zone(az_name)
            if az.edge_ha and az.edge_host_groups:
                edge_utils.update_edge_host_groups(nsxv,
                                                   edge_id,
                                                   cluster_mng,
                                                   az,
                                                   validate=True)
            else:
                LOG.error(
                    "Availability zone:%s does not have HA enabled or "
                    "no host groups defined. Skipping %s.", az_name, edge_id)
        except Exception as e:
            LOG.error("Failed to update edge %(id)s - %(e)s", {
                'id': edge['id'],
                'e': e
            })
    else:
        LOG.error("%s is not a gateway services", edge_id)
Beispiel #5
0
def nsx_redo_metadata_cfg(resource, event, trigger, **kwargs):
    edgeapi = utils.NeutronDbClient()

    config.register_nsxv_azs(cfg.CONF, cfg.CONF.nsxv.availability_zones)
    conf_az = nsx_az.NsxVAvailabilityZones()
    az_list = conf_az.list_availability_zones_objects()
    for az in az_list:
        if az.supports_metadata():
            nsx_redo_metadata_cfg_for_az(az, edgeapi)
        else:
            LOG.info("Skipping availability zone: %s - no metadata "
                     "configuration", az.name)
Beispiel #6
0
 def setUp(self):
     super(EdgeUtilsTestCaseMixin, self).setUp()
     nsxv_manager_p = mock.patch(vmware.VCNS_DRIVER_NAME, autospec=True)
     self.nsxv_manager = nsxv_manager_p.start()
     task = mock.Mock()
     nsxv_manager_p.return_value = task
     self.nsxv_manager.callbacks = mock.Mock()
     self.nsxv_manager.vcns = mock.Mock()
     get_ver = mock.patch.object(self.nsxv_manager.vcns,
                                 'get_version').start()
     get_ver.return_value = '6.1.4'
     self.ctx = context.get_admin_context()
     self.addCleanup(nsxv_manager_p.stop)
     self.az = (
         nsx_az.NsxVAvailabilityZones().get_default_availability_zone())
Beispiel #7
0
def nsx_redo_metadata_cfg_all(context, plugin):
    user_confirm = admin_utils.query_yes_no("Do you want to setup metadata "
                                            "infrastructure for all the edges",
                                            default="no")
    if not user_confirm:
        LOG.info("NSXv vnics deletion aborted by user")
        return

    config.register_nsxv_azs(cfg.CONF, cfg.CONF.nsxv.availability_zones)
    conf_az = nsx_az.NsxVAvailabilityZones()
    az_list = conf_az.list_availability_zones_objects()
    for az in az_list:
        if az.supports_metadata():
            nsx_redo_metadata_cfg_for_az(context, plugin, az.name, False)
        else:
            LOG.info("Skipping availability zone: %s - no metadata "
                     "configuration", az.name)
Beispiel #8
0
def _update_host_group_for_edge(nsxv, cluster_mng, edge_id, edge):
    if edge.get('type') == 'gatewayServices':
        try:
            az_name, size = _get_edge_az_and_size(edge_id)
            zones = nsx_az.NsxVAvailabilityZones()
            az = zones.get_availability_zone(az_name)
            edge_utils.update_edge_host_groups(nsxv,
                                               edge_id,
                                               cluster_mng,
                                               az,
                                               validate=True)
        except Exception as e:
            LOG.error("Failed to update edge %(id)s - %(e)s", {
                'id': edge['id'],
                'e': e
            })
    else:
        LOG.error("%s is not a gateway services", edge_id)
Beispiel #9
0
    def setUp(self):
        super(VcnsDriverTestCase, self).setUp()

        self.ctx = neutron_context.get_admin_context()
        self.temp_e_drv_nsxv_db = e_drv.nsxv_db
        e_drv.nsxv_db = mock.MagicMock()
        self.config_parse(args=['--config-file', VCNS_CONFIG_FILE])

        self.fc = fake_vcns.FakeVcns()
        self.mock_vcns = mock.patch(vmware.VCNS_NAME, autospec=True)
        self.vcns_patch()

        self.addCleanup(self.fc.reset_all)

        self.vcns_driver = vcns_driver.VcnsDriver(self)

        self.az = (nsx_az.NsxVAvailabilityZones().
                   get_default_availability_zone())
        self.edge_id = None
        self.result = None
Beispiel #10
0
 def _create_l2_gateway_edge(self, context):
     # Create a dedicated DLR
     lrouter = {
         'name': nsxv_constants.L2_GATEWAY_EDGE,
         'id': uuidutils.generate_uuid()
     }
     # Create the router on the default availability zone
     availability_zone = (
         nsx_az.NsxVAvailabilityZones().get_default_availability_zone())
     self._edge_manager.create_lrouter(context,
                                       lrouter,
                                       lswitch=None,
                                       dist=True,
                                       availability_zone=availability_zone)
     edge_binding = nsxv_db.get_nsxv_router_binding(context.session,
                                                    lrouter['id'])
     if not edge_binding:
         raise nsx_exc.NsxL2GWDeviceNotFound()
     # Enable edge HA on the DLR
     if availability_zone.edge_ha:
         edge_id = edge_binding['edge_id']
         self._edge_manager.nsxv_manager.update_edge_ha(edge_id)
     return edge_binding['edge_id']
Beispiel #11
0
def nsx_redo_metadata_cfg_for_az(context, plugin, az_name, check_az=True):
    LOG.info("Updating MetaData for availability zone: %s", az_name)

    if check_az:
        conf_az = nsx_az.NsxVAvailabilityZones()
        az = conf_az.availability_zones.get(az_name)
        if not az:
            LOG.error('Availability zone %s not found', az_name)
            return
        if not az.supports_metadata():
            LOG.error('Availability zone %s is not configured with metadata',
                      az_name)
            return

    edge_internal_ips, md_rtr_ids = _get_internal_edge_ips(context,
                                                           az_name)
    if not edge_internal_ips and not md_rtr_ids:
        LOG.error("Metadata infrastructure is missing or broken. "
                  "It is recommended to restart neutron service before "
                  "proceeding with configuration restoration")
        return

    router_bindings = nsxv_db.get_nsxv_router_bindings(
        context.session,
        filters={'edge_type': [nsxv_constants.SERVICE_EDGE],
                 'availability_zone': [az_name]})
    edge_ids = list(set([binding['edge_id'] for binding in router_bindings
                         if (binding['router_id'] not in set(md_rtr_ids) and
                             not binding['router_id'].startswith(
                                 vcns_constants.BACKUP_ROUTER_PREFIX) and
                             not binding['router_id'].startswith(
                                    vcns_constants.PLR_EDGE_PREFIX)and
                             not binding['router_id'].startswith(
                                    lb_common.RESOURCE_ID_PFX))]))

    for edge_id in edge_ids:
        _handle_edge(context, plugin, az_name, edge_id, edge_internal_ips)
 def __init__(self, plugin):
     self.plugin = plugin
     self.nsx_v = plugin.nsx_v
     self.edge_manager = plugin.edge_manager
     self.vcns = self.nsx_v.vcns
     self._availability_zones = nsx_az.NsxVAvailabilityZones()
Beispiel #13
0
def create_bgp_gw(resource, event, trigger, **kwargs):
    """Creates a new BGP GW edge"""
    usage = ("nsxadmin -r bgp-gw-edge -o create "
             "--property name=<GW_EDGE_NAME> "
             "--property local-as=<LOCAL_AS_NUMBER> "
             "--property external-iface=<PORTGROUP>:<IP_ADDRESS/PREFIX_LEN> "
             "--property internal-iface=<PORTGROUP>:<IP_ADDRESS/PREFIX_LEN> "
             "[--property default-gateway=<IP_ADDRESS>] "
             "[--property az-hint=<AZ_HINT>] "
             "[--property size=compact,large,xlarge,quadlarge]")
    required_params = ('name', 'local-as', 'internal-iface', 'external-iface')
    properties = admin_utils.parse_multi_keyval_opt(kwargs.get('property', []))
    if not properties or not set(required_params) <= set(properties.keys()):
        LOG.error(usage)
        return

    local_as = properties['local-as']
    if not _validate_asn(local_as):
        return

    size = properties.get('size', nsxv_constants.LARGE)
    if size not in vcns_const.ALLOWED_EDGE_SIZES:
        msg = ("Property 'size' takes one of the following values: %s." %
               ','.join(vcns_const.ALLOWED_EDGE_SIZES))
        LOG.error(msg)
        return

    external_iface_info = _extract_interface_info(properties['external-iface'])
    internal_iface_info = _extract_interface_info(properties['internal-iface'])
    if not (external_iface_info and internal_iface_info):
        return

    if 'default-gateway' in properties:
        default_gw = _extract_interface_info(properties['default-gateway'])
        if not default_gw:
            msg = ("Property 'default-gateway' doesn't contain a valid IP "
                   "address.")
            LOG.error(msg)
            return
        default_gw = default_gw[1]
    else:
        default_gw = None

    config.register_nsxv_azs(cfg.CONF, cfg.CONF.nsxv.availability_zones)
    az_hint = properties.get('az-hint', 'default')
    az = nsx_az.NsxVAvailabilityZones().get_availability_zone(az_hint)

    edge_id, gateway_ip = _assemble_gw_edge(properties['name'], size,
                                            external_iface_info,
                                            internal_iface_info, default_gw,
                                            az)
    nsxv.add_bgp_speaker_config(edge_id,
                                gateway_ip,
                                local_as,
                                True, [], [], [],
                                default_originate=True)

    res = {
        'name': properties['name'],
        'edge_id': edge_id,
        'size': size,
        'availability_zone': az.name,
        'bgp_identifier': gateway_ip,
        'local_as': local_as
    }
    headers = [
        'name', 'edge_id', 'size', 'bgp_identifier', 'availability_zone',
        'local_as'
    ]
    LOG.info(formatters.output_formatter('BGP GW Edge', [res], headers))
Beispiel #14
0
 def __init__(self, global_readonly, readonly_jobs):
     super(ErrorBackupEdgeJob, self).__init__(global_readonly,
                                              readonly_jobs)
     self.azs = nsx_az.NsxVAvailabilityZones()
Beispiel #15
0
 def __init__(self, readonly):
     super(ErrorBackupEdgeJob, self).__init__(readonly)
     self.azs = nsx_az.NsxVAvailabilityZones()
Beispiel #16
0
 def get_network_az_by_net_id(self, context, network_id):
     return (nsx_az.NsxVAvailabilityZones().get_default_availability_zone())