def neutron_add_subnet(nc, vsd_subnet, tenant): neutron_creds = get_neutron_creds(cfg.get('openstack', 'admin_username'), cfg.get('openstack', 'admin_password'), tenant.name) neutron = neutronclient.Client(**neutron_creds) # Ignore Shared L3 if not linked to shared subnet if not vsd_subnet['parentType'] == "enterprise" and vsd_subnet['address'] is None and vsd_subnet[ 'associatedSharedNetworkResourceID'] is None: if cfg.getboolean('sync', 'sync_shared_subnets'): logger.info( "|- Ignoring subnet: (ID:{0}). This is a public subnet without a pool assignment yet.".format( vsd_subnet['ID'])) else: logger.info( "|- Ignoring subnet: (ID:{0}). Sync of shared subnets is disabled in configuration.".format( vsd_subnet['ID'])) return None # Ignore if Shared L2/L3 subnet and syncing of shared subnets is disabled in the configuration if vsd_subnet['associatedSharedNetworkResourceID'] is not None and not cfg.getboolean('sync', 'sync_shared_subnets'): logger.info( "|- Ignoring subnet: (ID:{0}). Sync of shared subnets is disabled in configuration.".format( vsd_subnet['ID'])) return None # Check if network exists if vsd_subnet['parentType'] == "enterprise": net_name = calcL2SubnetName(nc, vsd_subnet) else: net_name = calcL3SubnetName(nc, vsd_subnet) try: logger.debug("Checking if openstack network {0} already exists".format(net_name)) netw = neutron.list_networks(name=net_name)['networks'] except Exception, e: logger.error("|- ERROR checking if openstack network {0} exists".format(net_name)) logger.error(repr(e))
def vsd_subnet_exists(os_nw,mapping): nc = NuageConnection(cfg.get('vsd','hostname'), enterprise=cfg.get('vsd','enterprise'), username=cfg.get('vsd','username'), password=cfg.get('vsd','password'), version=cfg.get('vsd','version'), port=cfg.get('vsd','port')) logger.debug("Checking if Openstack network(%s,%s) exists in the VSD" % (os_nw['id'],os_nw['name'])) try: vsd_subnet = nc.get("subnets/%s" % mapping["nuage_subnet_id"]).obj()[0] except Exception, e: try: vsd_subnet = nc.get("l2domains/%s" % mapping["nuage_subnet_id"]).obj()[0] except Exception, e: logger.info("|- Subnet (%s - ID:%s) not found in VSD --> Removing" % (os_nw['name'], os_nw['id']) ) vsd_subnet = []
def neutron_add_subnet(nc,vsd_subnet,tenant): neutron_creds = get_neutron_creds(cfg.get('openstack','admin_username'), cfg.get('openstack','admin_password'), tenant.name) neutron = neutronclient.Client(**neutron_creds) if not vsd_subnet['parentType'] == "enterprise" and vsd_subnet['address'] == None and vsd_subnet['associatedSharedNetworkResourceID'] == None: logger.debug("|- Ignoring subnet: (ID:%s). This is a public subnet without a pool assignment yet." % vsd_subnet['ID'] ) return None if vsd_subnet['parentType'] == "enterprise": net_name = calcL2SubnetName(nc,vsd_subnet) else: net_name = calcL3SubnetName(nc,vsd_subnet) try: logger.debug("Checking if openstack network %s already exists" % net_name) network = neutron.list_networks(name=net_name)['networks'] except Exception, e: logger.error("|- ERROR checking if openstack network %s exists" % net_name) logger.error(repr(e))
def neutron_add_subnet(nc, vsd_subnet, tenant): neutron_creds = get_neutron_creds(cfg.get('openstack', 'admin_username'), cfg.get('openstack', 'admin_password'), tenant.name) neutron = neutronclient.Client(**neutron_creds) # Ignore Shared L3 if not linked to shared subnet if not vsd_subnet['parentType'] == "enterprise" and vsd_subnet[ 'address'] is None and vsd_subnet[ 'associatedSharedNetworkResourceID'] is None: if cfg.getboolean('sync', 'sync_shared_subnets'): logger.info( "|- Ignoring subnet: (ID:{0}). This is a public subnet without a pool assignment yet." .format(vsd_subnet['ID'])) else: logger.info( "|- Ignoring subnet: (ID:{0}). Sync of shared subnets is disabled in configuration." .format(vsd_subnet['ID'])) return None # Ignore if Shared L2/L3 subnet and syncing of shared subnets is disabled in the configuration if vsd_subnet[ 'associatedSharedNetworkResourceID'] is not None and not cfg.getboolean( 'sync', 'sync_shared_subnets'): logger.info( "|- Ignoring subnet: (ID:{0}). Sync of shared subnets is disabled in configuration." .format(vsd_subnet['ID'])) return None # Check if network exists if vsd_subnet['parentType'] == "enterprise": net_name = calcL2SubnetName(nc, vsd_subnet) else: net_name = calcL3SubnetName(nc, vsd_subnet) try: logger.debug("Checking if openstack network {0} already exists".format( net_name)) netw = neutron.list_networks(name=net_name)['networks'] except Exception, e: logger.error( "|- ERROR checking if openstack network {0} exists".format( net_name)) logger.error(repr(e))
def vsd_subnet_exists(os_nw, mapping): nc = NuageConnection(cfg.get('vsd', 'hostname'), enterprise=cfg.get('vsd', 'enterprise'), username=cfg.get('vsd', 'username'), password=cfg.get('vsd', 'password'), version=cfg.get('vsd', 'version'), port=cfg.get('vsd', 'port')) logger.debug("Checking if Openstack network(%s,%s) exists in the VSD" % (os_nw['id'], os_nw['name'])) try: vsd_subnet = nc.get("subnets/%s" % mapping["nuage_subnet_id"]).obj()[0] except Exception, e: try: vsd_subnet = nc.get("l2domains/%s" % mapping["nuage_subnet_id"]).obj()[0] except Exception, e: logger.info( "|- Subnet (%s - ID:%s) not found in VSD --> Removing" % (os_nw['name'], os_nw['id'])) vsd_subnet = []
def neutron_add_subnet(nc, vsd_subnet, tenant): neutron_creds = get_neutron_creds(cfg.get('openstack', 'admin_username'), cfg.get('openstack', 'admin_password'), tenant.name) neutron = neutronclient.Client(**neutron_creds) if not vsd_subnet['parentType'] == "enterprise" and vsd_subnet[ 'address'] == None and vsd_subnet[ 'associatedSharedNetworkResourceID'] == None: logger.debug( "|- Ignoring subnet: (ID:%s). This is a public subnet without a pool assignment yet." % vsd_subnet['ID']) return None if vsd_subnet['parentType'] == "enterprise": net_name = calcL2SubnetName(nc, vsd_subnet) else: net_name = calcL3SubnetName(nc, vsd_subnet) try: logger.debug("Checking if openstack network %s already exists" % net_name) network = neutron.list_networks(name=net_name)['networks'] except Exception, e: logger.error("|- ERROR checking if openstack network %s exists" % net_name) logger.error(repr(e))
logger.error(repr(e)) return #First clean up existing Networks without attached subnets try: logger.info("Cleaning up Networks without subnets attached") cleanup_os_networks() except Exception, e: logger.error( "|- ERROR cleaning up Networks without subnets attached") logger.error(repr(e)) #First: Check if existing subnets are still in the VSD and remove them in OpenStack if not present in the VSD for mapping in subnet_mappings: if is_excluded_netpartition_id(mapping['net_partition_id']): logger.debug( "|- Ignoring subnet: (ID:%s) because it is in the default net partition or is in the list of excluded tenants" % mapping['subnet_id']) continue try: os_subnet = neutron.list_subnets( id=mapping['subnet_id'])['subnets'][0] except Exception, e: logger.error( "|- Error: Subnet %s found in subnet mapping but not in OpenStack." % mapping['subnet_id']) try: logger.debug("Checking if subnet %s exists" % mapping['subnet_id']) vsd_subnet = vsd_subnet_exists(os_subnet, mapping) except Exception, e: logger.error("|- ERROR checking if subnet %s exists" %
except Exception, e: logger.error("|- ERROR getting current subnet mappings from OpenStack MYSQL database") logger.error(repr(e)) return #First clean up existing Networks without attached subnets try: logger.info("Cleaning up Networks without subnets attached") cleanup_os_networks() except Exception, e: logger.error("|- ERROR cleaning up Networks without subnets attached") logger.error(repr(e)) #First: Check if existing subnets are still in the VSD and remove them in OpenStack if not present in the VSD for mapping in subnet_mappings: if is_excluded_netpartition_id(mapping['net_partition_id']): logger.debug("|- Ignoring subnet: (ID:%s) because it is in the default net partition or is in the list of excluded tenants" % mapping['subnet_id']) continue try: os_subnet = neutron.list_subnets(id=mapping['subnet_id'])['subnets'][0] except Exception, e: logger.error("|- Error: Subnet %s found in subnet mapping but not in OpenStack." % mapping['subnet_id'] ) try: logger.debug("Checking if subnet %s exists" % mapping['subnet_id']) vsd_subnet = vsd_subnet_exists(os_subnet,mapping) except Exception, e: logger.error("|- ERROR checking if subnet %s exists" % mapping['subnet_id']) logger.error(repr(e)) delete = True if vsd_subnet: if vsd_subnet['ID'] == mapping["nuage_subnet_id"] and check_adress_match(os_subnet,vsd_subnet) and check_name_match(nc,os_subnet,vsd_subnet): delete = False
logger.error(repr(e)) return # First clean up existing Networks without attached subnets try: logger.info("Cleaning up Networks without subnets attached") cleanup_os_networks() except Exception, e: logger.error( "|- ERROR cleaning up Networks without subnets attached") logger.error(repr(e)) # First: Check if existing subnets are still in the VSD and remove them in OpenStack if not present in the VSD for mapping in subnet_mappings: if is_excluded_netpartition_id(mapping['net_partition_id']): logger.debug( "|- Ignoring subnet: (ID:{0}) because it is in the default net partition or is in the list of excluded tenants" .format(mapping['subnet_id'])) continue try: os_subnet = neutron.list_subnets( id=mapping['subnet_id'])['subnets'][0] except Exception, e: logger.error( "|- Error: Subnet {0} found in subnet mapping but not in OpenStack." .format(mapping['subnet_id'])) logger.error(repr(e)) try: logger.debug("Checking if subnet {0} exists".format( mapping['subnet_id'])) vsd_subnet = vsd_subnet_exists(os_subnet, mapping) except Exception, e:
logger.error("|- ERROR getting current subnet mappings from OpenStack MYSQL database") logger.error(repr(e)) return # First clean up existing Networks without attached subnets try: logger.info("Cleaning up Networks without subnets attached") cleanup_os_networks() except Exception, e: logger.error("|- ERROR cleaning up Networks without subnets attached") logger.error(repr(e)) # First: Check if existing subnets are still in the VSD and remove them in OpenStack if not present in the VSD for mapping in subnet_mappings: if is_excluded_netpartition_id(mapping['net_partition_id']): logger.debug( "|- Ignoring subnet: (ID:{0}) because it is in the default net partition or is in the list of excluded tenants".format( mapping['subnet_id'])) continue try: os_subnet = neutron.list_subnets(id=mapping['subnet_id'])['subnets'][0] except Exception, e: logger.error("|- Error: Subnet {0} found in subnet mapping but not in OpenStack.".format( mapping['subnet_id'])) logger.error(repr(e)) try: logger.debug("Checking if subnet {0} exists".format(mapping['subnet_id'])) vsd_subnet = vsd_subnet_exists(os_subnet, mapping) except Exception, e: logger.error("|- ERROR checking if subnet {0} exists".format(mapping['subnet_id'])) logger.error(repr(e)) delete = True