コード例 #1
0
ファイル: cluster.py プロジェクト: cc1-cloud/cc1
def unlock(cm_id, caller_id, cluster_id):
    """
    Unlocks specified Cluster. Now VMs can be run on
    that Cluster.

    @clmview_admin_clm
    @param_post{cluster_id,int} id of the CM to unlock
    """
    try:
        cluster = Cluster.objects.get(pk=cluster_id)
    except:
        raise CLMException('cluster_get')

    cluster.state = cluster_states['ok']
    try:
        cluster.save()
    except:
        raise CLMException('cluster_unlock')

    users = list(User.objects.filter(is_active__exact=user_active_states['ok']).values_list('id', flat=True))
    status = None
    try:
        status = CM(cluster.id).send_request("user/user/add_missing/", caller_id=caller_id, remote=users)['status']
    except Exception, e:
        log.exception(caller_id, "Adding users: %s" % str(e))
        status = False
コード例 #2
0
ファイル: cluster.py プロジェクト: th3n3xtg3n3ration/cc1
def unlock(cm_id, caller_id, cluster_id):
    """
    Unlocks specified Cluster. Now VMs can be run on
    that Cluster.

    @clmview_admin_clm
    @param_post{cluster_id,int} id of the CM to unlock
    """
    try:
        cluster = Cluster.objects.get(pk=cluster_id)
    except:
        raise CLMException('cluster_get')

    cluster.state = cluster_states['ok']
    try:
        cluster.save()
    except:
        raise CLMException('cluster_unlock')

    users = list(
        User.objects.filter(
            is_active__exact=user_active_states['ok']).values_list('id',
                                                                   flat=True))
    status = None
    try:
        status = CM(cluster.id).send_request("user/user/add_missing/",
                                             caller_id=caller_id,
                                             remote=users)['status']
    except Exception, e:
        log.exception(caller_id, "Adding users: %s" % str(e))
        status = False
コード例 #3
0
ファイル: cluster.py プロジェクト: cc1-cloud/cc1
def add(cm_id, caller_id, name, address, port, new_password):
    """
    Adds new Cluster and makes the caller its admin. There should dedicated
    and configured CM server exist.

    @clmview_admin_clm
    @param_post{name} human-friendly name of the new CM (shown in Web Interface)
    @param_post{address} address of the new CM
    @param_post{port,string} port on which CM is configured to be running
    @param_post{new_password} password protecting the new CM
    """

    if not re.search('^[a-z0-9-]+$', name):
        raise CLMException('cluster_invalid_name')

    try:
        Cluster.objects.get(name=name)
        raise CLMException('cluster_duplicate_name')
    except Cluster.DoesNotExist:
        pass

    cluster = Cluster()
    cluster.address = address
    cluster.port = port
    cluster.name = name
    cluster.state = cluster_states['ok']

    try:
        cluster.save()
    except:
        raise CLMException('cluster_add')

    status = None

    # Get my ip for cluster
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((address, port))
    clm_ip = s.getsockname()[0]

    try:
        status = CM(cluster.id).send_request('user/admin/first_admin_add/',
                                             caller_id=caller_id, new_password=new_password, clm_address=clm_ip)['status']
    except:
        log.exception(caller_id, "Add cluster admin")
        status = False

    if status != 'ok':
        raise CLMException('cluster_add_admin')

    for user in User.objects.filter(default_cluster__exact=None):
        user.default_cluster = cluster
        try:
            user.save()
        except:
            raise CLMException('cluster_add')

    status = None

    users = list(User.objects.values_list('id', flat=True))
    try:
        status = CM(cluster.id).send_request('user/user/add_missing/', caller_id=caller_id, remote=users)['status']
    except Exception, e:
        log.exception(caller_id, e)
        status = False
コード例 #4
0
ファイル: cluster.py プロジェクト: th3n3xtg3n3ration/cc1
def add(cm_id, caller_id, name, address, port, new_password):
    """
    Adds new Cluster and makes the caller its admin. There should dedicated
    and configured CM server exist.

    @clmview_admin_clm
    @param_post{name} human-friendly name of the new CM (shown in Web Interface)
    @param_post{address} address of the new CM
    @param_post{port,string} port on which CM is configured to be running
    @param_post{new_password} password protecting the new CM
    """

    if not re.search('^[a-z0-9-]+$', name):
        raise CLMException('cluster_invalid_name')

    try:
        Cluster.objects.get(name=name)
        raise CLMException('cluster_duplicate_name')
    except Cluster.DoesNotExist:
        pass

    cluster = Cluster()
    cluster.address = address
    cluster.port = port
    cluster.name = name
    cluster.state = cluster_states['ok']

    try:
        cluster.save()
    except:
        raise CLMException('cluster_add')

    status = None

    # Get my ip for cluster
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((address, port))
    clm_ip = s.getsockname()[0]

    try:
        status = CM(cluster.id).send_request('user/admin/first_admin_add/',
                                             caller_id=caller_id,
                                             new_password=new_password,
                                             clm_address=clm_ip)['status']
    except:
        log.exception(caller_id, "Add cluster admin")
        status = False

    if status != 'ok':
        raise CLMException('cluster_add_admin')

    for user in User.objects.filter(default_cluster__exact=None):
        user.default_cluster = cluster
        try:
            user.save()
        except:
            raise CLMException('cluster_add')

    status = None

    users = list(User.objects.values_list('id', flat=True))
    try:
        status = CM(cluster.id).send_request('user/user/add_missing/',
                                             caller_id=caller_id,
                                             remote=users)['status']
    except Exception, e:
        log.exception(caller_id, e)
        status = False
コード例 #5
0
        except CLMException, e:
            transaction.rollback()
            user_id = 0
            resp = e.response
        except Exception, e:
            transaction.rollback()
            gen_exception = True
            user_id = 0
            resp = response('clm_error', str(e))

    if log_enabled or resp['status'] != 'ok':
        log.debug(user_id, '=' * 100)
        log.debug(user_id, 'Function: %s' % name)
        log.debug(user_id, 'ARGS:\n%s' % json.dumps(data, indent=4))
        if gen_exception:
            log.exception(user_id, 'General exception')
        log.debug(user_id, 'Response: %s' % resp or 'None')

    return HttpResponse(json.dumps(resp, default=json_convert))


def cm_request(fun):
    """
    Decorator for CM views functions that:
    - either are fully transparent and just return CM response,
    - or propagate request to CM and further postprocess its response.

    Decorated function ought to be defined like:

    @par Decorated function's declaration
    @code