def router_add_gateway_task(router=None): rc = create_rc_by_router(router) # find external network search_opts = {'router:external': True} networks = neutron.network_list(rc, **search_opts) ext_net = filter( lambda n: n.name.lower() == router.user_data_center.data_center. ext_net, networks) ext_net_id = None if ext_net and len(ext_net) > 0: ext_net_id = ext_net[0].id # set external gateway neutron.router_add_gateway(rc, router.router_id, ext_net_id) time.sleep(5) # update cloud db router gateway info os_router = neutron.router_get(rc, router.router_id) ext_fixed_ips = os_router["external_gateway_info"].get( "external_fixed_ips", []) router.gateway = ext_fixed_ips[0].get( "ip_address") if ext_fixed_ips else "---" router.status = NETWORK_STATE_ACTIVE router.is_gateway = True router.save() return True
def router_add_gateway_task(router=None): if not router: return rc = create_rc_by_router(router) LOG.info("Begin set gateway [Router:%s][%s]", router.id, router.name) # 1. find external network search_opts = {'router:external': True} networks = neutron.network_list(rc, **search_opts) ext_net_name = router.user_data_center.data_center.ext_net ext_net = filter(lambda n: n.name.lower() == ext_net_name, networks) ext_net_id = None if ext_net and len(ext_net) > 0: ext_net_id = ext_net[0].id if not ext_net_id: router.set_gateway_failed() LOG.error("No external network [%s] was found!", ext_net_name) return False # 2. set external gateway try: neutron.router_add_gateway(rc, router.router_id, ext_net_id) time.sleep(3) except Exception as ex: router.set_gateway_failed() LOG.exception(ex) return False # 3.update cloud db router gateway info try: os_router = neutron.router_get(rc, router.router_id) if os_router.external_gateway_info: LOG.info("Router [%s][%s] set gateway info [%s]", router.id, router.name, os_router.external_gateway_info) ext_fixed_ips = os_router.external_gateway_info.get( "external_fixed_ips", []) if ext_fixed_ips: router.gateway = ext_fixed_ips[0].get("ip_address", "N/A") router.is_gateway = True else: router.gateway = None router.is_gateway = False router.status = NETWORK_STATE_ACTIVE router.save() except Exception as ex: router.set_gateway_failed() LOG.exception(ex) LOG.info("End set gateway [Router:%s][%s]", router.id, router.name) return True
def router_add_gateway_task(router=None): if not router: return rc = create_rc_by_router(router) LOG.info("Begin set gateway [Router:%s][%s]", router.id, router.name) # 1. find external network search_opts = {'router:external': True} networks = neutron.network_list(rc, **search_opts) ext_net_name = router.user_data_center.data_center.ext_net ext_net = filter(lambda n: n.name.lower() == ext_net_name, networks) ext_net_id = None if ext_net and len(ext_net) > 0: ext_net_id = ext_net[0].id if not ext_net_id: router.set_gateway_failed() LOG.error("No external network [%s] was found!", ext_net_name) return False # 2. set external gateway try: neutron.router_add_gateway(rc, router.router_id, ext_net_id) time.sleep(3) except Exception as ex: router.set_gateway_failed() LOG.exception(ex) return False # 3.update cloud db router gateway info try: os_router = neutron.router_get(rc, router.router_id) if os_router.external_gateway_info: LOG.info("Router [%s][%s] set gateway info [%s]", router.id, router.name, os_router.external_gateway_info) ext_fixed_ips = os_router.external_gateway_info.get("external_fixed_ips", []) if ext_fixed_ips: router.gateway = ext_fixed_ips[0].get("ip_address", "N/A") router.is_gateway = True else: router.gateway = None router.is_gateway = False router.status = NETWORK_STATE_ACTIVE router.save() except Exception as ex: router.set_gateway_failed() LOG.exception(ex) LOG.info("End set gateway [Router:%s][%s]", router.id, router.name) return True
def router_add_gateway_task(router=None): rc = create_rc_by_router(router) # find external network search_opts = {'router:external': True} networks = neutron.network_list(rc, **search_opts) ext_net = filter(lambda n: n.name.lower() == router.user_data_center.data_center.ext_net, networks) ext_net_id = None if ext_net and len(ext_net) > 0: ext_net_id = ext_net[0].id # set external gateway neutron.router_add_gateway(rc, router.router_id, ext_net_id) time.sleep(5) # update cloud db router gateway info os_router = neutron.router_get(rc, router.router_id) ext_fixed_ips = os_router["external_gateway_info"].get("external_fixed_ips", []) router.gateway = ext_fixed_ips[0].get("ip_address") if ext_fixed_ips else "---" router.status = NETWORK_STATE_ACTIVE router.is_gateway = True router.save() return True
def allocate_floating_task(floating=None): rc = create_rc_by_floating(floating) LOG.info("Begin to allocate floating, [%s]" % floating.id); search_opts = {'router:external': True} networks = neutron.network_list(rc, **search_opts) ext_net = filter(lambda n: n.name.lower() == floating.user_data_center.data_center.ext_net, networks) ext_net_id = None if ext_net and len(ext_net) > 0: ext_net_id = ext_net[0].id if ext_net_id: try: fip = network.tenant_floating_ip_allocate(rc, pool=ext_net_id) floating.ip = fip.ip floating.status = FLOATING_AVAILABLE floating.uuid = fip.id floating.save(); LOG.info("End to allocate floating, [%s][%s]" % (floating.id, fip.ip)); except Exception as e: floating.status = FLOATING_ERROR floating.save(); LOG.exception(e); LOG.info("End to allocate floating, [%s][exception]" % floating.id); else: LOG.info("End to allocate floating, [%s][---]" % floating.id);