def __delete_host(self, tenant_id, network_id, host_ip): ret = {} try: hosts = mul.get_fabric_host_all(1) check = 0 for host in hosts: host_flow = host.host_flow if str(tenant_id) == str(mul.nbapi_uuid_to_str( host.tenant_id)) and str(network_id) == str( mul.nbapi_uuid_to_str(host.network_id) ) and str(host_ip) == str( mul.nbapi_fab_parse_nw_addr_to_str(host_flow)): host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) check = mul.delete_fabric_host(str(tenant_id), str(network_id), str(host_ip), str(host_mac)) if check == 1: ret.update({'delete host': 'success'}) break elif check == -1: raise Exception, 'Malformed tenant_id' elif check == -2: raise Exception, 'Malformed network_id' elif check == -3: raise Exception, 'Malformed host_ip(nw_src)' elif check == -4: raise Exception, 'Malformed host_mac(dl_src)' elif check == -5: raise Exception, 'failed to delete host' if check == 0: raise Exception, 'no such host' except Exception, e: ret.update({'fail': 'failed to delete host', 'reason': str(e)})
def __route_serialize(self, route): return { 'src_host': { 'tenant_id': mul.nbapi_uuid_to_str(route.src_host.tenant_id), 'network_id': mul.nbapi_uuid_to_str(route.src_host.network_id), 'dl_src': mul.nbapi_parse_mac_to_str(route.src_host.host_flow.dl_src), 'nw_src': mul.nbapi_fab_parse_nw_addr_to_str(route.src_host.host_flow), 'switch_dpid': '0x%lx' % route.src_host.switch_id.datapath_id, 'port': '%hu' % route.src_host.host_flow.in_port }, 'dst_host': { 'tenant_id': mul.nbapi_uuid_to_str(route.dst_host.tenant_id), 'network_id': mul.nbapi_uuid_to_str(route.dst_host.network_id), 'dl_src': mul.nbapi_parse_mac_to_str(route.dst_host.host_flow.dl_src), 'nw_src': mul.nbapi_fab_parse_nw_addr_to_str(route.dst_host.host_flow), 'switch_dpid': '0x%lx' % route.dst_host.switch_id.datapath_id, 'port': '%hu' % route.dst_host.host_flow.in_port }, 'route_link': eval(route.str_route) }
def __delete_host(self, tenant_id, network_id, host_ip): ret = {} try: hosts = mul.get_fabric_host_all(1) check = 0 for host in hosts: host_flow = host.host_flow if ( str(tenant_id) == str(mul.nbapi_uuid_to_str(host.tenant_id)) and str(network_id) == str(mul.nbapi_uuid_to_str(host.network_id)) and str(host_ip) == str(mul.nbapi_fab_parse_nw_addr_to_str(host_flow)) ): host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) check = mul.delete_fabric_host(str(tenant_id), str(network_id), str(host_ip), str(host_mac)) if check == 1: ret.update({"delete host": "success"}) break elif check == -1: raise Exception, "Malformed tenant_id" elif check == -2: raise Exception, "Malformed network_id" elif check == -3: raise Exception, "Malformed host_ip(nw_src)" elif check == -4: raise Exception, "Malformed host_mac(dl_src)" elif check == -5: raise Exception, "failed to delete host" if check == 0: raise Exception, "no such host" except Exception, e: ret.update({"fail": "failed to delete host", "reason": str(e)})
def get(self, tenant_id=None, network_id=None): logger.debug("request url - %s", self.get_request_uri()) logger.debug("request params - tenant_id: %s",tenant_id) ret = [] try: tenants = mul.get_fabric_tenant_net_all() for tenant in tenants: ret.append({'tenant_id' : mul.nbapi_uuid_to_str(tenant.tenant_id), 'network_id' : mul.nbapi_uuid_to_str(tenant.network_id)}) except SystemError: pass finally: self.finish({'tenant_and_networks' : ret})
def get(self, tenant_id=None, network_id=None): logger.debug("request url - %s", self.get_request_uri()) logger.debug("request params - tenant_id: %s",tenant_id) if tenant_id or network_id: self.raise404() ret = [] hosts = mul.get_fabric_port_tnid_all() for host in hosts: ret.append({ 'tenant_id' : mul.nbapi_uuid_to_str(host.tenant_id), 'network_id' : mul.nbapi_uuid_to_str(host.network_id), 'switch_dpid' : '0x%lx' % host.datapath_id, 'port' : '%hu' %host.port }) self.finish({"hosts" : ret })
def __delete_host(self, tenant_id, network_id, host_ip): try: hosts = mul.get_fabric_host_all(1, 0) ret = {} check = 0 for host in hosts: host_flow = host.host_flow if str(tenant_id) == str(mul.nbapi_uuid_to_str(host.tenant_id)) and str(network_id) == str(mul.nbapi_uuid_to_str(host.network_id)) and str(host_ip) == str(mul.nbapi_fab_parse_nw_addr_to_str(host_flow)): host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) check = mul.delete_fabric_host(str(tenant_id), str(network_id), str(host_ip), str(host_mac)) if check == 1: ret.update({'delete host' : 'success'}) break elif check == -1: raise Exception , 'Malformed tenant_id' elif check == -2: raise Exception , 'Malformed network_id' elif check == -3: raise Exception , 'Malformed host_ip(nw_src)' elif check == -4: raise Exception , 'Malformed host_mac(dl_src)' elif check == -5: raise Exception , 'failed to delete host' if check == 0: raise Exception , 'no such host' except Exception, e: ret.update({'fail' : 'failed to delete host', 'reason' : str(e)})
def get(self, tenant_id=None, network_id=None): logger.debug("request url - %s", self.get_request_uri()) logger.debug("request params - tenant_id: %s", tenant_id) ret = [] try: tenants = mul.get_fabric_tenant_net_all() for tenant in tenants: ret.append({ 'tenant_id': mul.nbapi_uuid_to_str(tenant.tenant_id), 'network_id': mul.nbapi_uuid_to_str(tenant.network_id) }) except SystemError: pass finally: self.finish({'tenant_and_networks': ret})
def get(self): #, tenant_id=None, network_id=None, host_id=None): logger.debug("request url - %s", self.get_request_uri()) hosts = mul.get_fabric_host_all(1) logger.debug(str(len(hosts))) ret = [] for host in hosts: host_flow = host.host_flow host_ip = mul.nbapi_fab_parse_nw_addr_to_str(host_flow) host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) res_d = { 'tenant_id': mul.nbapi_uuid_to_str(host.tenant_id), 'network_id': mul.nbapi_uuid_to_str(host.network_id), 'dl_src': host_mac, 'nw_src': host_ip, 'switch_dpid': '0x%lx' % host.switch_id.datapath_id, 'port': '%4hu' % host_flow.in_port } ret.append(res_d) self.finish({'hosts': ret})
def get(self): # , tenant_id=None, network_id=None, host_id=None): logger.debug("request url - %s", self.get_request_uri()) hosts = mul.get_fabric_host_all(1) logger.debug(str(len(hosts))) ret = [] for host in hosts: host_flow = host.host_flow host_ip = mul.nbapi_fab_parse_nw_addr_to_str(host_flow) host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) res_d = { "tenant_id": mul.nbapi_uuid_to_str(host.tenant_id), "network_id": mul.nbapi_uuid_to_str(host.network_id), "dl_src": host_mac, "nw_src": host_ip, "switch_dpid": "0x%lx" % host.switch_id.datapath_id, "port": "%4hu" % host_flow.in_port, } ret.append(res_d) self.finish({"hosts": ret})
def get(self):#, tenant_id=None, network_id=None, host_id=None): logger.debug("request url - %s", self.get_request_uri()) hosts = mul.get_fabric_host_all(1) logger.debug(str(len(hosts))) ret = [] for host in hosts: host_flow = host.host_flow host_ip = mul.nbapi_fab_parse_nw_addr_to_str(host_flow) host_mac = mul.nbapi_parse_mac_to_str(host_flow.dl_src) res_d = { 'tenant_id' : mul.nbapi_uuid_to_str(host.tenant_id), 'network_id' : mul.nbapi_uuid_to_str(host.network_id), 'dl_src' : host_mac, 'nw_src' : host_ip, 'switch_dpid' : '0x%lx' % host.switch_id.datapath_id, 'port' : '%4hu' %host_flow.in_port } ret.append(res_d) self.finish({'hosts' : ret })