예제 #1
0
 def insert_router(self, auth_url, neutron, service_id, router_id):
     result_router = neutron.getRouter(router_id)
     if result_router.get("success"):
         router = result_router["success"].get("router")
         params = (auth_url, service_id, router.get("id"),
                   router.get("name"), 9 if router.get("status") else 12,
                   7 if router.get("admin_state_up") else 8)
         from sdsec.settings import logger
         logger.debug(INSERT_SOAM_ROUTER % params)
         return self.insert(INSERT_SOAM_ROUTER, params)
예제 #2
0
def sync(request, router_id):
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    neutron = NeutronRestAPI(auth_url, token)
    service_id = request.POST.get("service_id")
    from sdsecgui.db.soa_db_connector import SOAManagerDBConnector
    try:
        m_conn = SOAManagerDBConnector.getInstance()
        m_conn.insert_router(auth_url, neutron, service_id, router_id)
        result = True
    except Exception as e:
        from sdsec.settings import logger
        logger.debug(e.message)
        result = False
    return JsonResponse({"result": result})
예제 #3
0
def sync(request, volume_id):
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    service_id = request.POST.get("service_id")
    cinder = CinderRestAPI(auth_url, token)
    try:
        from sdsecgui.db.soa_db_connector import SOAManagerDBConnector
        m_conn = SOAManagerDBConnector.getInstance()
        m_conn.insert_volume(auth_url, cinder, service_id, volume_id)
        result = True
    except Exception as e:
        from sdsec.settings import logger
        logger.debug(e.message)
        result = False
    return JsonResponse({"result": result})
예제 #4
0
def sync(request, network_id):
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    neutron = NeutronRestAPI(auth_url, token)
    service_id = request.POST.get("service_id")
    from sdsecgui.db.soa_db_connector import SOAManagerDBConnector
    from sdsecgui.tools.ctrlengine import ControlEngine
    control = ControlEngine(request.session.get("ctrl_header"))
    try:
        m_conn = SOAManagerDBConnector.getInstance()
        m_conn.insert_network(auth_url, control, neutron, service_id,
                              network_id)
        result = True
    except Exception as e:
        from sdsec.settings import logger
        logger.debug(e.message)
        result = False
    return JsonResponse({"result": result})
예제 #5
0
 def insert_network(self, auth_url, control, neutron, service_id,
                    network_id):
     from sdsec.settings import logger
     result_network = control.get_resource("NETWORK", network_id)
     if result_network.get("success"):
         network = result_network["success"].get("network")
         params = (
             auth_url,
             service_id,
             network.get("id"),
             network.get("name"),
             9 if network.get("status") else 12,
             7 if network.get("admin_state_up") else 8,
             "Y" if network.get("router:external") else "N",
             "Y" if network.get("share") else "N",
             network.get("mtu")  #
         )
         self.insert(INSERT_SOAM_NETWORK, params)
         # subnet
         for subnet_id in network.get("subnets"):
             result_subnet = neutron.get_subnet(subnet_id)
             if result_subnet.get("success"):
                 subnet = result_subnet["success"].get("subnet")
                 params = (auth_url, subnet.get("network_id"), subnet_id,
                           subnet.get("name"), subnet.get("cidr"),
                           31 if subnet.get("ip_version") == 4 else 32,
                           subnet.get("gateway_ip"))
                 self.insert(INSERT_SOAM_SUBNET, params)
                 logger.debug(INSERT_SOAM_SUBNET % params)
         # port
         result_ports = neutron.get_port_list({"network_id": network_id})
         if result_ports.get("success"):
             ports = result_ports["success"].get("ports")
             for port_detail in ports:
                 params = (auth_url, port_detail.get("network_id"),
                           port_detail.get("device_id"),
                           port_detail.get("id"), port_detail.get("name"),
                           9 if port_detail.get("status") else 12,
                           7 if port_detail.get("admin_state_up") else 8)
                 self.insert(INSERT_SOAM_PORT, params)
                 logger.debug(INSERT_SOAM_PORT % params)
                 # fixed ip
                 fixed_ips = port_detail.get("fixed_ips")
                 for fixed_ip in fixed_ips:
                     params = (auth_url, fixed_ip.get("subnet_id"),
                               port_detail.get("id"),
                               fixed_ip.get("ip_address"))
                     self.insert(INSERT_SOAM_FIXED_IP, params)
                     logger.debug(INSERT_SOAM_FIXED_IP % params)