本文整理汇总了Python中profitbricks.client.ProfitBricksService.delete_volume方法的典型用法代码示例。如果您正苦于以下问题:Python ProfitBricksService.delete_volume方法的具体用法?Python ProfitBricksService.delete_volume怎么用?Python ProfitBricksService.delete_volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.delete_volume方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import delete_volume [as 别名]
def main(argv=None):
'''Command line options.'''
if argv is None:
argv = sys.argv
else:
sys.argv.extend(argv)
program_name = os.path.basename(sys.argv[0])
program_version = "v%s" % __version__
program_build_date = str(__updated__)
program_version_message = '%%(prog)s %s (%s)' % (program_version,
program_build_date)
program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
program_license = '''%s
Created by J. Buchhammer on %s.
Copyright 2016 ProfitBricks GmbH. All rights reserved.
Licensed under the Apache License 2.0
http://www.apache.org/licenses/LICENSE-2.0
Distributed on an "AS IS" basis without warranties
or conditions of any kind, either express or implied.
USAGE
''' % (program_shortdesc, str(__date__))
try:
# Setup argument parser
parser = ArgumentParser(description=program_license,
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('-u', '--user', dest='user', help='the login name')
parser.add_argument('-p', '--password', dest='password',
help='the login password')
parser.add_argument('-L', '--Login', dest='loginfile', default=None,
help='the login file to use')
parser.add_argument('-d', '--datacenterid', dest='dc_id',
required=True, default=None,
help='datacenter of the server')
parser.add_argument('-s', '--serverid', dest='serverid', default=None,
help='ID of the server')
parser.add_argument('-n', '--name', dest='servername', default=None,
help='name of the server')
parser.add_argument('-C', '--command', dest='command', default=None,
help='remote shell command to use for shutdown')
parser.add_argument('-v', '--verbose', dest="verbose", action="count",
help="set verbosity level [default: %(default)s]")
parser.add_argument('-V', '--version', action='version',
version=program_version_message)
# Process arguments
args = parser.parse_args()
global verbose
verbose = args.verbose
dc_id = args.dc_id
if verbose > 0:
print("Verbose mode on")
if args.serverid is None and args.servername is None:
parser.error("one of 'serverid' or 'name' must be specified")
(user, password) = getLogin(args.loginfile, args.user, args.password)
if user is None or password is None:
raise ValueError("user or password resolved to None")
pbclient = ProfitBricksService(user, password)
server = getServerStates(pbclient, dc_id, args.serverid,
args.servername)
if server is None:
raise Exception(1, "specified server not found")
print("using server {}(id={}) in state {}, {}"
.format(server['name'], server['id'], server['state'],
server['vmstate']))
# ! stop/start/reboot_server() simply return 'True' !
# this implies, that there's NO response nor requestId to track!
if server['vmstate'] == 'SHUTOFF':
print("VM is already shut off")
else:
if args.command is None:
print("no command specified for shutdown of VM")
else:
print("executing {}".format(args.command))
cmdrc = call(args.command, shell=True)
print("executing {} returned {}".format(args.command, cmdrc))
server = wait_for_server(pbclient, dc_id, server['id'],
indicator='vmstate', state='SHUTOFF',
timeout=300)
# first we have to delete all attached volumes
volumes = pbclient.get_attached_volumes(dc_id, server['id'], 0)
for vol in volumes['items']:
print("deleting volume {} of server {}"
.format(vol['id'], server['name']))
pbclient.delete_volume(dc_id, vol['id'])
pbclient.delete_server(dc_id, server['id'])
wait_for_datacenter(pbclient, dc_id)
except KeyboardInterrupt:
# handle keyboard interrupt #
return 0
#.........这里部分代码省略.........
示例2: TestVolume
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import delete_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: TestVolume
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import delete_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',
#.........这里部分代码省略.........