当前位置: 首页>>代码示例>>Python>>正文


Python VM.get方法代码示例

本文整理汇总了Python中cm.models.vm.VM.get方法的典型用法代码示例。如果您正苦于以下问题:Python VM.get方法的具体用法?Python VM.get怎么用?Python VM.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cm.models.vm.VM的用法示例。


在下文中一共展示了VM.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: destroy

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def destroy(caller_id, vm_ids):
    """
    This function only destroys VM. All the cleanup (removing disk, saving,
    rescuing resources, ...) is done by hook through
    \c contextualization.update_vm method (yeah, intuitive).

    Simple sequence diagram:

    @code
            CLM        CM         CTX           Node (HOOK)
             .
            Destroy -->destroy
             |          |       (LV.destroy)
             |          |------------------------->HookScript
             .          .                          |
             .          .          ctx.update_vm<--|
             .          .           |              |
             .          .           |------------->cp
             .          .           |------------->rm
             .          .          update_resources
    @endcode

    @cmview_user
    @param_post{vm_ids,list} list of virtual machines' ids

    @response{list(dict)} VM.destroy() retval
    """
    vms = []
    for vm_id in vm_ids:
        vms.append(VM.get(caller_id, vm_id))
    return VM.destroy(vms)
开发者ID:cc1-cloud,项目名称:cc1,代码行数:33,代码来源:vm.py

示例2: attach

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def attach(caller_id, storage_image_id, vm_id):
    # vm_id, img_id, destination='usb', check=True/False
    """
    Attaches selected storage disk to specified Virtual Machine. Such disk may be
    mounted to VM so that data generated by VM may be stored on it. VM also gains
    access to data already stored on that storage disk.

    @cmview_user

    @parameter{storage_image_id,int} id of block device (should be Storage type) - Disk Volume Image
    @parameter{vm_id,int} id of the VM which Storage Image should be attached to

    @response{None}
    """
    vm = VM.get(caller_id, vm_id)
    disk = StorageImage.get(caller_id, storage_image_id)

    # Check if disk is already attached to a vm
    if disk.vm:
        raise CMException('image_attached')

    disk.attach(vm)

    try:
        disk.save()
    except:
        raise CMException('storage_image_attach')
开发者ID:cloudcache,项目名称:cc1,代码行数:29,代码来源:storage_image.py

示例3: attach

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def attach(caller_id, iso_image_id, vm_id):
    # vm_id, img_id, destination='usb', check=True/False
    """
    Attaches specified IsoImage to specified VM. It makes possible booting
    any operating system on created VM.

    @cmview_user
    @param_post{iso_image_id,int} id of block device (should be IsoImage type)
    @param_post{vm_id,int} id of the VM which IsoImage should be attached to

    @response{None}
    """

    vm = VM.get(caller_id, vm_id)
    disk = IsoImage.get(caller_id, iso_image_id)

    # Check if disk is already attached to a vm
    if disk.vm:
        raise CMException('image_attached')

    disk.attach(vm)

    try:
        disk.save()
    except:
        raise CMException('iso_image_attach')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:28,代码来源:iso_image.py

示例4: execute

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
    def execute(name, user_id, vm_id, **kwargs):
        """
        Method executes command @prm{name} on the specified VM.
        User with id @prm{user_id} must be the owner of that VM.

        @parameter{name,string} name of the function to execute
        @parameter{user_id,long} id of the declared VM owner
        @parameter{vm_id,int} id of the VM on which command needs to be executed
        @parameter{kwargs,dict} keyword args for the called function

        @raises{ctx_timeout,CMException}
        @raises{ctx_execute_command,CMException}
        """
        vm = VM.get(user_id, vm_id)

        try:
            cmd = Command.add_command(name, user_id, vm_id, **kwargs)
            transaction.commit()
            log.debug(user_id, "Command state %s for machine %s" % (cmd.state, vm_id))

            dom = vm.lv_domain()
            dom.sendKey(0, 500, [113], 1, 0)

            retry = 3
            retry_factor = 1.2
            retry_time = 1
            try:
                while retry > 0:
                    log.debug(user_id, "Check if command %s is finished for machine %s" % (cmd.id, vm_id))
                    Command.objects.update()
                    cmd = Command.objects.get(id=cmd.id)
                    log.debug(user_id, "Checked command status: %s, %s, %s" % (cmd.state, command_states['finished'], bool(cmd.state == command_states['finished'])))
                    if cmd.state == command_states['finished']:
                        log.debug(user_id, "Response %s from machine %s" % (cmd.response, vm_id))
                        break
                    elif cmd.state == command_states['failed']:
                        raise CMException('ctx_' + name)
                    retry -= 1
                    retry_time *= retry_factor
                    sleep(retry_time)
            except:
                raise
            finally:
                cmd.delete()

            if retry == 0:
                log.debug(user_id, "Command %s for machine %s - TIMEOUT" % (name, vm_id))
                raise CMException('ctx_timeout')

            return cmd.response or ''
        except CMException:
            raise
        except Exception:
            log.exception(user_id, 'Execute command')
            raise CMException('ctx_execute_command')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:57,代码来源:command.py

示例5: get_by_id

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def get_by_id(caller_id, vm_id):
    """
    Returns requested caller's VM.
    @cmview_user

    @parameter{vm_id,int} id of the requested VM

    @response{dict} VM's extended info
    """
    vm = VM.get(caller_id, vm_id)
    vm_mod = vm.long_dict
    return vm_mod
开发者ID:cloudcache,项目名称:cc1,代码行数:14,代码来源:vm.py

示例6: get_by_id

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def get_by_id(caller_id, vm_id):
    """
    Returns requested caller's VM.

    @cmview_user
    @param_post{vm_id,int} id of the requested VM

    @response{dict} VM.dict property of the requested VM
    """
    vm = VM.get(caller_id, vm_id)
    vm_mod = vm.long_dict
    return vm_mod
开发者ID:cc1-cloud,项目名称:cc1,代码行数:14,代码来源:vm.py

示例7: detach_vnc

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def detach_vnc(caller_id, vm_id):
    """
    Detaches VNC redirection from VM.

    @cmview_user
    @param_post{vm_id,int} id of the VM to have detached VM redirection
    """
    vm = VM.get(caller_id, vm_id)
    vm.detach_vnc()

    try:
        vm.save()
    except:
        raise CMException('vnc_detach')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:16,代码来源:vm.py

示例8: attach_vnc

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def attach_vnc(caller_id, vm_id):
    """
    Attaches VNC redirection to VM.
    @cmview_user

    @parameter{vm_id,int} id of the VM to have attached VM redirection

    @response{None}
    """
    vm = VM.get(caller_id, vm_id)
    vm.attach_vnc()

    try:
        vm.save()
    except:
        raise CMException('vnc_attach')
开发者ID:cloudcache,项目名称:cc1,代码行数:18,代码来源:vm.py

示例9: edit

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def edit(caller_id, vm_id, name, description):
    """
    Updates VM's attributes.

    @cmview_user
    @param_post{vm_id,int} id of the VM to edit
    @param_post{name,string}
    @param_post{description,string}

    @response{src.cm.views.utils.image.edit()}
    """
    vm = VM.get(caller_id, vm_id)

    vm.name = name
    vm.description = description
    vm.save(update_fields=['name', 'description'])
开发者ID:cc1-cloud,项目名称:cc1,代码行数:18,代码来源:vm.py

示例10: reset

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def reset(caller_id, vm_ids):
    """
    Safely restarts selected callers VMs

    @cmview_user
    @param_post{vm_ids,list(int)} ids of the VMs to restart

    @response{src.cm.views.utils.image.restart()}
    """

    # get to check permissions on vms
    vms = []
    for vm_id in vm_ids:
        vms.append(VM.get(caller_id, vm_id))

    return VM.reset(vms)
开发者ID:cc1-cloud,项目名称:cc1,代码行数:18,代码来源:vm.py

示例11: detach

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def detach(caller_id, storage_image_id, vm_id):
    """
    Detaches specified StorageImage from specified VM.

    @cmview_user
    @param_post{vm_id,int} id of the VM StorageImage should be detached from
    @param_post{storage_image_id,int} id of the StorageImage to detach
    """
    vm = VM.get(caller_id, vm_id)
    disk = StorageImage.get(caller_id, storage_image_id)

    disk.detach(vm)

    try:
        disk.save()
    except:
        raise CMException('storage_image_attach')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:19,代码来源:storage_image.py

示例12: save_and_shutdown

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def save_and_shutdown(caller_id, vm_id, name, description):
    """
    Calls src.cm.views.utils.image.save_and_shutdown() for the VM selected.

    @cmview_user

    @parameter{vm_id,int} id of the VM to save and shutdown.
    @parameter{name,string}
    @parameter{description,string}
    """
    user = User.get(caller_id)
    vm = VM.get(caller_id, vm_id)

    if user.used_storage + vm.system_image.size > user.storage:
        raise CMException('user_storage_limit')

    VM.save_and_shutdown(caller_id, vm, name, description)
开发者ID:cloudcache,项目名称:cc1,代码行数:19,代码来源:vm.py

示例13: edit

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def edit(caller_id, vm_id, name, description):
    """
    Changes selected VMs' parameters.
    Current should be get by src.cm.views.user.vm.get_by_id().
    @cmview_user

    @parameter{vm_id,int} id of the VM to edit
    @parameter{name,string}
    @parameter{description,string}

    @response{src.cm.views.utils.image.edit()}
    """
    vm = VM.get(caller_id, vm_id)

    vm.name = name
    vm.description = description
    vm.save(update_fields=['name', 'description'])
开发者ID:cloudcache,项目名称:cc1,代码行数:19,代码来源:vm.py

示例14: save_and_shutdown

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def save_and_shutdown(caller_id, vm_id, name, description):
    """
    Calls VM.save_and_shutdown() on specified VM

    @cmview_user
    @param_post{vm_id,int} id of the VM to save and shutdown.
    @param_post{name,string} name of the new SystemImage VM should be saved to
    @param_post{description,string} description of the new SystemImage VM
    should be saved to
    """
    user = User.get(caller_id)
    vm = VM.get(caller_id, vm_id)

    if user.used_storage + vm.system_image.size > user.storage:
        raise CMException('user_storage_limit')

    VM.save_and_shutdown(caller_id, vm, name, description)
开发者ID:cc1-cloud,项目名称:cc1,代码行数:19,代码来源:vm.py

示例15: detach

# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get [as 别名]
def detach(caller_id, iso_image_id, vm_id):
    """
    Detaches specified IsoImage from specified VM.

    @cmview_user
    @param_post{iso_image_id,int} id of the IsoImage to detach
    @param_post{vm_id,int} id of the VM from which IsoImage should be detached

    @response{None}
    """
    vm = VM.get(caller_id, vm_id)
    disk = IsoImage.get(caller_id, iso_image_id)

    disk.detach(vm)

    try:
        disk.save()
    except:
        raise CMException('iso_image_attach')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:21,代码来源:iso_image.py


注:本文中的cm.models.vm.VM.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。