本文整理汇总了Python中marvin.lib.base.Snapshot类的典型用法代码示例。如果您正苦于以下问题:Python Snapshot类的具体用法?Python Snapshot怎么用?Python Snapshot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Snapshot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createSnapshot
def createSnapshot(self, volumeid):
try:
Snapshot.create(
self.apiclient,
volumeid
)
except Exception as e:
self.debug("Exception occured: %s" % e)
self.exceptionOccured = True
示例2: test_validateState_fails_after_retry_limit
def test_validateState_fails_after_retry_limit(self):
retries = 3
timeout = 2
api_client = MockApiClient(retries, 'initial state', 'final state')
snapshot = Snapshot({'id': 'snapshot_id'})
state = snapshot.validateState(api_client, 'final state', timeout=timeout, interval=1)
self.assertEqual(state, [FAIL, 'Snapshot state not transited to final state, operation timed out'])
self.assertEqual(retries, api_client.retry_counter)
示例3: test_validateState_succeeds_at_retry_limit
def test_validateState_succeeds_at_retry_limit(self):
retries = 3
timeout = 3
api_client = MockApiClient(retries, 'initial state', 'final state')
snapshot = Snapshot({'id': 'snapshot_id'})
state = snapshot.validateState(api_client, 'final state', timeout=timeout, interval=1)
self.assertEqual(state, [PASS, None])
self.assertEqual(retries, api_client.retry_counter)
示例4: test_01_check_revert_snapshot
def test_01_check_revert_snapshot(self):
""" Test revert snapshot on XenServer
# 1. Deploy a VM.
# 2. Take VM snapshot.
# 3. Verify that volume snapshot fails with error
can not create volume snapshot for VM with VM-snapshot
"""
# Step 1
vm = VirtualMachine.create(
self.userapiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
volumes_cluster_list = list_volumes(
self.apiclient,
virtualmachineid=vm.id,
type='ROOT',
listall=True
)
volume_list_validation = validateList(volumes_cluster_list)
self.assertEqual(
volume_list_validation[0],
PASS,
"Event list validation failed due to %s" %
volume_list_validation[2]
)
root_volume = volumes_cluster_list[0]
#Step 2
vm_snap = VmSnapshot.create(self.apiclient,
vm.id)
self.assertEqual(
vm_snap.state,
"Ready",
"Check the snapshot of vm is ready!"
)
#Step 3
with self.assertRaises(Exception):
Snapshot.create(
self.apiclient,
root_volume.id)
return
示例5: test_05_snapshots_per_project
def test_05_snapshots_per_project(self):
"""Test Snapshot limit per project
"""
# Validate the following
# 1. set max no of snapshots per project to 1.
# 2. Create one snapshot in the project. Snapshot should be
# successfully created
# 5. Try to create another snapshot in this project. It should give
# user an appropriate error and an alert should be generated.
if self.hypervisor.lower() in ["hyperv"]:
raise self.skipTest("Snapshots feature is not supported on Hyper-V")
self.debug("Updating snapshot resource limits for project: %s" % self.project.id)
# Set usage_vm=1 for Account 1
update_resource_limit(self.apiclient, 3, max=1, projectid=self.project.id) # Snapshot
self.debug("Deploying VM for account: %s" % self.account.name)
virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["server"],
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
projectid=self.project.id,
)
self.cleanup.append(virtual_machine_1)
# Verify VM state
self.assertEqual(virtual_machine_1.state, "Running", "Check VM state is Running or not")
# Get the Root disk of VM
volumes = list_volumes(
self.apiclient, virtualmachineid=virtual_machine_1.id, projectid=self.project.id, type="ROOT"
)
self.assertEqual(isinstance(volumes, list), True, "Check for list volume response return valid data")
self.debug("Creating snapshot from volume: %s" % volumes[0].id)
# Create a snapshot from the ROOTDISK
snapshot_1 = Snapshot.create(self.apiclient, volumes[0].id, projectid=self.project.id)
self.cleanup.append(snapshot_1)
# list snapshots
snapshots = list_snapshots(self.apiclient, projectid=self.project.id)
self.debug("snapshots list: %s" % snapshots)
self.assertEqual(validateList(snapshots)[0], PASS, "Snapshots list validation failed")
self.assertEqual(len(snapshots), 1, "Snapshots list should have exactly one entity")
# Exception should be raised for second snapshot
with self.assertRaises(Exception):
Snapshot.create(self.apiclient, volumes[0].id, projectid=self.project.id)
return
示例6: createSnapshotFromVirtualMachineVolume
def createSnapshotFromVirtualMachineVolume(apiclient, account, vmid):
"""Create snapshot from volume"""
try:
volumes = Volume.list(apiclient, account=account.name, domainid=account.domainid, virtualmachineid=vmid)
validationresult = validateList(volumes)
assert validateList(volumes)[0] == PASS, "List volumes should return a valid response"
snapshot = Snapshot.create(apiclient, volume_id=volumes[0].id, account=account.name, domainid=account.domainid)
snapshots = Snapshot.list(apiclient, id=snapshot.id, listall=True)
validationresult = validateList(snapshots)
assert validationresult[0] == PASS, "List snapshot should return a valid list"
except Exception as e:
return [FAIL, e]
return [PASS, snapshot]
示例7: test_03_list_snapshots
def test_03_list_snapshots(self):
"""Test listing Snapshots using 'ids' parameter
"""
list_snapshot_response = Snapshot.list(
self.apiclient,
ids=[self.snapshot_1.id, self.snapshot_2.id, self.snapshot_3.id],
listAll=True
)
self.assertEqual(
isinstance(list_snapshot_response, list),
True,
"ListSnapshots response was not a valid list"
)
self.assertEqual(
len(list_snapshot_response),
3,
"ListSnapshots response expected 3 Snapshots, received %s" % len(list_snapshot_response)
)
#PLEASE UNCOMMENT ONCE VM SNAPSHOT DELAY BUG AFTER VM CREATION IS FIXED
#@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
#def test_04_list_vm_snapshots(self):
"""Test listing VMSnapshots using 'vmsnapshotids' parameter
"""
"""list_vm_snapshot_response = VmSnapshot.list(
示例8: test_01_test_vm_volume_snapshot
def test_01_test_vm_volume_snapshot(self):
"""
@Desc: Test that Volume snapshot for root volume is allowed
when VM snapshot is present for the VM
@Steps:
1: Deploy a VM and create a VM snapshot for VM
2: Try to create snapshot for the root volume of the VM,
It should not fail
"""
# Creating Virtual Machine
virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
VmSnapshot.create(
self.apiclient,
virtual_machine.id,
)
volumes = Volume.list(self.apiclient,
virtualmachineid=virtual_machine.id,
type="ROOT",
listall=True)
self.assertEqual(validateList(volumes)[0], PASS,
"Failed to get root volume of the VM")
snapshot = Snapshot.create(
self.apiclient,
volumes[0].id,
account=self.account.name,
domainid=self.account.domainid
)
self.debug("Snapshot created: ID - %s" % snapshot.id)
snapshots = list_snapshots(
self.apiclient,
id=snapshot.id
)
self.assertEqual(
validateList(snapshots)[0],
PASS,
"Invalid snapshot list"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check resource id in list resources call"
)
return
示例9: test_06_create_snapshots_in_project
def test_06_create_snapshots_in_project(self):
"""Test create snapshots in project
"""
# Validate the following
# 1. Create a project
# 2. Add some snapshots to the project
# 3. Verify snapshot created inside project can only be used in inside
# the project
self.debug("Deploying VM for Project: %s" % self.project.id)
virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["server"],
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
projectid=self.project.id,
)
self.cleanup.append(virtual_machine_1)
# Verify VM state
self.assertEqual(virtual_machine_1.state, "Running", "Check VM state is Running or not")
# Get the Root disk of VM
volumes = list_volumes(self.apiclient, projectid=self.project.id, type="ROOT", listall=True)
self.assertEqual(isinstance(volumes, list), True, "Check for list volume response return valid data")
self.debug("Creating snapshot from volume: %s" % volumes[0].id)
# Create a snapshot from the ROOTDISK
snapshot = Snapshot.create(self.apiclient, volumes[0].id, projectid=self.project.id)
self.cleanup.append(snapshot)
# Verify Snapshot state
self.assertEqual(
snapshot.state in ["BackedUp", "CreatedOnPrimary", "Allocated"],
True,
"Check Snapshot state is in one of the mentioned possible states, \
It is currently: %s"
% snapshot.state,
)
snapshots = Snapshot.list(self.apiclient, account=self.account.name, domainid=self.account.domainid)
self.assertEqual(snapshots, None, "Snapshots should not be available outside the project")
return
示例10: test_02_snapshot_data_disk
def test_02_snapshot_data_disk(self):
"""Test Snapshot Data Disk
"""
if self.hypervisor.lower() in ['hyperv']:
self.skipTest("Snapshots feature is not supported on Hyper-V")
volume = list_volumes(
self.apiclient,
virtualmachineid=self.virtual_machine_with_disk.id,
type='DATADISK',
listall=True
)
self.assertEqual(
isinstance(volume, list),
True,
"Check list response returns a valid list"
)
self.debug("Creating a Snapshot from data volume: %s" % volume[0].id)
snapshot = Snapshot.create(
self.apiclient,
volume[0].id,
account=self.account.name,
domainid=self.account.domainid
)
snapshots = list_snapshots(
self.apiclient,
id=snapshot.id
)
self.assertEqual(
isinstance(snapshots, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
snapshots,
None,
"Check if result exists in list item call"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check resource id in list resources call"
)
self.assertTrue(
is_snapshot_on_nfs(
self.apiclient,
self.dbclient,
self.config,
self.zone.id,
snapshot.id))
return
示例11: test_01_test_vm_volume_snapshot
def test_01_test_vm_volume_snapshot(self):
"""
@Desc: Test that Volume snapshot for root volume is not allowed
when VM snapshot is present for the VM
@Steps:
1: Deploy a VM and create a VM snapshot for VM
2: Try to create snapshot for the root volume of the VM,
It should expect Exception
"""
# Creating Virtual Machine
virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
VmSnapshot.create(
self.apiclient,
virtual_machine.id,
)
volumes = Volume.list(self.apiclient,
virtualmachineid=virtual_machine.id,
type="ROOT",
listall=True)
self.assertEqual(validateList(volumes)[0], PASS,
"Failed to get root volume of the VM")
volume = volumes[0]
with self.assertRaises(Exception):
Snapshot.create(self.apiclient,
volume_id=volume.id)
return
示例12: test_04_template_from_snapshot
def test_04_template_from_snapshot(self):
"""Create Template from snapshot
"""
# Validate the following
# 2. Snapshot the Root disk
# 3. Create Template from snapshot
# 4. Deploy Virtual machine using this template
# 5. VM should be in running state
userapiclient = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain)
volumes = Volume.list(userapiclient, virtualmachineid=self.virtual_machine.id, type="ROOT", listall=True)
volume = volumes[0]
self.debug("Creating a snapshot from volume: %s" % volume.id)
# Create a snapshot of volume
snapshot = Snapshot.create(userapiclient, volume.id, account=self.account.name, domainid=self.account.domainid)
self.debug("Creating a template from snapshot: %s" % snapshot.id)
# Generate template from the snapshot
template = Template.create_from_snapshot(userapiclient, snapshot, self.services["template"])
self.cleanup.append(template)
# Verify created template
templates = Template.list(
userapiclient, templatefilter=self.services["template"]["templatefilter"], id=template.id
)
self.assertNotEqual(templates, None, "Check if result exists in list item call")
self.assertEqual(templates[0].id, template.id, "Check new template id in list resources call")
self.debug("Deploying a VM from template: %s" % template.id)
# Deploy new virtual machine using template
virtual_machine = VirtualMachine.create(
userapiclient,
self.services["virtual_machine"],
templateid=template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
self.cleanup.append(virtual_machine)
vm_response = VirtualMachine.list(
userapiclient, id=virtual_machine.id, account=self.account.name, domainid=self.account.domainid
)
self.assertEqual(isinstance(vm_response, list), True, "Check for list VM response return valid list")
# Verify VM response to check whether VM deployment was successful
self.assertNotEqual(len(vm_response), 0, "Check VMs available in List VMs response")
vm = vm_response[0]
self.assertEqual(vm.state, "Running", "Check the state of VM created from Template")
return
示例13: test_01_snapshot_data_disk
def test_01_snapshot_data_disk(self):
"""Test Snapshot Data Disk
"""
volume = list_volumes(
self.apiclient,
virtualmachineid=self.virtual_machine_with_disk.id,
type='DATADISK',
listall=True
)
self.assertEqual(
isinstance(volume, list),
True,
"Check list response returns a valid list"
)
self.debug("Creating a Snapshot from data volume: %s" % volume[0].id)
snapshot = Snapshot.create(
self.apiclient,
volume[0].id,
account=self.account.name,
domainid=self.account.domainid,
asyncbackup=True
)
snapshots = list_snapshots(
self.apiclient,
id=snapshot.id
)
self.assertEqual(
isinstance(snapshots, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
snapshots,
None,
"Check if result exists in list item call"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check resource id in list resources call"
)
self.assertEqual(
snapshot.state,
"BackingUp",
"Check resource state in list resources call"
)
return
示例14: CreateSnapshot
def CreateSnapshot(self, root_volume, is_recurring):
"""Create Snapshot"""
if is_recurring:
self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
self.testdata["recurring_snapshot"]["schedule"] = 1
recurring_snapshot = SnapshotPolicy.create(
self.apiclient,
root_volume.id,
self.testdata["recurring_snapshot"]
)
self.rec_policy_pool.append(recurring_snapshot)
else:
root_vol_snapshot = Snapshot.create(
self.apiclient,
root_volume.id)
self.snapshot_pool.append(root_vol_snapshot)
return
示例15: create_vm
def create_vm(self,
account,
domain,
isRunning=False,
project =None,
limit =None,
pfrule =False,
lbrule =None,
natrule =None,
volume =None,
snapshot =False):
#TODO: Implemnt pfrule/lbrule/natrule
self.debug("Deploying instance in the account: %s" % account.name)
self.virtual_machine = VirtualMachine.create(self.apiclient,
self.services["virtual_machine"],
accountid=account.name,
domainid=domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype if pfrule else 'basic',
projectid=project.id if project else None)
self.debug("Deployed instance in account: %s" % account.name)
list_virtual_machines(self.apiclient,
id=self.virtual_machine.id)
if snapshot:
volumes = list_volumes(self.apiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True)
self.snapshot = Snapshot.create(self.apiclient,
volumes[0].id,
account=account.name,
domainid=account.domainid)
if volume:
self.virtual_machine.attach_volume(self.apiclient,
volume)
if not isRunning:
self.virtual_machine.stop(self.apiclient)
self.cleanup.append(self.virtual_machine)