Пример #1
0
    def __init__(self, cm_id):
        """
        Create object representing CM.

        @parameter{cm_id,int} id of the CM

        @returns{common.utils.ServerProxy} instance of CM proxy server
        """
        cluster = Cluster.get(cm_id)
        self.server = ServerProxy('http://%s:%s' % (cluster.address, cluster.port))
Пример #2
0
    def __init__(self, cm_id):
        """
        Create object representing CM.

        @parameter{cm_id,int} id of the CM

        @returns{common.utils.ServerProxy} instance of CM proxy server
        """
        cluster = Cluster.get(cm_id)
        self.server = ServerProxy('http://%s:%s' %
                                  (cluster.address, cluster.port))
Пример #3
0
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
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