def nsx_update_metadata_proxy_server_ip(resource, event, trigger, **kwargs):
    """Update Metadata proxy server ip on the nsx."""
    nsxlib = utils.get_connected_nsxlib()
    nsx_version = nsxlib.get_version()
    if not nsx_utils.is_nsx_version_1_1_0(nsx_version):
        LOG.error("This utility is not available for NSX version %s",
                  nsx_version)
        return

    server_ip = None
    az_name = nsx_az.DEFAULT_NAME
    if kwargs.get('property'):
        properties = admin_utils.parse_multi_keyval_opt(kwargs['property'])
        server_ip = properties.get('server-ip')
        az_name = properties.get('availability-zone', az_name)
    if not server_ip or not netaddr.valid_ipv4(server_ip):
        LOG.error("Need to specify a valid server-ip parameter")
        return

    config.register_nsxv3_azs(cfg.CONF, cfg.CONF.nsx_v3.availability_zones)
    if (az_name != nsx_az.DEFAULT_NAME
            and az_name not in cfg.CONF.nsx_v3.availability_zones):
        LOG.error("Availability zone %s was not found in the configuration",
                  az_name)
        return

    az = nsx_az.NsxV3AvailabilityZones().get_availability_zone(az_name)
    az.translate_configured_names_to_uuids(nsxlib)

    if (not az.metadata_proxy or not cfg.CONF.nsx_v3.native_dhcp_metadata):
        LOG.error(
            "Native DHCP metadata is not enabled in the configuration "
            "of availability zone %s", az_name)
        return
    metadata_proxy_uuid = az._native_md_proxy_uuid

    try:
        mdproxy = nsxlib.native_md_proxy.get(metadata_proxy_uuid)
    except nsx_exc.ResourceNotFound:
        LOG.error("metadata proxy %s not found", metadata_proxy_uuid)
        return

    # update the IP in the URL
    url = mdproxy.get('metadata_server_url')
    url = re.sub(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', server_ip, url)
    LOG.info(
        "Updating the URL of the metadata proxy server %(uuid)s to "
        "%(url)s", {
            'uuid': metadata_proxy_uuid,
            'url': url
        })
    nsxlib.native_md_proxy.update(metadata_proxy_uuid, server_url=url)
    LOG.info("Done.")
Beispiel #2
0
 def initialize(self):
     self._availability_zones = nsx_az.NsxV3AvailabilityZones()
     LOG.info("DNSExtensionDriverNSXv3 initialization complete")
Beispiel #3
0
 def initialize(self):
     self._availability_zones = nsx_az.NsxV3AvailabilityZones()
     LOG.info("DNSExtensionDriverNSXv3 initialization complete")
     self.config_dns_domain = cfg.CONF.nsx_v3.dns_domain