示例#1
0
def hello(remote_ip, **kw):
    """
    REST stub for hello function

    @parameter{kw}
    @returns HTTP response
    """
    vm = VM.get_by_ip(remote_ip)
    log.info(vm.user_id, "vm  called hello")
    Command.hello(remote_ip)

    r = response('ok')
    if int(kw.get('version', 0)) < VERSION:
        f = file(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'actions.py'), 'r')
        r['actions_file'] = f.read()
        f.close()
    return r
示例#2
0
def hello(remote_ip, **kw):
    """
    REST stub for hello function

    @param_post{remote_ip,string}
    @param_post{kw}
    @returns HTTP response
    """
    vm = VM.get_by_ip(remote_ip)
    log.info(vm.user_id, "vm  called hello")
    Command.hello(remote_ip)

    r = response('ok')
    if int(kw.get('version', 0)) < VERSION:
        f = file(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'actions.py'), 'r')
        r['actions_file'] = f.read()
        f.close()
    return r
示例#3
0
文件: vm.py 项目: cc1-cloud/cc1
    def save_and_shutdown(user_id, vm, name, description):
        vm.description = description
        vm.name = name
        vm.save_vm = 2
        try:
            vm.save()
        except:
            raise CMException('vm_save')

        if vm.state != vm_states['running ctx']:
            raise CMException('vm_cannot_shutdown')

        try:
            from cm.models.command import Command

            Command.execute('shutdown', user_id, vm.id)
        except:
            raise CMException('vm_ctx_connect')
示例#4
0
    def save_and_shutdown(user_id, vm, name, description):
        vm.description = description
        vm.name = name
        vm.save_vm = 2
        try:
            vm.save()
        except:
            raise CMException('vm_save')

        if vm.state != vm_states['running ctx']:
            raise CMException('vm_cannot_shutdown')

        try:
            from cm.models.command import Command

            Command.execute('shutdown', user_id, vm.id)
        except:
            raise CMException('vm_ctx_connect')
示例#5
0
文件: ctx.py 项目: cloudcache/cc1
def shutdown(caller_id, vm_id, timeout='now'):
    """
    Method executes \c shutdown on virtual machines listed in \c vm_list
    at given \c timeout (*now* by default) provided they belong to caller.
    @decoratedby{src.cm.utils.decorators.user_log}

    @parameter{vm_id,int}
    @parameter{timeout,string} optional, "now" by default
    """
    return Command.execute('shutdown', caller_id, vm_id, timeout=timeout)
示例#6
0
def shutdown(caller_id, vm_id, timeout='now'):
    """
    Executes \c shutdown on virtual machines listed in \c vm_list at a given
    \c timeout (@val{now} by default) provided they belong to caller.

    @cmview_user
    @param_post{vm_id,int}
    @param_post{timeout,string} optional, "now" by default
    """
    return Command.execute('shutdown', caller_id, vm_id, timeout=timeout)
示例#7
0
文件: ctx.py 项目: cloudcache/cc1
def reboot(caller_id, vm_id, timeout='now'):
    """
    Function executes \c reboot on given VM at given \c timeout (*now* by default).
    @warning Deprecated since execution's success/failure depends on inner
    VM's state.
    @decoratedby{src.cm.utils.decorators.user_log}

    @parameter{vm_id,int} id of the VM to reboot
    @parameter{timeout,string} @optional{"now"}
    """
    return Command.execute('reboot', caller_id, vm_id, timeout=timeout)
示例#8
0
def reset_password(caller_id, vm_id, vm_username):
    """
    Resets password of the existing OS user \c user_name on given VM. User
    obtains new randomly created password. Such a password is sent in CM
    response. It is recommended to change password manually afterwards.

    @cmview_user
    @param_post{vm_id,int}
    @param_post{vm_username,string} username of the user whose password should
    be reseted
    """
    return {'password': Command.execute('reset_password', caller_id, vm_id, user=vm_username)}
示例#9
0
def add_ssh_key(caller_id, vm_ids, vm_username, vm_key):
    """
    Injects given SSH public key to authorized keys on specified VMs.

    @cmview_user
    @param_post{vm_ids,list(int)} id's of the VMs where SSH public key should be injected
    @param_post{vm_username,string}
    @param_post{vm_key,string}
    """
    results = ''
    for vm_id in vm_ids:
        results += Command.execute('add_ssh_key', caller_id, vm_id, user=vm_username, ssh_key=vm_key)
    return results
示例#10
0
def reboot(caller_id, vm_id, timeout='now'):
    """
    Executes reboot on given VM at given timeout. Be default it's executed
    with no delay.

    @warning Deprecated since execution's success/failure depends on inner
    VM's state.

    @cmview_user
    @param_post{vm_id,int} id of the VM to reboot
    @param_post{timeout,string} @optional{"now"}
    """
    return Command.execute('reboot', caller_id, vm_id, timeout=timeout)
示例#11
0
文件: ctx.py 项目: cloudcache/cc1
def reset_password(caller_id, vm_id, vm_username):
    """
    Method resets password of the existing OS user \c user_name on given VM.
    @decoratedby{src.cm.utils.decorators.user_log}

    @parameter{vm_id,int}
    @parameter{data,dict}
    \n fields:
    @dictkey{user_name,string} whose password is to be reseted
    @dictkey{password,string} new password to set

    @noresponse
    """
    return {'password': Command.execute('reset_password', caller_id, vm_id, user=vm_username)}
示例#12
0
文件: ctx.py 项目: cloudcache/cc1
def add_ssh_key(caller_id, vm_ids, vm_username, vm_key):
    """
    Method sets key \c vm_key on each machine listed in \c vm_ids
    (provided they belong to caller).
    @decoratedby{src.cm.utils.decorators.user_log}

    @parameter{vm_ids,int} id's of the VMs to add SSH key on which
    @parameter{data,dict}
    \n fields:
    @dictkey{vm_username,string}
    @dictkey{vm_key,string}
    """
    results = ''
    for vm_id in vm_ids:
        results += Command.execute('add_ssh_key', caller_id, vm_id, user=vm_username, ssh_key=vm_key)
    return results