• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.add_task函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wok.utils.add_task函数的典型用法代码示例。如果您正苦于以下问题:Python add_task函数的具体用法?Python add_task怎么用?Python add_task使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: create

    def create(self, vmid, params):
        dev_name = params['name']
        self._passthrough_device_validate(dev_name)
        dev_info = DeviceModel(conn=self.conn).lookup(dev_name)

        if dev_info['device_type'] == 'pci':
            taskid = add_task(u'/plugins/kimchi/vms/%s/hostdevs/' %
                              VMModel.get_vm(vmid, self.conn).name(),
                              self._attach_pci_device, self.objstore,
                              {'vmid': vmid, 'dev_info': dev_info})
            return self.task.lookup(taskid)

        with RollbackContext() as rollback:
            try:
                dev = self.conn.get().nodeDeviceLookupByName(dev_name)
                dev.dettach()
            except Exception:
                raise OperationFailed('KCHVMHDEV0005E', {'name': dev_name})
            else:
                rollback.prependDefer(dev.reAttach)

            rollback.commitAll()

        taskid = add_task(u'/plugins/kimchi/vms/%s/hostdevs/' %
                          VMModel.get_vm(vmid, self.conn).name(),
                          '_attach_%s_device' % dev_info['device_type'],
                          self.objstore, {'vmid': vmid, 'dev_info': dev_info})

        return self.task.lookup(taskid)
开发者ID:encrypt94,项目名称:kimchi,代码行数:29,代码来源:vmhostdevs.py


示例2: test_tasks

    def test_tasks(self):
        id1 = add_task('/plugins/ginger/tasks/1', self._async_op,
                       model._objstore)
        id2 = add_task('/plugins/ginger/tasks/2', self._except_op,
                       model._objstore)
        id3 = add_task('/plugins/ginger/tasks/3', self._intermid_op,
                       model._objstore)

        target_uri = urllib2.quote('^/plugins/ginger/tasks/*', safe="")
        filter_data = 'status=running&target_uri=%s' % target_uri
        tasks = json.loads(
            self.request('/plugins/ginger/tasks?%s' % filter_data).read()
        )
        self.assertEquals(3, len(tasks))

        tasks = json.loads(self.request('/plugins/ginger/tasks').read())
        tasks_ids = [int(t['id']) for t in tasks]
        self.assertEquals(set([id1, id2, id3]) - set(tasks_ids), set([]))
        wait_task(self._task_lookup, id2)
        foo2 = json.loads(
            self.request('/plugins/ginger/tasks/%s' % id2).read()
        )
        keys = ['id', 'status', 'message', 'target_uri']
        self.assertEquals(sorted(keys), sorted(foo2.keys()))
        self.assertEquals('failed', foo2['status'])
        wait_task(self._task_lookup, id3)
        foo3 = json.loads(
            self.request('/plugins/ginger/tasks/%s' % id3).read()
        )
        self.assertEquals('in progress', foo3['message'])
        self.assertEquals('running', foo3['status'])
开发者ID:atreyeemukhopadhyay,项目名称:ginger,代码行数:31,代码来源:test_tasks.py


示例3: test_async_tasks

    def test_async_tasks(self):
        class task_except(Exception):
            pass

        def quick_op(cb, message):
            cb(message, True)

        def long_op(cb, params):
            time.sleep(params.get('delay', 3))
            cb(params.get('message', ''), params.get('result', False))

        def abnormal_op(cb, params):
            try:
                raise task_except
            except:
                cb("Exception raised", False)

        def continuous_ops(cb, params):
            cb("step 1 OK")
            time.sleep(2)
            cb("step 2 OK")
            time.sleep(2)
            cb("step 3 OK", params.get('result', True))

        inst = model.Model('test:///default',
                           objstore_loc=self.tmp_store)
        taskid = add_task('', quick_op, inst.objstore, 'Hello')
        inst.task_wait(taskid)
        self.assertEquals(1, taskid)
        self.assertEquals('finished', inst.task_lookup(taskid)['status'])
        self.assertEquals('Hello', inst.task_lookup(taskid)['message'])

        taskid = add_task('', long_op, inst.objstore,
                          {'delay': 3, 'result': False,
                           'message': 'It was not meant to be'})
        self.assertEquals(2, taskid)
        self.assertEquals('running', inst.task_lookup(taskid)['status'])
        self.assertEquals('OK', inst.task_lookup(taskid)['message'])
        inst.task_wait(taskid)
        self.assertEquals('failed', inst.task_lookup(taskid)['status'])
        self.assertEquals('It was not meant to be',
                          inst.task_lookup(taskid)['message'])
        taskid = add_task('', abnormal_op, inst.objstore, {})
        inst.task_wait(taskid)
        self.assertEquals('Exception raised',
                          inst.task_lookup(taskid)['message'])
        self.assertEquals('failed', inst.task_lookup(taskid)['status'])

        taskid = add_task('', continuous_ops, inst.objstore,
                          {'result': True})
        self.assertEquals('running', inst.task_lookup(taskid)['status'])
        inst.task_wait(taskid, timeout=10)
        self.assertEquals('finished', inst.task_lookup(taskid)['status'])
开发者ID:madhawa,项目名称:kimchi,代码行数:53,代码来源:test_model.py


示例4: test_async_tasks

    def test_async_tasks(self):
        class task_except(Exception):
            pass

        def quick_op(cb, message):
            cb(message, True)

        def long_op(cb, params):
            time.sleep(params.get("delay", 3))
            cb(params.get("message", ""), params.get("result", False))

        def abnormal_op(cb, params):
            try:
                raise task_except
            except:
                cb("Exception raised", False)

        def continuous_ops(cb, params):
            cb("step 1 OK")
            time.sleep(2)
            cb("step 2 OK")
            time.sleep(2)
            cb("step 3 OK", params.get("result", True))

        inst = model.Model("test:///default", objstore_loc=self.tmp_store)
        taskid = add_task("", quick_op, inst.objstore, "Hello")
        inst.task_wait(taskid)
        self.assertEquals(1, taskid)
        self.assertEquals("finished", inst.task_lookup(taskid)["status"])
        self.assertEquals("Hello", inst.task_lookup(taskid)["message"])

        taskid = add_task(
            "", long_op, inst.objstore, {"delay": 3, "result": False, "message": "It was not meant to be"}
        )
        self.assertEquals(2, taskid)
        self.assertEquals("running", inst.task_lookup(taskid)["status"])
        self.assertEquals("OK", inst.task_lookup(taskid)["message"])
        inst.task_wait(taskid)
        self.assertEquals("failed", inst.task_lookup(taskid)["status"])
        self.assertEquals("It was not meant to be", inst.task_lookup(taskid)["message"])
        taskid = add_task("", abnormal_op, inst.objstore, {})
        inst.task_wait(taskid)
        self.assertEquals("Exception raised", inst.task_lookup(taskid)["message"])
        self.assertEquals("failed", inst.task_lookup(taskid)["status"])

        taskid = add_task("", continuous_ops, inst.objstore, {"result": True})
        self.assertEquals("running", inst.task_lookup(taskid)["status"])
        inst.task_wait(taskid, timeout=10)
        self.assertEquals("finished", inst.task_lookup(taskid)["status"])
开发者ID:Truja,项目名称:kimchi,代码行数:49,代码来源:test_model.py


示例5: create

    def create(self, vm_name, params={}):
        """Create a snapshot with the current domain state.

        The VM must be stopped and contain only disks with format 'qcow2';
        otherwise an exception will be raised.

        Parameters:
        vm_name -- the name of the VM where the snapshot will be created.
        params -- a dict with the following values:
            "name": The snapshot name (optional). If omitted, a default value
            based on the current time will be used.

        Return:
        A Task running the operation.
        """
        vir_dom = VMModel.get_vm(vm_name, self.conn)
        if DOM_STATE_MAP[vir_dom.info()[0]] != u'shutoff':
            raise InvalidOperation('KCHSNAP0001E', {'vm': vm_name})

        # if the VM has a non-CDROM disk with type 'raw', abort.
        for storage_name in self.vmstorages.get_list(vm_name):
            storage = self.vmstorage.lookup(vm_name, storage_name)
            type = storage['type']
            format = storage['format']

            if type != u'cdrom' and format != u'qcow2':
                raise InvalidOperation('KCHSNAP0010E', {'vm': vm_name,
                                                        'format': format})

        name = params.get('name', unicode(int(time.time())))

        task_params = {'vm_name': vm_name, 'name': name}
        taskid = add_task(u'/plugins/kimchi/vms/%s/snapshots/%s' % (vm_name,
                          name), self._create_task, self.objstore, task_params)
        return self.task.lookup(taskid)
开发者ID:Finn10111,项目名称:kimchi,代码行数:35,代码来源:vmsnapshots.py


示例6: clone

    def clone(self, pool, name, new_pool=None, new_name=None):
        """Clone a storage volume.

        Arguments:
        pool -- The name of the original pool.
        name -- The name of the original volume.
        new_pool -- The name of the destination pool (optional). If omitted,
            the new volume will be created on the same pool as the
            original one.
        new_name -- The name of the new volume (optional). If omitted, a new
            value based on the original volume's name will be used.

        Return:
        A Task running the clone operation.
        """
        # the same pool will be used if no pool is specified
        if new_pool is None:
            new_pool = pool

        # a default name based on the original name will be used if no name
        # is specified
        if new_name is None:
            base, ext = os.path.splitext(name)
            new_name = get_next_clone_name(self.storagevolumes.get_list(pool),
                                           base, ext)

        params = {'pool': pool,
                  'name': name,
                  'new_pool': new_pool,
                  'new_name': new_name}
        taskid = add_task(u'/plugins/kimchi/storagepools/%s/storagevolumes/%s'
                          % (pool, new_name), self._clone_task, self.objstore,
                          params)
        return self.task.lookup(taskid)
开发者ID:andreteodoro,项目名称:kimchi,代码行数:34,代码来源:storagevolumes.py


示例7: create

    def create(self, params):
        uuid_uuid4 = uuid.uuid4()
        if isinstance(uuid_uuid4, unicode):
            uuid_uuid4 = uuid_uuid4.encode('utf-8')
        archive_id = str(uuid_uuid4)
        stamp = int(time.mktime(time.localtime()))

        # Though formally we ask front-end to not send "include" at all when
        # it's empty, but in implementation we try to be tolerant.
        # Front-end can also send [] to indicate the "include" is empty.
        include = params.get('include')
        exclude = params.get('exclude', [])
        if not include:
            include = self._default_include
            if not exclude:
                exclude = self._default_exclude

        ar_params = {'identity': archive_id,
                     'include': include,
                     'exclude': exclude,
                     'description': params.get('description', ''),
                     'checksum': {},
                     'timestamp': stamp,
                     'file': ''}

        taskid = add_task(u'/backup/create/%s' % (archive_id),
                          self._create_task, self._objstore, ar_params)
        return self.task.lookup(taskid)
开发者ID:olidietzel,项目名称:ginger,代码行数:28,代码来源:backup.py


示例8: _gen_debugreport_file

    def _gen_debugreport_file(self, name):
        gen_cmd = self.get_system_report_tool()

        if gen_cmd is not None:
            return add_task("/plugins/gingerbase/debugreports/%s" % name, gen_cmd, self.objstore, name)

        raise OperationFailed("GGBDR0002E")
开发者ID:frediz,项目名称:gingerbase,代码行数:7,代码来源:debugreports.py


示例9: _mock_vmsnapshots_create

 def _mock_vmsnapshots_create(self, vm_name, params):
     name = params.get('name', unicode(int(time.time())))
     params = {'vm_name': vm_name, 'name': name}
     taskid = add_task(u'/plugins/kimchi/vms/%s/snapshots/%s' %
                       (vm_name, name), self._vmsnapshots_create_task,
                       self.objstore, params)
     return self.task_lookup(taskid)
开发者ID:ShinJR,项目名称:kimchi,代码行数:7,代码来源:mockmodel.py


示例10: trigger

    def trigger(self, name):
        """
        Trigger LUN scanning
        """
        taskid = add_task('/plugins/gingers390/lunscan/trigger',
                          utils.trigger_lun_scan, self.objstore, {})

        return self.task.lookup(taskid)
开发者ID:pawankg,项目名称:gingers390x,代码行数:8,代码来源:fc_luns.py


示例11: _gen_debugreport_file

    def _gen_debugreport_file(self, name):
        gen_cmd = self.get_system_report_tool()

        if gen_cmd is not None:
            return add_task('/plugins/kimchi/debugreports/%s' % name, gen_cmd,
                            self.objstore, name)

        raise OperationFailed("KCHDR0002E")
开发者ID:lcorreia,项目名称:kimchi,代码行数:8,代码来源:debugreports.py


示例12: lookup

    def lookup(self, *name):
        try:
            swupdate = SoftwareUpdate()
        except:
            raise OperationFailed('GGBPKGUPD0004E')

        taskid = add_task('/plugins/gingerbase/host/swupdateprogress',
                          swupdate.tailUpdateLogs, self.objstore, None)
        return self.task.lookup(taskid)
开发者ID:popbjc,项目名称:kimchi,代码行数:9,代码来源:host.py


示例13: format

    def format(self, name, fstype):

        if utils._is_mntd(name):
            raise OperationFailed('GINPART00004E')

        task_params = {'name': name, 'fstype': fstype}
        taskid = add_task(u'/partitions/%s/fstype%s' % (name, fstype),
                          self._format_task, self.objstore, task_params)

        return self.task.lookup(taskid)
开发者ID:atreyeemukhopadhyay,项目名称:ginger,代码行数:10,代码来源:diskparts.py


示例14: create

    def create(self, pool_name, params):
        vol_source = ["url", "capacity"]

        name = params.get("name")

        index_list = list(i for i in range(len(vol_source)) if vol_source[i] in params)
        if len(index_list) != 1:
            raise InvalidParameter("KCHVOL0018E", {"param": ",".join(vol_source)})

        create_param = vol_source[index_list[0]]

        # Verify if the URL is valid
        if create_param == "url":
            url = params["url"]
            try:
                urllib2.urlopen(url).close()
            except:
                raise InvalidParameter("KCHVOL0022E", {"url": url})

        all_vol_names = self.get_list(pool_name)

        if name is None:
            # the methods listed in 'REQUIRE_NAME_PARAMS' cannot have
            # 'name' == None
            if create_param in REQUIRE_NAME_PARAMS:
                raise InvalidParameter("KCHVOL0016E")

            # if 'name' is omitted - except for the methods listed in
            # 'REQUIRE_NAME_PARAMS' - the default volume name will be the
            # file/URL basename.
            if create_param == "url":
                name = os.path.basename(params["url"])
            else:
                name = "upload-%s" % int(time.time())

            name = get_unique_file_name(all_vol_names, name)
            params["name"] = name

        try:
            create_func = getattr(self, "_create_volume_with_%s" % create_param)
        except AttributeError:
            raise InvalidParameter("KCHVOL0019E", {"param": create_param})

        pool_info = StoragePoolModel(conn=self.conn, objstore=self.objstore).lookup(pool_name)
        if pool_info["type"] in READONLY_POOL_TYPE:
            raise InvalidParameter("KCHVOL0012E", {"type": pool_info["type"]})
        if pool_info["state"] == "inactive":
            raise InvalidParameter("KCHVOL0003E", {"pool": pool_name, "volume": name})
        if name in all_vol_names:
            raise InvalidParameter("KCHVOL0001E", {"name": name})

        params["pool"] = pool_name
        targeturi = "/plugins/kimchi/storagepools/%s/storagevolumes/%s" % (pool_name, name)
        taskid = add_task(targeturi, create_func, self.objstore, params)
        return self.task.lookup(taskid)
开发者ID:carriercomm,项目名称:kimchi,代码行数:55,代码来源:storagevolumes.py


示例15: create

    def create(self, params):

        if 'pv_name' not in params:
            raise MissingParameter("GINPV00001E")

        pvname = params['pv_name']

        taskid = add_task(u'/pvs/pv_name/%s' % (pvname),
                          self._create_task, self.objstore, params)

        return self.task.lookup(taskid)
开发者ID:harche,项目名称:ginger,代码行数:11,代码来源:physical_vol.py


示例16: create

    def create(self, params):

        if 'vg_name' not in params:
            raise MissingParameter('GINLV00001E')

        vgname = params['vg_name']

        if 'size' not in params:
            raise MissingParameter('GINLV00002E')

        taskid = add_task(u'/lvs/vg_name/%s' % (vgname),
                          self._create_linear_task, self.objstore, params)
        return self.task.lookup(taskid)
开发者ID:LiftedKilt,项目名称:ginger,代码行数:13,代码来源:log_volume.py


示例17: swupdate

    def swupdate(self, *name):
        try:
            swupdate = SoftwareUpdate()
        except:
            raise OperationFailed('KCHPKGUPD0004E')

        pkgs = swupdate.getNumOfUpdates()
        if pkgs == 0:
            raise OperationFailed('KCHPKGUPD0001E')

        wok_log.debug('Host is going to be updated.')
        taskid = add_task('/plugins/kimchi/host/swupdate', swupdate.doUpdate,
                          self.objstore, None)
        return self.task.lookup(taskid)
开发者ID:lcorreia,项目名称:kimchi,代码行数:14,代码来源:host.py


示例18: create

    def create(self, params):

        if 'vg_name' not in params:
            raise MissingParameter("GINVG00013E")

        vgname = params['vg_name']

        if "pv_paths" not in params:
            raise MissingParameter("GINVG00014E")

        taskid = add_task(u'/vgs/vg_name/%s' % (vgname),
                          self._create_task, self.objstore, params)

        return self.task.lookup(taskid)
开发者ID:atreyeemukhopadhyay,项目名称:ginger,代码行数:14,代码来源:vol_group.py


示例19: unconfigure

 def unconfigure(self, interface):
     """
     method to un-configure network device - remove or bring the network
     device offline and unpersist it
     :param interface: name of the network interface
     :return: returns task json
     """
     wok_log.info('Un-configuring network device %s' % interface)
     device = str(interface).strip()
     if ENCCW in device:
         # filtering out device id from interface
         device = device.replace(ENCCW, '')
     taskid = add_task('/plugins/gingers390x/nwdevices/%s/unconfigure'
                       % interface, _unconfigure_interface,
                       self.objstore, device)
     return self.task.lookup(taskid)
开发者ID:pawankg,项目名称:gingers390x,代码行数:16,代码来源:nwdevices.py


示例20: swupdate

    def swupdate(self, *name):
        try:
            swupdate = SoftwareUpdate()
        except:
            raise OperationFailed('GGBPKGUPD0004E')

        pkgs = swupdate.getNumOfUpdates()
        if pkgs == 0:
            wok_log.debug(messages['GGBPKGUPD0001E'])
            return {'message': messages['GGBPKGUPD0001E']}

        wok_log.debug('Host is going to be updated.')
        taskid = add_task('/plugins/gingerbase/host/swupdate',
                          swupdate.doUpdate,
                          self.objstore, None)
        return self.task.lookup(taskid)
开发者ID:Clevero,项目名称:gingerbase,代码行数:16,代码来源:host.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.run_command函数代码示例发布时间:2022-05-26
下一篇:
Python vms.VMModel类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap