Example #1
0
def _find_network(cc, network):
    if network.isdigit() and not utils.is_uuid_like(network):
        network_list = cc.network.list()
        for n in network_list:
            if str(n.id) == network:
                return n
        else:
            raise exc.CommandError('network not found: %s' % network)
    elif utils.is_uuid_like(network):
        try:
            h = cc.network.get(network)
        except exc.HTTPNotFound:
            raise exc.CommandError('network not found: %s' % network)
        else:
            return h
    else:
        network_list = cc.network.list()
        for n in network_list:
            if n.name == network:
                return n
        else:
            raise exc.CommandError('network not found: %s' % network)
Example #2
0
def _find_device_image(cc, device_image):
    if device_image.isdigit() and not utils.is_uuid_like(device_image):
        device_image_list = cc.device_image.list()
        for n in device_image_list:
            if str(n.id) == device_image:
                return n
        else:
            raise exc.CommandError('device image not found: %s' % device_image)
    elif utils.is_uuid_like(device_image):
        try:
            h = cc.device_image.get(device_image)
        except exc.HTTPNotFound:
            raise exc.CommandError('device image not found: %s' % device_image)
        else:
            return h
    else:
        device_image_list = cc.device_image.list()
        for n in device_image_list:
            if n.name == device_image:
                return n
        else:
            raise exc.CommandError('device image not found: %s' % device_image)
def _find_datanetwork(cc, datanetwork):
    if datanetwork.isdigit() and not utils.is_uuid_like(datanetwork):
        datanetwork_list = cc.datanetwork.list()
        for n in datanetwork_list:
            if str(n.id) == datanetwork:
                return n
        else:
            raise exc.CommandError('datanetwork not found: %s' % datanetwork)
    elif utils.is_uuid_like(datanetwork):
        try:
            h = cc.datanetwork.get(datanetwork)
        except exc.HTTPNotFound:
            raise exc.CommandError('datanetwork not found: %s' % datanetwork)
        else:
            return h
    else:
        datanetwork_list = cc.datanetwork.list()
        for n in datanetwork_list:
            if n.name == datanetwork:
                return n
        else:
            raise exc.CommandError('datanetwork not found: %s' % datanetwork)
Example #4
0
def _find_disk(cc, ihost, idisk):
    if utils.is_uuid_like(idisk):
        try:
            disk = cc.idisk.get(idisk)
        except exc.HTTPNotFound:
            return None
        else:
            return disk
    else:
        disklist = cc.idisk.list(ihost.uuid)
        for disk in disklist:
            if disk.device_node == idisk or disk.device_path == idisk:
                return disk
        else:
            return None
Example #5
0
def _find_ihost(cc, ihost):
    if ihost.isdigit() or utils.is_uuid_like(ihost):
        try:
            h = cc.ihost.get(ihost)
        except exc.HTTPNotFound:
            raise exc.CommandError('host not found: %s' % ihost)
        else:
            return h
    else:
        hostlist = cc.ihost.list()
        for h in hostlist:
            if h.hostname == ihost:
                return h
        else:
            raise exc.CommandError('host not found: %s' % ihost)