本文整理汇总了Python中profitbricks.client.ProfitBricksService.get_volume方法的典型用法代码示例。如果您正苦于以下问题:Python ProfitBricksService.get_volume方法的具体用法?Python ProfitBricksService.get_volume怎么用?Python ProfitBricksService.get_volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.get_volume方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestVolume
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_volume [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'])
#.........这里部分代码省略.........
示例2:
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_volume [as 别名]
# Set the servername
servername = server['properties']['name']
# If this server is listed in our config, do the work
if servername in config.TARGET_SERVER_NAMES:
# Get the list of volumes for this server
for server_volume in server['entities']['volumes']['items']:
# Set volumeid
volumeid = server_volume['id']
# Get the volume object from API
volume = client.get_volume( datacenter_id=config.DATACENTER_ID,volume_id=volumeid)
# Set the volumename
volumename = volume['properties']['name']
# Assume we have no recent snapshots
no_recent_snapshot = True
# find snapshots that have a name starting with this volumename
for snapshot in snapshots['items']:
# Set the snapid and snapname
snapid = snapshot['id']
snapname = snapshot['properties']['name']
# Convert the snapshot createdDate to snapdate datetime object
snapdate = datetime.strptime(snapshot['metadata']['createdDate'], "%Y-%m-%dT%H:%M:%SZ")
示例3: ProfitBricksService
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_volume [as 别名]
sleep_seconds = config.getint('snapshots', 'sleep_seconds')
pb = ProfitBricksService(
username=config.get('credentials', 'username'),
password=config.get('credentials', 'password'),
)
# 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)
示例4: TestVolume
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_volume [as 别名]
class TestVolume(unittest.TestCase):
def setUp(self):
self.volume = ProfitBricksService(
username='username', password='password')
def test_list_volumes(self):
volumes = self.volume.list_volumes(
datacenter_id=datacenter_id)
self.assertEqual(len(volumes), 4)
self.assertEqual(volumes['items'][0]['id'], volume_id)
self.assertEqual(volumes['items'][0]['properties']['name'], 'my boot volume for server 1')
self.assertEqual(volumes['items'][0]['properties']['size'], 80)
self.assertEqual(volumes['items'][0]['properties']['licenceType'], 'WINDOWS')
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.assertEqual(volumes['items'][0]['properties']['bus'], 'VIRTIO')
self.assertEqual(volumes['items'][0]['properties']['type'], 'HDD')
def test_get_volume(self):
volume = self.volume.get_volume(
datacenter_id=datacenter_id,
volume_id=volume_id)
self.assertEqual(volume['properties']['name'], 'my boot volume for server 1')
self.assertEqual(volume['properties']['size'], 80)
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'])
self.assertEqual(volume['properties']['bus'], 'VIRTIO')
self.assertEqual(volume['properties']['type'], 'HDD')
def test_delete_volume(self):
volume = self.volume.delete_volume(
datacenter_id=datacenter_id,
volume_id=volume_id)
self.assertTrue(volume)
def test_update_volume(self):
volume = self.volume.update_volume(
datacenter_id=datacenter_id,
volume_id=volume_id,
size=100,
name='Resized storage to 100 GB',
cpu_hot_unplug=True)
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',
#.........这里部分代码省略.........