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


Python ProfitBricksService.create_snapshot方法代码示例

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


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

示例1: TestVolume

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_snapshot [as 别名]
class TestVolume(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # Create test datacenter
        self.datacenter = self.client.create_datacenter(
            datacenter=Datacenter(**self.resource['datacenter']))
        wait_for_completion(self.client, self.datacenter, 'create_datacenter')

        # Create test volume
        self.volume = self.client.create_volume(
            datacenter_id=self.datacenter['id'],
            volume=Volume(**self.resource['volume']))
        wait_for_completion(self.client, self.volume, 'create_volume')

        # Create snapshot1
        self.snapshot1 = self.client.create_snapshot(
            datacenter_id=self.datacenter['id'],
            volume_id=self.volume['id'],
            name=self.resource['snapshot']['name'],
            description=self.resource['snapshot']['description'])
        wait_for_completion(self.client, self.snapshot1, 'create_snapshot1',
                            wait_timeout=600)

        # Create snapshot2 (used in delete test)
        self.snapshot2 = self.client.create_snapshot(
            datacenter_id=self.datacenter['id'],
            volume_id=self.volume['id'],
            name=self.resource['snapshot']['name'],
            description=self.resource['snapshot']['description'])
        wait_for_completion(self.client, self.snapshot2, 'create_snapshop2',
                            wait_timeout=600)

        self.image = find_image(self.client, configuration.IMAGE_NAME)

    @classmethod
    def tearDownClass(self):
        self.client.remove_snapshot(snapshot_id=self.snapshot1['id'])
        self.client.delete_datacenter(datacenter_id=self.datacenter['id'])

    def test_list_volumes(self):
        volumes = self.client.list_volumes(
            datacenter_id=self.datacenter['id'])

        self.assertGreater(len(volumes), 0)
        assertRegex(self, volumes['items'][0]['id'], self.resource['uuid_match'])
        self.assertEqual(volumes['items'][0]['type'], 'volume')
        self.assertEqual(volumes['items'][0]['properties']['name'], self.resource['volume']['name'])
        self.assertEqual(volumes['items'][0]['properties']['size'], self.resource['volume']['size'])
        self.assertEqual(volumes['items'][0]['properties']['licenceType'], self.resource['volume']['licence_type'])
        self.assertEqual(volumes['items'][0]['properties']['type'], self.resource['volume']['type'])
        self.assertFalse(volumes['items'][0]['properties']['cpuHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['cpuHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['ramHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['ramHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['nicHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['nicHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['discVirtioHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['discVirtioHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['discScsiHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['discScsiHotUnplug'])
        self.assertIsNone(volumes['items'][0]['properties']['bus'])

    def test_get_volume(self):
        volume = self.client.get_volume(
            datacenter_id=self.datacenter['id'],
            volume_id=self.volume['id'])

        self.assertEqual(volume['id'], self.volume['id'])
        self.assertEqual(volume['type'], 'volume')
        self.assertEqual(volume['properties']['name'], self.resource['volume']['name'])
        self.assertEqual(volume['properties']['size'], self.resource['volume']['size'])
        self.assertEqual(volume['properties']['licenceType'], self.resource['volume']['licence_type'])
        self.assertEqual(volume['properties']['type'], self.resource['volume']['type'])
        self.assertFalse(volume['properties']['cpuHotPlug'])
        self.assertFalse(volume['properties']['cpuHotUnplug'])
        self.assertFalse(volume['properties']['ramHotPlug'])
        self.assertFalse(volume['properties']['ramHotUnplug'])
        self.assertFalse(volume['properties']['nicHotPlug'])
        self.assertFalse(volume['properties']['nicHotUnplug'])
        self.assertFalse(volume['properties']['discVirtioHotPlug'])
        self.assertFalse(volume['properties']['discVirtioHotUnplug'])
        self.assertFalse(volume['properties']['discScsiHotPlug'])
        self.assertFalse(volume['properties']['discScsiHotUnplug'])
        self.assertIsNone(volume['properties']['bus'])

    def test_delete_volume(self):
        volume = self.client.create_volume(
            datacenter_id=self.datacenter['id'],
            volume=Volume(**self.resource['volume']))
        wait_for_completion(self.client, volume, 'create_volume')

        volume = self.client.delete_volume(
            datacenter_id=self.datacenter['id'],
            volume_id=volume['id'])
#.........这里部分代码省略.........
开发者ID:jbuchhammer,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:test_volume_live.py

示例2: main

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

#.........这里部分代码省略.........
        dcdef = pbclient.get_datacenter(dc_id, 5)
        print("starting dump of datacenter {}".format(dcdef["properties"]["name"]))
        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)
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:70,代码来源:pb_snapshotDatacenter.py

示例3: print

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_snapshot [as 别名]
# timestamp for creating and deleting
now = datetime.now()

# create new snapshots from list of volumes in datacenter
volumes = pb.list_volumes(datacenter_id=datacenter_id)

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")
开发者ID:seibert-media,项目名称:profitbricks-snapshot,代码行数:32,代码来源:profitbricks-snapshot.py

示例4: ProfitBricksService

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_snapshot [as 别名]
    datacenter_id=datacenter_id, volume=i)

"""Create snapshot
"""

from profitbricks.client import ProfitBricksService

datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
volume_id = '700e1cab-99b2-4c30-ba8c-1d273ddba025'

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

volume = client.create_snapshot(
    datacenter_id=datacenter_id,
    volume_id=volume_id,
    snapshot_name='<URLENCODED_SNAPSHOT_NAME>',
    snapshot_description='<URLENCODED_SNAPSHOT_DESCRIPTION>')

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

datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
volume_id = '700e1cab-99b2-4c30-ba8c-1d273ddba025'
snapshot_id = '7df81087-5835-41c6-a10b-3e098593bba4'


client = ProfitBricksService(
    username='username', password='password')
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:32,代码来源:volume_example.py

示例5: days

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_snapshot [as 别名]
         print "Server '%s' snapshot '%s' deleted, older than %d retention days (%d days, %d seconds)" % (servername, snapname, config.RETENTION_DAYS, snapage.days, snapage.seconds)

        else:
         # Recent, keep it
         print "Server '%s' snapshot '%s' kept, not older than %d retention days (%d days, %d seconds)" % (servername, snapname, config.RETENTION_DAYS, snapage.days, snapage.seconds)
         
	 # For recent backups, check if it's less than min_snap_hours 
         if snapage < timedelta(hours=config.MIN_SNAP_HOURS):
	  # Snapshot is recent, don't make a new one
          no_recent_snapshot = False


    # Does this volume have recent snapshots?
    if no_recent_snapshot:

      # nothing recent, create one. Following PB default name syntax, e.g. "{volumename}-Snapshot-MM/DD/YYYY"
      snapname = volumename + '-Snapshot-' + datetime.utcnow().strftime('%m/%d/%Y')

      # Do the actual snapshot creation api call
      newsnapshot = client.create_snapshot(datacenter_id=config.DATACENTER_ID,volume_id=volumeid, name=snapname)
      print "Created new snapshot '%s' with id '%s'" % (snapname, newsnapshot['id'])
    else:

     # No need to make a snapshot, we have a recent one
     print "Found snapshot less than %d hours old, not making new one" % config.MIN_SNAP_HOURS

  else: 

    # This server is not managed based on config settings
    print "Not managing snapshots for %s" % servername
开发者ID:infernix,项目名称:pbsnappy,代码行数:32,代码来源:pbsnappy.py

示例6: TestVolume

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

#.........这里部分代码省略.........

        self.assertEqual(
            volume['properties']['name'], 'Resized storage to 100 GB')
        self.assertEqual(volume['properties']['size'], 100)

    def test_create_volume(self):
        i = Volume(
            name='Explicitly created volume',
            size=56,
            image='<IMAGE/SNAPSHOT-ID>',
            bus='VIRTIO')

        response = self.volume.create_volume(
            datacenter_id=datacenter_id, volume=i)

        self.assertEqual(
            response['properties']['name'], 'my boot volume for server 1')
        self.assertEqual(response['properties']['size'], 80)
        self.assertEqual(response['properties']['licenceType'], 'WINDOWS')
        self.assertFalse(response['properties']['cpuHotPlug'])
        self.assertFalse(response['properties']['cpuHotUnplug'])
        self.assertFalse(response['properties']['ramHotPlug'])
        self.assertFalse(response['properties']['ramHotUnplug'])
        self.assertFalse(response['properties']['nicHotPlug'])
        self.assertFalse(response['properties']['nicHotUnplug'])
        self.assertFalse(response['properties']['discVirtioHotPlug'])
        self.assertFalse(response['properties']['discVirtioHotUnplug'])
        self.assertFalse(response['properties']['discScsiHotPlug'])
        self.assertFalse(response['properties']['discScsiHotUnplug'])
        self.assertEqual(response['properties']['bus'], 'VIRTIO')
        self.assertEqual(response['properties']['type'], 'HDD')

    def test_create_optional_value(self):
        i = Volume(
            name='Explicitly created volume',
            size=56,
            image='<IMAGE/SNAPSHOT-ID>',
            bus='VIRTIO',
            ram_hot_plug=True,
            cpu_hot_unplug=True)

        response = self.volume.create_volume(
            datacenter_id=datacenter_id, volume=i)

        self.assertEqual(
            response['properties']['name'], 'my boot volume for server 1')
        self.assertEqual(response['properties']['size'], 80)
        self.assertEqual(response['properties']['licenceType'], 'WINDOWS')
        self.assertFalse(response['properties']['cpuHotPlug'])
        self.assertFalse(response['properties']['cpuHotUnplug'])
        self.assertFalse(response['properties']['ramHotPlug'])
        self.assertFalse(response['properties']['ramHotUnplug'])
        self.assertFalse(response['properties']['nicHotPlug'])
        self.assertFalse(response['properties']['nicHotUnplug'])
        self.assertFalse(response['properties']['discVirtioHotPlug'])
        self.assertFalse(response['properties']['discVirtioHotUnplug'])
        self.assertFalse(response['properties']['discScsiHotPlug'])
        self.assertFalse(response['properties']['discScsiHotUnplug'])
        self.assertEqual(response['properties']['bus'], 'VIRTIO')
        self.assertEqual(response['properties']['type'], 'HDD')

    def test_create_snapshot(self):
        volume = self.volume.create_snapshot(
            datacenter_id=datacenter_id,
            volume_id=volume_id,
            name='<URLENCODED_SNAPSHOT_NAME>',
            description='<URLENCODED_SNAPSHOT_DESCRIPTION>')

        self.assertEqual(volume['id'], snapshot_id)
        self.assertEqual(
            volume['properties']['name'],
            'Snapshot of storage X on 12.12.12 12:12:12 - updated')
        self.assertEqual(volume['properties']['description'],
                         'description of a snapshot - updated')
        self.assertEqual(volume['properties']['location'], 'de/fkb')
        self.assertEqual(volume['properties']['size'], 28)
        self.assertEqual(volume['properties']['licenceType'], 'WINDOWS')
        self.assertFalse(volume['properties']['cpuHotPlug'])
        self.assertFalse(volume['properties']['cpuHotUnplug'])
        self.assertFalse(volume['properties']['ramHotPlug'])
        self.assertFalse(volume['properties']['ramHotUnplug'])
        self.assertFalse(volume['properties']['nicHotPlug'])
        self.assertFalse(volume['properties']['nicHotUnplug'])
        self.assertFalse(volume['properties']['discVirtioHotPlug'])
        self.assertFalse(volume['properties']['discVirtioHotUnplug'])
        self.assertFalse(volume['properties']['discScsiHotPlug'])
        self.assertFalse(volume['properties']['discScsiHotUnplug'])

    def test_restore_snapshot(self):
        response = self.volume.restore_snapshot(
            datacenter_id=datacenter_id,
            volume_id=volume_id,
            snapshot_id=snapshot_id)

        self.assertTrue(response)

    def test_remove_snapshot(self):
        volume = self.volume.remove_snapshot(snapshot_id=snapshot_id)

        self.assertTrue(volume)
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:104,代码来源:test_volume.py


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