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


Python ProfitBricksService.get_snapshot方法代码示例

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


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

示例1: main

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_snapshot [as 别名]

#.........这里部分代码省略.........
        dcdef_file = outfile + "_source.json"
        print("write source dc to {}".format(dcdef_file))
        write_dc_definition(pbclient, dcdef, dcdef_file)
        print("get existing Snapshots")
        # first get existing snapshots
        known_snapshots = dict()
        snapshots = pbclient.list_snapshots()
        for snap in snapshots["items"]:
            print("SNAP : {}".format(json.dumps(snap)))
            known_snapshots[snap["properties"]["name"]] = snap["id"]
        print("create Snapshots, this may take a while ..")
        # we do NOT consider dangling volumes, only server-attached ones
        vol_snapshots = dict()  # map volume id==snapshot name snapshot id
        for server in dcdef["entities"]["servers"]["items"]:
            print("- server {}".format(server["properties"]["name"]))
            if "volumes" not in server["entities"]:
                print(" server {} has no volumes".format(server["properties"]["name"]))
                continue
            # The volumes are attached by order of creation
            # Thus we must sort them to keep the order in the clone
            print("setting volume order by deviceNumber")
            volumes = server["entities"]["volumes"]["items"]
            new_order = sorted(volumes, key=lambda vol: vol["properties"]["deviceNumber"])
            server["entities"]["volumes"]["items"] = new_order
            for volume in server["entities"]["volumes"]["items"]:
                vol_id = volume["id"]  # this will be the name too
                if vol_id in known_snapshots:
                    print("use existing snapshot {} of volume {}".format(vol_id, volume["properties"]["name"]))
                    vol_snapshots[vol_id] = known_snapshots[vol_id]
                else:
                    print("taking snapshot {} of volume {}".format(vol_id, volume["properties"]["name"]))
                    response = pbclient.create_snapshot(dc_id, vol_id, vol_id, "auto-created by pb_snapshotDatacenter")
                    # response has no request id, need to check metadata state (BUSY, AVAILABLE..)
                    vol_snapshots[vol_id] = response["id"]
                    print("snapshot in progress: {}".format(str(response)))
            # end for(volume)
        # end for(server)
        print("Waiting for snapshots to complete")
        snapdone = dict()
        while len(snapdone) != len(vol_snapshots):
            sleep(10)
            for snap_id in vol_snapshots.values():
                print("looking for {}".format(snap_id))
                if snap_id in snapdone:
                    continue
                snapshot = pbclient.get_snapshot(snap_id)
                print("snapshot {} is in state {}".format(snap_id, snapshot["metadata"]["state"]))
                if snapshot["metadata"]["state"] == "AVAILABLE":
                    snapdone[snap_id] = snapshot["metadata"]["state"]
            # end for(vol_snapshots)
        # end while(snapdone)

        # now replace the volumes image IDs
        print("setting snapshot id to volumes")
        for server in dcdef["entities"]["servers"]["items"]:
            print("- server {}".format(server["properties"]["name"]))
            if "volumes" not in server["entities"]:
                print(" server {} has no volumes".format(server["properties"]["name"]))
                continue
            for volume in server["entities"]["volumes"]["items"]:
                vol_id = volume["id"]  # this will be the name too
                volume["properties"]["image"] = vol_snapshots[vol_id]
            # end for(volume)
        # end for(server)

        # As it came out, the LAN id is rearranged by order of creation
        # Thus we must sort the LANs to keep the order in the clone
        print("setting LAN order by id")
        lans = dcdef["entities"]["lans"]["items"]
        new_order = sorted(lans, key=lambda lan: lan["id"])
        dcdef["entities"]["lans"]["items"] = new_order

        # now sort unordered NICs by MAC and save the dcdef
        # reason is, that NICs seem to be ordered by MAC, but API response
        # doesn't guarantee the order, which we need for re-creation
        print("setting NIC order by MAC")
        for server in dcdef["entities"]["servers"]["items"]:
            print("- server {}".format(server["properties"]["name"]))
            if "nics" not in server["entities"]:
                print(" server {} has no nics".format(server["properties"]["name"]))
                continue
            nics = server["entities"]["nics"]["items"]
            # print("NICs before {}".format(json.dumps(nics)))
            new_order = sorted(nics, key=lambda nic: nic["properties"]["mac"])
            # print("NICs after {}".format(json.dumps(new_order)))
            server["entities"]["nics"]["items"] = new_order
        # end for(server)
        dcdef_file = outfile + ".json"
        print("write snapshot dc to {}".format(dcdef_file))
        write_dc_definition(pbclient, dcdef, dcdef_file)

        return 0

    except KeyboardInterrupt:
        ### handle keyboard interrupt ###
        return 0
    except Exception:
        traceback.print_exc()
        sys.stderr.write("\n" + program_name + ":  for help use --help\n")
        return 2
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:104,代码来源:pb_snapshotDatacenter.py

示例2: TestServer

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_snapshot [as 别名]
class TestServer(unittest.TestCase):
    def setUp(self):
        self.snapshot = ProfitBricksService(
            username='username', password='password')

    def test_list_snapshots(self):
        snapshots = self.snapshot.list_snapshots()

        self.assertEqual(len(snapshots), 4)
        self.assertEqual(snapshots['items'][0]['id'], snapshot_id)
        self.assertEqual(
            snapshots['items'][0]['properties']['name'],
            'Snapshot of storage X on 12.12.12 12:12:12')

        self.assertEqual(
            snapshots['items'][0]['properties']['description'],
            'description of a snapshot')

        self.assertEqual(
            snapshots['items'][0]['properties']['location'], 'de/fkb')

        self.assertEqual(
            snapshots['items'][0]['properties']['size'], 28)

    def test_get_snapshot(self):
        snapshot = self.snapshot.get_snapshot(
            snapshot_id=snapshot_id)

        self.assertEqual(snapshot['id'], snapshot_id)
        self.assertEqual(
            snapshot['properties']['name'],
            'Snapshot of storage X on 12.12.12 12:12:12')

        self.assertEqual(
            snapshot['properties']['description'],
            'description of a snapshot')

        self.assertEqual(
            snapshot['properties']['location'], 'de/fkb')

        self.assertEqual(
            snapshot['properties']['size'], 28)

    def test_delete_snapshot(self):
        snapshot = self.snapshot.delete_snapshot(
            snapshot_id=snapshot_id)

        self.assertTrue(snapshot)

    def test_update_snapshot(self):
        snapshot = self.snapshot.update_snapshot(
            snapshot_id='7df81087-5835-41c6-a10b-3e098593bbd2',
            name='New name')

        self.assertEqual(snapshot['id'], '7df81087-5835-41c6-a10b-3e098593bbd2')
        self.assertEqual(snapshot['properties']['name'], 'New name')

        self.assertEqual(
            snapshot['properties']['description'],
            'description of a snapshot - updated')

        self.assertEqual(
            snapshot['properties']['location'], 'de/fkb')

        self.assertEqual(
            snapshot['properties']['size'], 28)
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:68,代码来源:test_snapshot.py

示例3: print

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_snapshot [as 别名]
for volume_item in volumes['items']:
    volume_id = volume_item['id']
    volume = pb.get_volume(datacenter_id, volume_id)

    volume_name = volume['properties']['name']
    snapshot_name = "{}-{}-{}".format(snapshot_prefix, now.strftime("%Y%m%d"), volume_name)

    print("creating snapshot: {}".format(snapshot_name))
    pb.create_snapshot(datacenter_id, volume_id, snapshot_name)
    sleep(sleep_seconds)

# delete old snapshots
snapshots = pb.list_snapshots()

for snapshot_item in snapshots['items']:
    snapshot_id = snapshot_item['id']
    snapshot = pb.get_snapshot(snapshot_id)

    snapshot_name = snapshot['properties']['name']
    if not snapshot_name.startswith(snapshot_prefix):
        continue

    snapshot_created = snapshot['metadata']['createdDate']
    snapshot_date = datetime.strptime(snapshot_created, "%Y-%m-%dT%H:%M:%SZ")

    if snapshot_date < now - timedelta(days=retention_time):
        print("deleting snapshot: {} (created: {})".format(snapshot_name, snapshot_created))
        pb.delete_snapshot(snapshot_id)
        sleep(sleep_seconds)
开发者ID:seibert-media,项目名称:profitbricks-snapshot,代码行数:31,代码来源:profitbricks-snapshot.py

示例4: ProfitBricksService

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_snapshot [as 别名]
client = ProfitBricksService(username="username", password="password")

snapshots = client.list_snapshots()

for s in snapshots["items"]:
    print s["properties"]["name"]

"""Get Snapshot
"""
from profitbricks.client import ProfitBricksService

snapshot_id = "7df81087-5835-41c6-a10b-3e098593bba4"

client = ProfitBricksService(username="username", password="password")

snapshot = client.get_snapshot(snapshot_id=snapshot_id)

"""
Update Snapshot

Valid snapshot parameters are:

* name (str)
* description (str)
* licence_type (one of 'LINUX', 'WINDOWS' or 'UNKNOWN')
* cpu_hot_plug (bool)
* ram_hot_plug (bool)
* nic_hot_plug (bool)
* nic_hot_unplug (bool)
* disc_virtio_hot_plug (bool)
* disc_virtio_hot_unplug (bool)
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:33,代码来源:snapshot_examples.py


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