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


Python CCIManager.wait_for_transaction方法代码示例

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


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

示例1: execute

# 需要导入模块: from SoftLayer import CCIManager [as 别名]
# 或者: from SoftLayer.CCIManager import wait_for_transaction [as 别名]
    def execute(self, args):
        cci = CCIManager(self.client)

        cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
        ready = cci.wait_for_transaction(cci_id, int(args.get('--wait') or 0))

        if ready:
            return "READY"
        else:
            raise CLIAbort("Instance %s not ready" % cci_id)
开发者ID:crvidya,项目名称:softlayer-api-python-client,代码行数:12,代码来源:cci.py

示例2: CCIWaitReadyGoTests

# 需要导入模块: from SoftLayer import CCIManager [as 别名]
# 或者: from SoftLayer.CCIManager import wait_for_transaction [as 别名]
class CCIWaitReadyGoTests(unittest.TestCase):

    def setUp(self):
        self.client = MagicMock()
        self.cci = CCIManager(self.client)
        self.guestObject = self.client['Virtual_Guest'].getObject

    @patch('SoftLayer.managers.cci.CCIManager.wait_for_ready')
    def test_wait_interface(self, ready):
        # verify interface to wait_for_ready is intact
        self.cci.wait_for_transaction(1, 1)
        ready.assert_called_once_with(1, 1, delay=1, pending=True)

    def test_active_not_provisioned(self):
        # active transaction and no provision date should be false
        self.guestObject.side_effect = [
            {'activeTransaction': {'id': 1}},
        ]
        value = self.cci.wait_for_ready(1, 1)
        self.assertFalse(value)

    def test_active_and_provisiondate(self):
        # active transaction and provision date should be True
        self.guestObject.side_effect = [
            {'activeTransaction': {'id': 1},
             'provisionDate': 'aaa'},
        ]
        value = self.cci.wait_for_ready(1, 1)
        self.assertTrue(value)

    def test_active_provision_pending(self):
        # active transaction and provision date
        # and pending should be false
        self.guestObject.side_effect = [
            {'activeTransaction': {'id': 1},
             'provisionDate': 'aaa'},
        ]
        value = self.cci.wait_for_ready(1, 1, pending=True)
        self.assertFalse(value)

    def test_active_reload(self):
        # actively running reload
        self.guestObject.side_effect = [
            {
                'activeTransaction': {'id': 1},
                'provisionDate': 'aaa',
                'lastOperatingSystemReload': {'id': 1},
            },
        ]
        value = self.cci.wait_for_ready(1, 1)
        self.assertFalse(value)

    def test_reload_no_pending(self):
        # reload complete, maintance transactions
        self.guestObject.side_effect = [
            {
                'activeTransaction': {'id': 2},
                'provisionDate': 'aaa',
                'lastOperatingSystemReload': {'id': 1},
            },
        ]
        value = self.cci.wait_for_ready(1, 1)
        self.assertTrue(value)

    def test_reload_pending(self):
        # reload complete, pending maintance transactions
        self.guestObject.side_effect = [
            {
                'activeTransaction': {'id': 2},
                'provisionDate': 'aaa',
                'lastOperatingSystemReload': {'id': 1},
            },
        ]
        value = self.cci.wait_for_ready(1, 1, pending=True)
        self.assertFalse(value)

    @patch('SoftLayer.managers.cci.sleep')
    def test_ready_iter_once_incomplete(self, _sleep):
        self.guestObject = self.client['Virtual_Guest'].getObject

        # no iteration, false
        self.guestObject.side_effect = [
            {'activeTransaction': {'id': 1}},
        ]
        value = self.cci.wait_for_ready(1, 1)
        self.assertFalse(value)
        self.assertFalse(_sleep.called)

    @patch('SoftLayer.managers.cci.sleep')
    def test_iter_once_complete(self, _sleep):
        # no iteration, true
        self.guestObject.side_effect = [
            {'provisionDate': 'aaa'},
        ]
        value = self.cci.wait_for_ready(1, 1)
        self.assertTrue(value)
        self.assertFalse(_sleep.called)

    @patch('SoftLayer.managers.cci.sleep')
    def test_iter_four_complete(self, _sleep):
#.........这里部分代码省略.........
开发者ID:mattmarcum,项目名称:softlayer-python,代码行数:103,代码来源:cci_tests.py

示例3: on_post

# 需要导入模块: from SoftLayer import CCIManager [as 别名]
# 或者: from SoftLayer.CCIManager import wait_for_transaction [as 别名]
    def on_post(self, req, resp, tenant_id, instance_id):
        body = json.loads(req.stream.read().decode())

        if len(body) == 0:
            return bad_request(resp, message="Malformed request body")

        vg_client = req.env['sl_client']['Virtual_Guest']
        cci = CCIManager(req.env['sl_client'])

        try:
            instance_id = int(instance_id)
        except ValueError:
            return not_found(resp, "Invalid instance ID specified.")

        instance = cci.get_instance(instance_id)

        if 'pause' in body or 'suspend' in body:
            try:
                vg_client.pause(id=instance_id)
            except SoftLayerAPIError as e:
                if 'Unable to pause instance' in e.faultString:
                    return duplicate(resp, e.faultString)
                raise
            resp.status = 202
            return
        elif 'unpause' in body or 'resume' in body:
            vg_client.resume(id=instance_id)
            resp.status = 202
            return
        elif 'reboot' in body:
            if body['reboot'].get('type') == 'SOFT':
                vg_client.rebootSoft(id=instance_id)
            elif body['reboot'].get('type') == 'HARD':
                vg_client.rebootHard(id=instance_id)
            else:
                vg_client.rebootDefault(id=instance_id)
            resp.status = 202
            return
        elif 'os-stop' in body:
            vg_client.powerOff(id=instance_id)
            resp.status = 202
            return
        elif 'os-start' in body:
            vg_client.powerOn(id=instance_id)
            resp.status = 202
            return
        elif 'createImage' in body:
            image_name = body['createImage']['name']
            disks = []

            for disk in filter(lambda x: x['device'] == '0',
                               instance['blockDevices']):
                disks.append(disk)

            try:
                vg_client.createArchiveTransaction(
                    image_name,
                    disks,
                    "Auto-created by OpenStack compatibility layer",
                    id=instance_id,
                )
                # Workaround for not having an image guid until the image is
                # fully created. TODO: Fix this
                cci.wait_for_transaction(instance_id, 300)
                _filter = {
                    'privateBlockDeviceTemplateGroups': {
                        'name': {'operation': image_name},
                        'createDate': {
                            'operation': 'orderBy',
                            'options': [{'name': 'sort', 'value': ['DESC']}],
                        }
                    }}

                acct = req.env['sl_client']['Account']
                matching_image = acct.getPrivateBlockDeviceTemplateGroups(
                    mask='id, globalIdentifier', filter=_filter, limit=1)
                image_guid = matching_image.get('globalIdentifier')

                url = self.app.get_endpoint_url('image', req, 'v2_image',
                                                image_guid=image_guid)

                resp.status = 202
                resp.set_header('location', url)
            except SoftLayerAPIError as e:
                compute_fault(resp, e.faultString)
            return
        elif 'os-getConsoleOutput' in body:
            resp.status = 501
            return
        elif 'resize' in body:
            flavor_id = int(body['resize'].get('flavorRef'))
            if flavor_id not in FLAVORS:
                return bad_request(resp,
                                   message="Invalid flavor id in the "
                                   "request body")
            flavor = FLAVORS[flavor_id]
            cci.upgrade(instance_id, cpus=flavor['cpus'],
                        memory=flavor['ram'] / 1024)
            resp.status = 202
            return
#.........这里部分代码省略.........
开发者ID:pbarquer,项目名称:jumpgate,代码行数:103,代码来源:servers.py

示例4: CCITests

# 需要导入模块: from SoftLayer import CCIManager [as 别名]
# 或者: from SoftLayer.CCIManager import wait_for_transaction [as 别名]

#.........这里部分代码省略.........
    def test_generate_multi_disk(self):
        data = self.cci._generate_create_dict(
            cpus=1,
            memory=1,
            hostname='test',
            domain='example.com',
            os_code="STRING",
            disks=[50, 70, 100]
        )

        assert_data = {
            'blockDevices': [
                {"device": "0", "diskImage": {"capacity": 50}},
                {"device": "2", "diskImage": {"capacity": 70}},
                {"device": "3", "diskImage": {"capacity": 100}}]
        }

        self.assertTrue(data.get('blockDevices'))
        self.assertEqual(data['blockDevices'], assert_data['blockDevices'])

    @patch('SoftLayer.managers.cci.sleep')
    def test_wait(self, _sleep):
        guestObject = self.client['Virtual_Guest'].getObject

        # test 4 iterations with positive match
        guestObject.side_effect = [
            {'activeTransaction': {'id': 1}},
            {'activeTransaction': {'id': 1}},
            {'activeTransaction': {'id': 1}},
            {'provisionDate': 'aaa'},
            {'provisionDate': 'aaa'}
        ]

        value = self.cci.wait_for_transaction(1, 4)
        self.assertTrue(value)
        _sleep.assert_has_calls([call(1), call(1), call(1)])
        guestObject.assert_has_calls([
            call(id=1, mask=ANY), call(id=1, mask=ANY),
            call(id=1, mask=ANY), call(id=1, mask=ANY),
        ])

        # test 2 iterations, with no matches
        _sleep.reset_mock()
        guestObject.reset_mock()

        guestObject.side_effect = [
            {'activeTransaction': {'id': 1}},
            {'activeTransaction': {'id': 1}},
            {'activeTransaction': {'id': 1}},
            {'provisionDate': 'aaa'}
        ]
        value = self.cci.wait_for_transaction(1, 2)
        self.assertFalse(value)
        _sleep.assert_has_calls([call(1), call(1)])
        guestObject.assert_has_calls([
            call(id=1, mask=ANY), call(id=1, mask=ANY),
            call(id=1, mask=ANY)
        ])

        # 10 iterations at 10 second sleeps with no
        # matching values.
        _sleep.reset_mock()
        guestObject.reset_mock()
        guestObject.side_effect = [
            {},
            {'activeTransaction': {'id': 1}},
开发者ID:crvidya,项目名称:softlayer-api-python-client,代码行数:70,代码来源:cci_tests.py

示例5: on_post

# 需要导入模块: from SoftLayer import CCIManager [as 别名]
# 或者: from SoftLayer.CCIManager import wait_for_transaction [as 别名]
    def on_post(self, req, resp, tenant_id, instance_id):
        body = json.loads(req.stream.read().decode())

        if len(body) == 0:
            return bad_request(resp, message="Malformed request body")

        vg_client = req.env["sl_client"]["Virtual_Guest"]
        cci = CCIManager(req.env["sl_client"])

        try:
            instance_id = int(instance_id)
        except ValueError:
            return not_found(resp, "Invalid instance ID specified.")

        instance = cci.get_instance(instance_id)

        if "pause" in body or "suspend" in body:
            try:
                vg_client.pause(id=instance_id)
            except SoftLayerAPIError as e:
                if "Unable to pause instance" in e.faultString:
                    return duplicate(resp, e.faultString)
                raise
            resp.status = 202
            return
        elif "unpause" in body or "resume" in body:
            vg_client.resume(id=instance_id)
            resp.status = 202
            return
        elif "reboot" in body:
            if body["reboot"].get("type") == "SOFT":
                vg_client.rebootSoft(id=instance_id)
            elif body["reboot"].get("type") == "HARD":
                vg_client.rebootHard(id=instance_id)
            else:
                vg_client.rebootDefault(id=instance_id)
            resp.status = 202
            return
        elif "os-stop" in body:
            vg_client.powerOff(id=instance_id)
            resp.status = 202
            return
        elif "os-start" in body:
            vg_client.powerOn(id=instance_id)
            resp.status = 202
            return
        elif "createImage" in body:
            image_name = body["createImage"]["name"]
            disks = []

            for disk in filter(lambda x: x["device"] == "0", instance["blockDevices"]):
                disks.append(disk)

            try:
                vg_client.createArchiveTransaction(
                    image_name, disks, "Auto-created by OpenStack compatibility layer", id=instance_id
                )
                # Workaround for not having an image guid until the image is
                # fully created. TODO: Fix this
                cci.wait_for_transaction(instance_id, 300)
                _filter = {
                    "privateBlockDeviceTemplateGroups": {
                        "name": {"operation": image_name},
                        "createDate": {"operation": "orderBy", "options": [{"name": "sort", "value": ["DESC"]}]},
                    }
                }

                acct = req.env["sl_client"]["Account"]
                matching_image = acct.getPrivateBlockDeviceTemplateGroups(
                    mask="id, globalIdentifier", filter=_filter, limit=1
                )
                image_guid = matching_image.get("globalIdentifier")

                url = self.app.get_endpoint_url("image", req, "v2_image", image_guid=image_guid)

                resp.status = 202
                resp.set_header("location", url)
            except SoftLayerAPIError as e:
                compute_fault(resp, e.faultString)
            return
        elif "os-getConsoleOutput" in body:
            resp.status = 501
            return

        return bad_request(resp, message="There is no such action: %s" % list(body.keys()), code=400)
开发者ID:Neetuj,项目名称:jumpgate,代码行数:87,代码来源:servers.py


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