本文整理汇总了Python中profitbricks.client.ProfitBricksService.create_volume方法的典型用法代码示例。如果您正苦于以下问题:Python ProfitBricksService.create_volume方法的具体用法?Python ProfitBricksService.create_volume怎么用?Python ProfitBricksService.create_volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.create_volume方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestServer
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_volume [as 别名]
class TestServer(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 volume1.
self.volume1 = self.client.create_volume(
datacenter_id=self.datacenter['id'],
volume=Volume(**self.resource['volume']))
wait_for_completion(self.client, self.volume1, 'create_volume')
# Create test volume2 (attach volume test).
self.volume2 = self.client.create_volume(
datacenter_id=self.datacenter['id'],
volume=Volume(**self.resource['volume']))
wait_for_completion(self.client, self.volume2, 'create_volume')
# Create test server.
server = Server(**self.resource['server'])
server.attach_volumes = [self.volume1['id']]
self.server = self.client.create_server(
datacenter_id=self.datacenter['id'],
server=server)
wait_for_completion(self.client, self.server, 'create_server')
# Create test NIC.
self.nic = self.client.create_nic(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'],
nic=NIC(**self.resource['nic']))
wait_for_completion(self.client, self.nic, 'create_nic')
# Find an Ubuntu image for testing.
for item in self.client.list_images()['items']:
if 'Ubuntu-15' in item['properties']['name'] and item['properties']['location'] == configuration.LOCATION:
self.image = item
@classmethod
def tearDownClass(self):
self.client.delete_datacenter(datacenter_id=self.datacenter['id'])
def test_list(self):
servers = self.client.list_servers(datacenter_id=self.datacenter['id'])
self.assertGreater(len(servers), 0)
self.assertEqual(servers['items'][0]['type'], 'server')
assertRegex(self, servers['items'][0]['id'], self.resource['uuid_match'])
def test_get(self):
server = self.client.get_server(
datacenter_id=self.datacenter['id'],
server_id=self.server['id']
)
self.assertEqual(server['type'], 'server')
self.assertEqual(server['id'], self.server['id'])
self.assertEqual(server['properties']['name'], self.resource['server']['name'])
self.assertEqual(server['properties']['cores'], self.resource['server']['cores'])
self.assertEqual(server['properties']['ram'], self.resource['server']['ram'])
def test_delete(self):
server = self.client.create_server(
datacenter_id=self.datacenter['id'],
server=Server(**self.resource['server'])
)
wait_for_completion(self.client, server, 'create_server')
response = self.client.delete_server(
datacenter_id=self.datacenter['id'],
server_id=server['id']
)
self.assertTrue(response)
def test_update(self):
server = self.client.update_server(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'],
name=self.resource['server']['name'] + ' RENAME')
wait_for_completion(self.client, server, 'update_server')
server = self.client.get_server(
datacenter_id=self.datacenter['id'],
server_id=self.server['id']
)
self.assertEqual(server['id'], self.server['id'])
self.assertEqual(server['properties']['name'], self.resource['server']['name'] + ' RENAME')
self.assertEqual(server['properties']['cores'], self.resource['server']['cores'])
self.assertEqual(server['properties']['ram'], self.resource['server']['ram'])
def test_create_simple(self):
#.........这里部分代码省略.........
示例2: TestVolume
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_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'])
#.........这里部分代码省略.........
示例3: main
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_volume [as 别名]
#.........这里部分代码省略.........
raise ValueError("user or password resolved to None")
pbclient = ProfitBricksService(user, password)
if args.metatype == 'OVF':
metadata = OFVData(args.metafile)
metadata.parse()
else:
sys.stderr.write("Metadata type '{}' is not supported"
.format(args.metatype))
return 1
# we need the DC first to have the location defined
dc_id = None
if args.datacenterid is None:
if args.dcname is None or args.location is None:
sys.stderr.write("Either '-d <id>' or '-D <name> -l <loc>' must be specified")
return 1
# else: we will create the DC later after parsing the meta data
else:
dc_id = args.datacenterid
if dc_id is None:
location = args.location
dc = Datacenter(name=args.dcname, location=location,
description="created by pb_importVM")
print("create new DC {}".format(str(dc)))
response = pbclient.create_datacenter(dc)
dc_id = response['id']
result = wait_for_request(pbclient, response['requestId'])
print("wait loop returned {}".format(result))
else:
dc = pbclient.get_datacenter(dc_id)
location = dc['properties']['location']
print("use existing DC {} in location {}"
.format(dc['properties']['name'], location))
# check if images exist
for disk in metadata.disks:
disk_name = disk['file']
images = get_disk_image_by_name(pbclient, location, disk_name)
if len(images) == 0:
raise ValueError("No HDD image with name '{}' found in location {}"
.format(disk_name, location))
if len(images) > 1:
raise ValueError("Ambigous image name '{}' in location {}"
.format(disk_name, location))
disk['image'] = images[0]['id']
# now we're ready to create the VM
# Server
server = Server(name=metadata.name,
cores=metadata.cpus, ram=metadata.ram)
print("create server {}".format(str(Server)))
response = pbclient.create_server(dc_id, server)
srv_id = response['id']
result = wait_for_request(pbclient, response['requestId'])
print("wait loop returned {}".format(str(result)))
# NICs (note that createing LANs may be implicit)
for nic in metadata.nics:
dcnic = NIC(name=nic['nic'], lan=nic['lanid'])
print("create NIC {}".format(str(dcnic)))
response = pbclient.create_nic(dc_id, srv_id, dcnic)
nic_id = response['id']
result = wait_for_request(pbclient, response['requestId'])
print("wait loop returned {}".format(str(result)))
response = pbclient.get_nic(dc_id, srv_id, nic_id, 2)
mac = response['properties']['mac']
print("dcnic has MAC {} for {}".format(mac, nic_id))
# end for(nics)
# Volumes (we use the image name as volume name too
requests = []
for disk in metadata.disks:
dcvol = Volume(name=disk['file'], size=disk['capacity'],
image=disk['image'],
licence_type=metadata.licenseType)
print("create Volume {}".format(str(dcvol)))
response = pbclient.create_volume(dc_id, dcvol)
requests.append(response['requestId'])
disk['volume_id'] = response['id']
# end for(disks)
if len(requests) != 0:
result = wait_for_requests(pbclient, requests, initial_wait=10, scaleup=15)
print("wait loop returned {}".format(str(result)))
for disk in metadata.disks:
print("attach volume {}".format(disk))
response = pbclient.attach_volume(dc_id, srv_id, disk['volume_id'])
result = wait_for_request(pbclient, response['requestId'])
print("wait loop returned {}".format(str(result)))
# end for(disks)
print("import of VM succesfully finished")
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
示例4: ProfitBricksService
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_volume [as 别名]
"""
from profitbricks.client import ProfitBricksService, Volume
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
client = ProfitBricksService(
username='username', password='password')
i = Volume(
name='Explicitly created volume',
size=56,
image='<IMAGE/SNAPSHOT-ID>',
bus='VIRTIO')
response = client.create_volume(
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,
示例5: main
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_volume [as 别名]
#.........这里部分代码省略.........
dc_id = dcdef["custom"]["id"]
print("using existing DC w/ id {}".format(str(dc_id)))
else:
if args.dcname is not None:
print("Overwrite DC name w/ '{}'".format(args.dcname))
dcdef["properties"]["name"] = args.dcname
dc = getDatacenterObject(dcdef)
# print("create DC {}".format(str(dc)))
response = pbclient.create_datacenter(dc)
dc_id = response["id"]
if "custom" not in dcdef:
dcdef["custom"] = dict()
dcdef["custom"]["id"] = dc_id
result = wait_for_request(pbclient, response["requestId"])
print("wait loop returned {}".format(result))
tmpfile = usefile + ".tmp_postdc"
write_dc_definition(pbclient, dcdef, tmpfile)
requests = []
print("create Volumes {}".format(str(dc)))
# we do NOT consider dangling volumes, only server-attached ones
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"]:
if "custom" in volume and "id" in volume["custom"]:
vol_id = volume["custom"]["id"]
print("using existing volume w/ id {}".format(str(vol_id)))
else:
dcvol = getVolumeObject(volume)
print("OBJ: {}".format(str(dcvol)))
response = pbclient.create_volume(dc_id, dcvol)
volume.update({"custom": {"id": response["id"]}})
requests.append(response["requestId"])
# end for(volume)
# end for(server)
if len(requests) != 0:
result = wait_for_requests(pbclient, requests, initial_wait=10, scaleup=15)
print("wait loop returned {}".format(str(result)))
tmpfile = usefile + ".tmp_postvol"
write_dc_definition(pbclient, dcdef, tmpfile)
else:
print("all volumes existed already")
requests = []
print("create Servers {}".format(str(dc)))
# we do NOT consider dangling volumes, only server-attached ones
for server in dcdef["entities"]["servers"]["items"]:
print("- server {}".format(server["properties"]["name"]))
if "custom" in server and "id" in server["custom"]:
srv_id = server["custom"]["id"]
print("using existing server w/ id {}".format(str(srv_id)))
else:
dcsrv = getServerObject(server)
print("OBJ: {}".format(str(dcsrv)))
response = pbclient.create_server(dc_id, dcsrv)
server.update({"custom": {"id": response["id"]}})
requests.append(response["requestId"])
# end for(server)
if len(requests) != 0:
result = wait_for_requests(pbclient, requests, initial_wait=10, scaleup=15)
print("wait loop returned {}".format(str(result)))
tmpfile = usefile + ".tmp_postsrv"
write_dc_definition(pbclient, dcdef, tmpfile)
示例6: TestVolume
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_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',
#.........这里部分代码省略.........