Exemple #1
0
    def __add_host(self, tenant_id, network_id):
        ret = {}
        try:
            #tenants = mul.get_fabric_tenant_net_all()
        #    check = -1
        #    for tenant in tenants:
#                if str(mul.nbapi_uuid_to_str(tenant.tenant_id)) == str(tenant_id) and \
#                   str(mul.nbapi_uuid_to_str(tenant.network_id)) == str(network_id):
#                    check = 0
#            if check == -1:
#                raise Exception, 'no such tenant and network id'
            body = HostSchema().deserialize(json.loads(self.request.body))
            logger.debug(str(body))
            check = mul.add_fabric_host(int(str(body['dpid']), 16),
                                        str(tenant_id),
                                        str(network_id),
                                        str(body['nw_src']),
                                        str(body['dl_src']),
                                        str(body['in_port']),
                                        str(body['is_gw']))
            if check == 1:
                ret.update({'add host' : 'success' , 'host_id' : 'later..'})
            elif check == -2:
                raise Exception, 'Malformed tenant id'
            elif check == -3:
                raise Exception, 'Malformed network id'
            elif check == -4:
                raise Exception, 'Malformed nw_src'
            elif check == -5:
                raise Exception, 'Malformed dl_src'
            else:
                raise Exception, 'failed to add host'
        except Exception, e:
            ret.update({'error_message' : 'failed to add host', 'reason' : str(e)})
Exemple #2
0
 def __add_fabric_host(self, tenant_id, network_id, body):
     logger.debug(str(body))
     check = mul.add_fabric_host(int(str(body['dpid']), 16),
                                 str(tenant_id),
                                 str(network_id),
                                 str(body['nw_src']),
                                 str(body['dl_src']),
                                 str(body['in_port']),
                                 str(body['is_gw']))
     if check == 1:
         return True
     elif check == -2:
         raise Exception, 'Malformed tenant id'
     elif check == -3:
         raise Exception, 'Malformed network id'
     elif check == -4:
         raise Exception, 'Malformed nw_src'
     elif check == -5:
         raise Exception, 'Malformed dl_src'
     else:
         raise Exception, 'failed to add fabric host'
Exemple #3
0
 def __add_host(self, tenant_id, network_id):
     ret = {}
     try:
         #tenants = mul.get_fabric_tenant_net_all()
         #    check = -1
         #    for tenant in tenants:
         #                if str(mul.nbapi_uuid_to_str(tenant.tenant_id)) == str(tenant_id) and \
         #                   str(mul.nbapi_uuid_to_str(tenant.network_id)) == str(network_id):
         #                    check = 0
         #            if check == -1:
         #                raise Exception, 'no such tenant and network id'
         body = HostSchema().deserialize(json.loads(self.request.body))
         logger.debug(str(body))
         check = mul.add_fabric_host(int(str(body['dpid']), 16),
                                     str(tenant_id), str(network_id),
                                     str(body['nw_src']),
                                     str(body['dl_src']),
                                     str(body['in_port']),
                                     str(body['is_gw']))
         if check == 1:
             ret.update({'add host': 'success', 'host_id': 'later..'})
         elif check == -2:
             raise Exception, 'Malformed tenant id'
         elif check == -3:
             raise Exception, 'Malformed network id'
         elif check == -4:
             raise Exception, 'Malformed nw_src'
         elif check == -5:
             raise Exception, 'Malformed dl_src'
         else:
             raise Exception, 'failed to add host'
     except Exception, e:
         ret.update({
             'error_message': 'failed to add host',
             'reason': str(e)
         })
Exemple #4
0
 def __add_host(self, tenant_id, network_id):
     ret = {}
     try:
         # tenants = mul.get_fabric_tenant_net_all()
         #    check = -1
         #    for tenant in tenants:
         #                if str(mul.nbapi_uuid_to_str(tenant.tenant_id)) == str(tenant_id) and \
         #                   str(mul.nbapi_uuid_to_str(tenant.network_id)) == str(network_id):
         #                    check = 0
         #            if check == -1:
         #                raise Exception, 'no such tenant and network id'
         body = HostSchema().deserialize(json.loads(self.request.body))
         logger.debug(str(body))
         check = mul.add_fabric_host(
             int(str(body["dpid"]), 16),
             str(tenant_id),
             str(network_id),
             str(body["nw_src"]),
             str(body["dl_src"]),
             str(body["in_port"]),
             str(body["is_gw"]),
         )
         if check == 1:
             ret.update({"add host": "success", "host_id": "later.."})
         elif check == -2:
             raise Exception, "Malformed tenant id"
         elif check == -3:
             raise Exception, "Malformed network id"
         elif check == -4:
             raise Exception, "Malformed nw_src"
         elif check == -5:
             raise Exception, "Malformed dl_src"
         else:
             raise Exception, "failed to add host"
     except Exception, e:
         ret.update({"error_message": "failed to add host", "reason": str(e)})