uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5ca18071f10b17d65a2e0877 | train | function | @contextlib.contextmanager
def vdi_attached(session, vdi_ref, read_only=False, dom0=False):
if dom0:
this_vm_ref = _get_dom0_ref(session)
else:
# Make sure we are running as a domU.
ensure_correct_host(session)
this_vm_ref = _get_this_vm_ref(session)
vbd_ref = create_vbd(ses... | @contextlib.contextmanager
def vdi_attached(session, vdi_ref, read_only=False, dom0=False):
| if dom0:
this_vm_ref = _get_dom0_ref(session)
else:
# Make sure we are running as a domU.
ensure_correct_host(session)
this_vm_ref = _get_this_vm_ref(session)
vbd_ref = create_vbd(session, this_vm_ref, vdi_ref, 'autodetect',
read_only=read_only, boot... | continue
if 'nova_instance_uuid' in vdi_rec['other_config']:
# Belongs to an instance and probably left over after an
# unclean restart
LOG.info('Disconnecting stale VDI %s from compute domU',
vdi_rec['uuid'])
unplug_vbd(session, vbd_ref, th... | 109 | 109 | 364 | 25 | 84 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | vdi_attached | vdi_attached | 2,162 | 2,196 | 2,162 | 2,163 | 1c874eb773cfdb30f9af906a2f2462d1db8c9c1f | bigcode/the-stack | train |
9438c667d7bbd1fd268641d2 | train | function | def _vdi_get_virtual_size(session, vdi_ref):
size = session.call_xenapi('VDI.get_virtual_size', vdi_ref)
return int(size)
| def _vdi_get_virtual_size(session, vdi_ref):
| size = session.call_xenapi('VDI.get_virtual_size', vdi_ref)
return int(size)
| version[0] > 5
if (xcp and not r1_2_or_above) or (xenserver and not r6_or_above):
return 'VDI.resize_online'
return 'VDI.resize'
def _vdi_get_virtual_size(session, vdi_ref):
| 64 | 64 | 37 | 13 | 51 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vdi_get_virtual_size | _vdi_get_virtual_size | 850 | 852 | 850 | 850 | 9befc9ec1ac715feb64cc1199feed9195bf8f4d3 | bigcode/the-stack | train |
2d41a8c2ae5d3ba352e1c9ac | train | function | def _create_cached_image(context, session, instance, name_label,
image_id, image_type, image_handler):
sr_ref = safe_find_sr(session)
sr_type = session.call_xenapi('SR.get_type', sr_ref)
if CONF.use_cow_images and sr_type != "ext":
LOG.warning("Fast cloning is only supporte... | def _create_cached_image(context, session, instance, name_label,
image_id, image_type, image_handler):
| sr_ref = safe_find_sr(session)
sr_type = session.call_xenapi('SR.get_type', sr_ref)
if CONF.use_cow_images and sr_type != "ext":
LOG.warning("Fast cloning is only supported on default local SR "
"of type ext. SR on this system was found to be of "
"type %s. I... | kernel'].get('file')
if instance['ramdisk_id']:
vdis = _create_kernel_image(context, session,
instance, name_label, instance['ramdisk_id'],
ImageType.RAMDISK)
ramdisk_file = vdis['ramdisk'].get('file')
return kernel_file, ramdisk_file
def destroy_kernel_ramdis... | 180 | 180 | 601 | 24 | 155 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _create_cached_image | _create_cached_image | 1,229 | 1,288 | 1,229 | 1,230 | 5bc681928ad113e5ba0eafcc9556e83564e53e6e | bigcode/the-stack | train |
44cfacc070f923906c26421c | train | function | def _sparse_copy(src_path, dst_path, virtual_size, block_size=4096):
"""Copy data, skipping long runs of zeros to create a sparse file."""
start_time = last_log_time = timeutils.utcnow()
EMPTY_BLOCK = '\0' * block_size
bytes_read = 0
skipped_bytes = 0
left = virtual_size
LOG.debug("Starting... | def _sparse_copy(src_path, dst_path, virtual_size, block_size=4096):
| """Copy data, skipping long runs of zeros to create a sparse file."""
start_time = last_log_time = timeutils.utcnow()
EMPTY_BLOCK = '\0' * block_size
bytes_read = 0
skipped_bytes = 0
left = virtual_size
LOG.debug("Starting sparse_copy src=%(src_path)s dst=%(dst_path)s "
"virtu... | )
def _log_progress_if_required(left, last_log_time, virtual_size):
if timeutils.is_older_than(last_log_time, PROGRESS_INTERVAL_SECONDS):
last_log_time = timeutils.utcnow()
complete_pct = float(virtual_size - left) / virtual_size * 100
LOG.debug("Sparse copy in progress, "
... | 131 | 131 | 438 | 20 | 110 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _sparse_copy | _sparse_copy | 2,328 | 2,374 | 2,328 | 2,328 | 0e2b1946893514d3d4fe7d23b40384ef6da58e93 | bigcode/the-stack | train |
faa9ac40fb59883afe0ba6f4 | train | function | def _safe_copy_vdi(session, sr_ref, instance, vdi_to_copy_ref):
"""Copy a VDI and return the new VDIs reference.
This function differs from the XenAPI `VDI.copy` call in that the copy is
atomic and isolated, meaning we don't see half-downloaded images. It
accomplishes this by copying the VDI's into a t... | def _safe_copy_vdi(session, sr_ref, instance, vdi_to_copy_ref):
| """Copy a VDI and return the new VDIs reference.
This function differs from the XenAPI `VDI.copy` call in that the copy is
atomic and isolated, meaning we don't see half-downloaded images. It
accomplishes this by copying the VDI's into a temporary directory and then
atomically renaming them into th... | 'autodetect',
read_only=True)
try:
yield vm_ref
finally:
try:
destroy_vbd(session, vbd_ref)
except exception.StorageError:
# destroy_vbd() will log error
pass
finally:
destroy_vm... | 85 | 85 | 284 | 19 | 66 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _safe_copy_vdi | _safe_copy_vdi | 496 | 520 | 496 | 496 | 6f81bfc84f197ddeb468f6e43ceb3722be3c008b | bigcode/the-stack | train |
a7c4d48b1b228a6dc553fdb5 | train | function | def destroy_vm(session, instance, vm_ref):
"""Destroys a VM record."""
try:
session.VM.destroy(vm_ref)
except session.XenAPI.Failure:
LOG.exception(_('Destroy VM failed'))
return
LOG.debug("VM destroyed", instance=instance)
| def destroy_vm(session, instance, vm_ref):
| """Destroys a VM record."""
try:
session.VM.destroy(vm_ref)
except session.XenAPI.Failure:
LOG.exception(_('Destroy VM failed'))
return
LOG.debug("VM destroyed", instance=instance)
| 'BIOS order'
if device_id:
rec['platform']['device_id'] = str(device_id).zfill(4)
vm_ref = session.VM.create(rec)
LOG.debug('Created VM', instance=instance)
return vm_ref
def destroy_vm(session, instance, vm_ref):
| 64 | 64 | 60 | 10 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | destroy_vm | destroy_vm | 262 | 270 | 262 | 262 | 5166f8dbc8a7ba7fdac45430a108adbdc198600a | bigcode/the-stack | train |
624b352addb6c570220fd99c | train | function | def _mounted_processing(device, key, net, metadata):
"""Callback which runs with the image VDI attached."""
# NB: Partition 1 hardcoded
dev_path = utils.make_dev_path(device, partition=1)
with utils.tempdir() as tmpdir:
# Mount only Linux filesystems, to avoid disturbing NTFS images
err ... | def _mounted_processing(device, key, net, metadata):
| """Callback which runs with the image VDI attached."""
# NB: Partition 1 hardcoded
dev_path = utils.make_dev_path(device, partition=1)
with utils.tempdir() as tmpdir:
# Mount only Linux filesystems, to avoid disturbing NTFS images
err = _mount_filesystem(dev_path, tmpdir)
if not ... | _blocks)
def _mount_filesystem(dev_path, mount_point):
"""mounts the device specified by dev_path in mount_point."""
try:
_out, err = nova.privsep.fs.mount('ext2,ext3,ext4,reiserfs',
dev_path, mount_point, None)
except processutils.ProcessExecutionError as... | 98 | 98 | 328 | 12 | 85 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _mounted_processing | _mounted_processing | 2,407 | 2,437 | 2,407 | 2,407 | 8041c008b3eea74bee6f8a7990a54891b73ca6bc | bigcode/the-stack | train |
bd5fed4ac9333c06b045cd5d | train | function | def _get_rrd(server, vm_uuid):
"""Return the VM RRD XML as a string."""
try:
xml = urlrequest.urlopen("%s://%s:%s@%s/vm_rrd?uuid=%s" % (
server[0],
CONF.xenserver.connection_username,
CONF.xenserver.connection_password,
server[1],
vm_uuid))
... | def _get_rrd(server, vm_uuid):
| """Return the VM RRD XML as a string."""
try:
xml = urlrequest.urlopen("%s://%s:%s@%s/vm_rrd?uuid=%s" % (
server[0],
CONF.xenserver.connection_username,
CONF.xenserver.connection_password,
server[1],
vm_uuid))
return xml.read()
exce... | None
def _get_rrd_server():
"""Return server's scheme and address to use for retrieving RRD XMLs."""
xs_url = urlparse.urlparse(CONF.xenserver.connection_url)
return [xs_url.scheme, xs_url.netloc]
def _get_rrd(server, vm_uuid):
| 64 | 64 | 136 | 10 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_rrd | _get_rrd | 1,951 | 1,965 | 1,951 | 1,951 | 4195a7c75b73404800d45cefdd87d0948a0caa6a | bigcode/the-stack | train |
62d17996c1e5429823dfb9a8 | train | function | def _find_iso_sr(session):
"""Return the storage repository to hold ISO images."""
host = session.host_ref
for sr_ref, sr_rec in session.get_all_refs_and_recs('SR'):
LOG.debug("ISO: looking at SR %s", sr_rec)
if not sr_rec['content_type'] == 'iso':
LOG.debug("ISO: not iso content... | def _find_iso_sr(session):
| """Return the storage repository to hold ISO images."""
host = session.host_ref
for sr_ref, sr_rec in session.get_all_refs_and_recs('SR'):
LOG.debug("ISO: looking at SR %s", sr_rec)
if not sr_rec['content_type'] == 'iso':
LOG.debug("ISO: not iso content")
continue
... | default SR for the pool) "
"and/or configure the flag 'sr_matching_filter'.")
return None
def _safe_find_iso_sr(session):
"""Same as _find_iso_sr except raises a NotFound exception if SR
cannot be determined
"""
sr_ref = _find_iso_sr(session)
if sr_ref is None:
raise exc... | 99 | 99 | 333 | 7 | 91 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _find_iso_sr | _find_iso_sr | 1,913 | 1,942 | 1,913 | 1,913 | b58c3772d93c1c5cc00856d14f2721e642501337 | bigcode/the-stack | train |
e88927ed04195d5439847e75 | train | function | def _import_migrate_ephemeral_disks(session, instance):
ephemeral_vdis = {}
instance_uuid = instance['uuid']
ephemeral_gb = instance.old_flavor.ephemeral_gb
disk_sizes = get_ephemeral_disk_sizes(ephemeral_gb)
for chain_number, _size in enumerate(disk_sizes, start=1):
chain_label = instance_u... | def _import_migrate_ephemeral_disks(session, instance):
| ephemeral_vdis = {}
instance_uuid = instance['uuid']
ephemeral_gb = instance.old_flavor.ephemeral_gb
disk_sizes = get_ephemeral_disk_sizes(ephemeral_gb)
for chain_number, _size in enumerate(disk_sizes, start=1):
chain_label = instance_uuid + "_ephemeral_%d" % chain_number
vdi_label =... | _migrated_root_disk(session, instance):
chain_label = instance['uuid']
vdi_label = instance['name']
return _import_migrated_vhds(session, instance, chain_label, "root",
vdi_label)
def _import_migrate_ephemeral_disks(session, instance):
| 64 | 64 | 178 | 13 | 51 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _import_migrate_ephemeral_disks | _import_migrate_ephemeral_disks | 2,475 | 2,489 | 2,475 | 2,475 | 2d9da91d62870140e130731eff31ab1201eb3292 | bigcode/the-stack | train |
6c849fb09f0bb194bab402e6 | train | function | def host_in_this_pool(session, host_ref):
rec_dict = session.host.get_all_records()
return host_ref in rec_dict.keys()
| def host_in_this_pool(session, host_ref):
| rec_dict = session.host.get_all_records()
return host_ref in rec_dict.keys()
| pci key of other-config parameter to params."""
other_config = session.call_xenapi("VM.get_other_config", vm_ref)
other_config['pci'] = params
session.call_xenapi("VM.set_other_config", vm_ref, other_config)
def host_in_this_pool(session, host_ref):
| 64 | 64 | 29 | 10 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | host_in_this_pool | host_in_this_pool | 2,605 | 2,607 | 2,605 | 2,605 | a50df8e058011e1a02aa5a22b328cc448533cde2 | bigcode/the-stack | train |
1d6e98b0f1fcf73b1b366cf9 | train | function | def _wait_for_device(session, dev, dom0, max_seconds):
"""Wait for device node to appear."""
dev_path = utils.make_dev_path(dev)
found_path = None
if dom0:
found_path = disk_management.wait_for_dev(session, dev_path,
max_seconds)
else:
... | def _wait_for_device(session, dev, dom0, max_seconds):
| """Wait for device node to appear."""
dev_path = utils.make_dev_path(dev)
found_path = None
if dom0:
found_path = disk_management.wait_for_dev(session, dev_path,
max_seconds)
else:
for i in range(0, max_seconds):
if os.pat... | greenthread.sleep(CONF.xenserver.vhd_coalesce_poll_interval)
msg = (_("VHD coalesce attempts exceeded (%d)"
", giving up...") % max_attempts)
raise exception.NovaException(msg)
def _wait_for_device(session, dev, dom0, max_seconds):
| 64 | 64 | 131 | 15 | 49 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _wait_for_device | _wait_for_device | 2,120 | 2,136 | 2,120 | 2,120 | d895a8f6cbb5d2367d3f394ad7bacbc8041b2f62 | bigcode/the-stack | train |
871658beca8cbd4f20c0f973 | train | function | def _write_partition(session, virtual_size, dev):
dev_path = utils.make_dev_path(dev)
primary_first = MBR_SIZE_SECTORS
primary_last = MBR_SIZE_SECTORS + (virtual_size / SECTOR_SIZE) - 1
LOG.debug('Writing partition table %(primary_first)d %(primary_last)d'
' to %(dev_path)s...',
... | def _write_partition(session, virtual_size, dev):
| dev_path = utils.make_dev_path(dev)
primary_first = MBR_SIZE_SECTORS
primary_last = MBR_SIZE_SECTORS + (virtual_size / SECTOR_SIZE) - 1
LOG.debug('Writing partition table %(primary_first)d %(primary_last)d'
' to %(dev_path)s...',
{'primary_first': primary_first, 'primary_las... | _write_partition(session, virtual_size, dev)
dev_path = utils.make_dev_path(dev)
with utils.temporary_chown(dev_path):
with open(dev_path, 'wb') as f:
f.seek(offset)
image_service_func(f)
def _write_partition(session, virtual_size, dev):
| 64 | 64 | 138 | 11 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _write_partition | _write_partition | 2,263 | 2,274 | 2,263 | 2,263 | 0a5eafd1da73b4a587ac56a628d2d2eab3f899a2 | bigcode/the-stack | train |
48b77340f37c6e4bc37d4ccc | train | function | def _find_sr(session):
"""Return the storage repository to hold VM images."""
host = session.host_ref
try:
tokens = CONF.xenserver.sr_matching_filter.split(':')
filter_criteria = tokens[0]
filter_pattern = tokens[1]
except IndexError:
# oops, flag is invalid
LOG.w... | def _find_sr(session):
| """Return the storage repository to hold VM images."""
host = session.host_ref
try:
tokens = CONF.xenserver.sr_matching_filter.split(':')
filter_criteria = tokens[0]
filter_pattern = tokens[1]
except IndexError:
# oops, flag is invalid
LOG.warning("Flag sr_matchin... | _default_sr(session):
"""Looks for the system default SR and triggers a re-scan."""
sr_ref = safe_find_sr(session)
_scan_sr(session, sr_ref)
return sr_ref
def safe_find_sr(session):
"""Same as _find_sr except raises a NotFound exception if SR cannot be
determined
"""
sr_ref = _find_sr(... | 106 | 106 | 354 | 6 | 99 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _find_sr | _find_sr | 1,866 | 1,900 | 1,866 | 1,866 | d85c970e49dace2e47e4af227ae3353529cf7824 | bigcode/the-stack | train |
c16aafd6eb3c2274ef531e30 | train | function | def destroy_vbd(session, vbd_ref):
"""Destroy VBD from host database."""
try:
session.call_xenapi('VBD.destroy', vbd_ref)
except session.XenAPI.Failure:
LOG.exception(_('Unable to destroy VBD'))
raise exception.StorageError(
reason=_('Unable to destroy VBD %s') % vbd_... | def destroy_vbd(session, vbd_ref):
| """Destroy VBD from host database."""
try:
session.call_xenapi('VBD.destroy', vbd_ref)
except session.XenAPI.Failure:
LOG.exception(_('Unable to destroy VBD'))
raise exception.StorageError(
reason=_('Unable to destroy VBD %s') % vbd_ref)
| raise exception.StorageError(
reason=_('Unable to unplug VBD %s') % vbd_ref)
raise exception.StorageError(
reason=_('Reached maximum number of retries '
'trying to unplug VBD %s')
% vbd_ref)
def destroy_vbd(session, vbd_ref):
| 64 | 64 | 79 | 10 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | destroy_vbd | destroy_vbd | 375 | 382 | 375 | 375 | cd601abee36f7b8ddf5f163cbdb3aa4100ead4d2 | bigcode/the-stack | train |
91103215023a6091ab61c088 | train | function | def get_vdi_for_vm_safely(session, vm_ref, userdevice='0'):
"""Retrieves the primary VDI for a VM."""
vbd_refs = _vm_get_vbd_refs(session, vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = _vbd_get_rec(session, vbd_ref)
# Convention dictates the primary VDI will be userdevice 0
if vbd_rec['... | def get_vdi_for_vm_safely(session, vm_ref, userdevice='0'):
| """Retrieves the primary VDI for a VM."""
vbd_refs = _vm_get_vbd_refs(session, vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = _vbd_get_rec(session, vbd_ref)
# Convention dictates the primary VDI will be userdevice 0
if vbd_rec['userdevice'] == userdevice:
vdi_ref = vbd_rec['V... | return session.call_xenapi("VDI.get_uuid", vdi_ref)
def _vdi_snapshot(session, vdi_ref):
return session.call_xenapi("VDI.snapshot", vdi_ref, {})
def get_vdi_for_vm_safely(session, vm_ref, userdevice='0'):
| 63 | 64 | 159 | 19 | 44 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | get_vdi_for_vm_safely | get_vdi_for_vm_safely | 584 | 594 | 584 | 584 | e38f0dfe5a56f557567a3d019d3490ee1505c99c | bigcode/the-stack | train |
1680f719248d4c1143e44076 | train | function | def vm_ref_or_raise(session, instance_name):
vm_ref = lookup(session, instance_name)
if vm_ref is None:
raise exception.InstanceNotFound(instance_id=instance_name)
return vm_ref
| def vm_ref_or_raise(session, instance_name):
| vm_ref = lookup(session, instance_name)
if vm_ref is None:
raise exception.InstanceNotFound(instance_id=instance_name)
return vm_ref
| _uuid,
sr_path, seq_num)
except session.XenAPI.Failure:
msg = "Failed to transfer vhd to new host"
LOG.debug(msg, instance=instance, exc_info=True)
raise exception.MigrationError(reason=msg)
def vm_ref_or_raise(session, instance_name):
| 64 | 64 | 44 | 10 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | vm_ref_or_raise | vm_ref_or_raise | 2,529 | 2,533 | 2,529 | 2,529 | 6a1d7c97d832b76be380e76cd502c9fdfacddce6 | bigcode/the-stack | train |
dc338426f81c2a45a4875e40 | train | function | def create_kernel_and_ramdisk(context, session, instance, name_label):
kernel_file = None
ramdisk_file = None
if instance['kernel_id']:
vdis = _create_kernel_image(context, session,
instance, name_label, instance['kernel_id'],
ImageType.KERNEL)
kernel_file = v... | def create_kernel_and_ramdisk(context, session, instance, name_label):
| kernel_file = None
ramdisk_file = None
if instance['kernel_id']:
vdis = _create_kernel_image(context, session,
instance, name_label, instance['kernel_id'],
ImageType.KERNEL)
kernel_file = vdis['kernel'].get('file')
if instance['ramdisk_id']:
vdis ... | _disk_image(context, session, instance, name_label,
image_id, image_type)
else:
vdi_type = ImageType.to_string(image_type)
return {vdi_type: dict(uuid=None, file=filename)}
def create_kernel_and_ramdisk(context, session, instance, name_label):
| 63 | 64 | 141 | 15 | 48 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | create_kernel_and_ramdisk | create_kernel_and_ramdisk | 1,199 | 1,214 | 1,199 | 1,199 | 4c31007bd3c9574bed4a7fdfc71d2a0d059ddf5e | bigcode/the-stack | train |
c0cd69ffe43044bdfd9d954d | train | function | def generate_configdrive(session, context, instance, vm_ref, userdevice,
network_info, admin_password=None, files=None):
sr_ref = safe_find_sr(session)
vdi_ref = create_vdi(session, sr_ref, instance, 'config-2',
'configdrive', configdrive.CONFIGDRIVESIZE_BYTES)
... | def generate_configdrive(session, context, instance, vm_ref, userdevice,
network_info, admin_password=None, files=None):
| sr_ref = safe_find_sr(session)
vdi_ref = create_vdi(session, sr_ref, instance, 'config-2',
'configdrive', configdrive.CONFIGDRIVESIZE_BYTES)
try:
extra_md = {}
if admin_password:
extra_md['admin_pass'] = admin_password
inst_md = instance_metadata.... | size_gb': size_gb,
'exc': exc})
safe_destroy_vdis(session, vdi_refs)
def generate_iso_blank_root_disk(session, instance, vm_ref, userdevice,
name_label, size_gb):
_generate_disk(session, instance, vm_ref, userdevice, name_label,
... | 111 | 111 | 371 | 27 | 84 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | generate_configdrive | generate_configdrive | 1,138 | 1,170 | 1,138 | 1,139 | c65b2e646f39c0211e0d26a36d9a7463a19cb579 | bigcode/the-stack | train |
582a688597c1357e53ca919a | train | function | def get_vm_device_id(session, image_meta):
# NOTE: device_id should be 2 for windows VMs which run new xentools
# (>=6.1). Refer to http://support.citrix.com/article/CTX135099 for more
# information.
device_id = image_meta.properties.get('hw_device_id')
# The device_id is required to be set for hyp... | def get_vm_device_id(session, image_meta):
# NOTE: device_id should be 2 for windows VMs which run new xentools
# (>=6.1). Refer to http://support.citrix.com/article/CTX135099 for more
# information.
| device_id = image_meta.properties.get('hw_device_id')
# The device_id is required to be set for hypervisor version 6.1 and above
if device_id:
hypervisor_version = session.product_version
if _hypervisor_supports_device_id(hypervisor_version):
return device_id
else:
... | (image_type_id)
def get_vm_device_id(session, image_meta):
# NOTE: device_id should be 2 for windows VMs which run new xentools
# (>=6.1). Refer to http://support.citrix.com/article/CTX135099 for more
# information.
| 64 | 64 | 177 | 60 | 4 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | get_vm_device_id | get_vm_device_id | 145 | 160 | 145 | 148 | 78e79b1f1c55b48f018b3f80184fe32d5831e5fb | bigcode/the-stack | train |
0edf453e3cd5f24d7c7c5b9f | train | function | def _fetch_vhd_image(context, session, instance, image_id, image_handler):
"""Tell glance to download an image and put the VHDs into the SR
Returns: A list of dictionaries that describe VDIs
"""
LOG.debug("Asking xapi to fetch vhd image %s", image_id,
instance=instance)
vdis = image_h... | def _fetch_vhd_image(context, session, instance, image_id, image_handler):
| """Tell glance to download an image and put the VHDs into the SR
Returns: A list of dictionaries that describe VDIs
"""
LOG.debug("Asking xapi to fetch vhd image %s", image_id,
instance=instance)
vdis = image_handler.download_image(
context, session, instance, image_id)
#... | level = CONF.xenserver.image_compression_level
if level is not None and (level < 1 or level > 9):
LOG.warning("Invalid value '%d' for image_compression_level", level)
return None
return level
def _fetch_vhd_image(context, session, instance, image_id, image_handler):
| 72 | 72 | 241 | 18 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _fetch_vhd_image | _fetch_vhd_image | 1,388 | 1,413 | 1,388 | 1,388 | c12b4779d444d56243b516f2340cc6c77ed3f890 | bigcode/the-stack | train |
f6ca84360ec27e30e496829a | train | function | def lookup(session, name_label, check_rescue=False):
"""Look the instance up and return it if available.
:param:check_rescue: if True will return the 'name'-rescue vm if it
exists, instead of just 'name'
"""
if check_rescue:
result = lookup(session, name_label + '-rescue', False)
if ... | def lookup(session, name_label, check_rescue=False):
| """Look the instance up and return it if available.
:param:check_rescue: if True will return the 'name'-rescue vm if it
exists, instead of just 'name'
"""
if check_rescue:
result = lookup(session, name_label + '-rescue', False)
if result:
return result
vm_refs = sessi... | _other_config.get('osvol'):
# This is not an attached volume
vdi_refs.append(vdi_ref)
except session.XenAPI.Failure:
LOG.exception(_('"Look for the VDIs failed'))
return vdi_refs
def lookup(session, name_label, check_rescue=False):
| 64 | 64 | 149 | 12 | 51 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | lookup | lookup | 1,636 | 1,652 | 1,636 | 1,636 | 2aab03cf21aa852764e906baba97560f7fd2acc9 | bigcode/the-stack | train |
175eeae70ecac5bc0759a960 | train | function | def _get_resize_func_name(session):
brand = session.product_brand
version = session.product_version
# To maintain backwards compatibility. All recent versions
# should use VDI.resize
if version and brand:
xcp = brand == 'XCP'
r1_2_or_above = (version[0] == 1 and version[1] > 1) or v... | def _get_resize_func_name(session):
| brand = session.product_brand
version = session.product_version
# To maintain backwards compatibility. All recent versions
# should use VDI.resize
if version and brand:
xcp = brand == 'XCP'
r1_2_or_above = (version[0] == 1 and version[1] > 1) or version[0] > 1
xenserver = b... | .get_all_records_where", expr)
number_found = len(recs)
if number_found > 0:
if number_found > 1:
LOG.warning("Multiple base images for image: %s", image_id)
return list(recs.keys())[0]
def _get_resize_func_name(session):
| 64 | 64 | 161 | 8 | 56 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_resize_func_name | _get_resize_func_name | 831 | 847 | 831 | 831 | 500cdf5f3803b4553c86d12c0bd4eafac305f64e | bigcode/the-stack | train |
fe7793e08e848f524fbe5a9f | train | function | def _get_partitions(dev):
return nova.privsep.fs.list_partitions(utils.make_dev_path(dev))
| def _get_partitions(dev):
| return nova.privsep.fs.list_partitions(utils.make_dev_path(dev))
| enapi.xenstore_read(
'/local/domain/%s/vm' % domid.strip())
return vm_key.strip()[4:]
def _get_this_vm_ref(session):
return session.call_xenapi("VM.get_by_uuid", get_this_vm_uuid(session))
def _get_partitions(dev):
| 64 | 64 | 23 | 7 | 57 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_partitions | _get_partitions | 2,245 | 2,246 | 2,245 | 2,245 | 48ee5b8504054770b90f5fe904d138c5a1e08163 | bigcode/the-stack | train |
592b73027d329935f0e70a22 | train | function | def _get_rrd_server():
"""Return server's scheme and address to use for retrieving RRD XMLs."""
xs_url = urlparse.urlparse(CONF.xenserver.connection_url)
return [xs_url.scheme, xs_url.netloc]
| def _get_rrd_server():
| """Return server's scheme and address to use for retrieving RRD XMLs."""
xs_url = urlparse.urlparse(CONF.xenserver.connection_url)
return [xs_url.scheme, xs_url.netloc]
| want %(pbd_rec)s, have %(host)s",
{'pbd_rec': pbd_rec, 'host': host})
if pbd_rec_host == host:
LOG.debug("ISO: SR with local PBD")
return sr_ref
return None
def _get_rrd_server():
| 64 | 64 | 52 | 7 | 56 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_rrd_server | _get_rrd_server | 1,945 | 1,948 | 1,945 | 1,945 | a8934c0fd05a71aac3be2c27766e7d64cd017c83 | bigcode/the-stack | train |
190234d6079c0b3bb1c06a8e | train | function | def ensure_correct_host(session):
"""Ensure we're connected to the host we're running on. This is the
required configuration for anything that uses vdi_attached without
the dom0 flag.
"""
if session.host_checked:
return
this_vm_uuid = get_this_vm_uuid(session)
try:
session.... | def ensure_correct_host(session):
| """Ensure we're connected to the host we're running on. This is the
required configuration for anything that uses vdi_attached without
the dom0 flag.
"""
if session.host_checked:
return
this_vm_uuid = get_this_vm_uuid(session)
try:
session.call_xenapi('VM.get_by_uuid', this... | .inject_data_into_fs(vfs,
key, net, metadata, None, None)
finally:
nova.privsep.fs.umount(dev_path)
else:
LOG.info('Failed to mount filesystem (expected for '
'non-linux instances): %s', err)
def ensure_cor... | 64 | 64 | 136 | 6 | 58 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | ensure_correct_host | ensure_correct_host | 2,440 | 2,457 | 2,440 | 2,440 | 7938d196ab2691d770293d6bd766bbc8db25870a | bigcode/the-stack | train |
0d0b9a9119ce2d3c14458400 | train | function | def list_vms(session):
vms = session.call_xenapi("VM.get_all_records_where",
'field "is_control_domain"="false" and '
'field "is_a_template"="false" and '
'field "resident_on"="%s"' % session.host_ref)
for vm_ref in vms.ke... | def list_vms(session):
| vms = session.call_xenapi("VM.get_all_records_where",
'field "is_control_domain"="false" and '
'field "is_a_template"="false" and '
'field "resident_on"="%s"' % session.host_ref)
for vm_ref in vms.keys():
yield vm_... | _fields.VMMode.XEN
# most images run OK as HVM
return obj_fields.VMMode.HVM
def set_vm_name_label(session, vm_ref, name_label):
session.call_xenapi("VM.set_name_label", vm_ref, name_label)
def list_vms(session):
| 64 | 64 | 83 | 6 | 58 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | list_vms | list_vms | 1,604 | 1,610 | 1,604 | 1,604 | 258d796ba3af69350f07073466bbbf3ed6897617 | bigcode/the-stack | train |
c54b73eddaf306457a757c7e | train | function | def _count_children(session, parent_vdi_uuid, sr_ref):
# Search for any other vdi which has the same parent as us to work out
# whether we have siblings and therefore if coalesce is possible
children = 0
for _ref, rec in _get_all_vdis_in_sr(session, sr_ref):
if (rec['sm_config'].get('vhd-parent'... | def _count_children(session, parent_vdi_uuid, sr_ref):
# Search for any other vdi which has the same parent as us to work out
# whether we have siblings and therefore if coalesce is possible
| children = 0
for _ref, rec in _get_all_vdis_in_sr(session, sr_ref):
if (rec['sm_config'].get('vhd-parent') == parent_vdi_uuid):
children = children + 1
return children
| _snapshot(rec):
continue
children.add(rec_uuid)
return list(children)
def _count_children(session, parent_vdi_uuid, sr_ref):
# Search for any other vdi which has the same parent as us to work out
# whether we have siblings and therefore if coalesce is possible
| 64 | 64 | 104 | 47 | 17 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _count_children | _count_children | 2,048 | 2,055 | 2,048 | 2,050 | d0867ea574b20a1c542e0108610a63cd38deaf35 | bigcode/the-stack | train |
23bac971720ac4fe6a206752 | train | function | def destroy_vdi(session, vdi_ref):
try:
session.call_xenapi('VDI.destroy', vdi_ref)
except session.XenAPI.Failure:
LOG.debug("Unable to destroy VDI %s", vdi_ref, exc_info=True)
msg = _("Unable to destroy VDI %s") % vdi_ref
LOG.error(msg)
raise exception.StorageError(reaso... | def destroy_vdi(session, vdi_ref):
| try:
session.call_xenapi('VDI.destroy', vdi_ref)
except session.XenAPI.Failure:
LOG.debug("Unable to destroy VDI %s", vdi_ref, exc_info=True)
msg = _("Unable to destroy VDI %s") % vdi_ref
LOG.error(msg)
raise exception.StorageError(reason=msg)
| userdevice,
vbd_type='cd', read_only=True,
bootable=True, empty=True,
unpluggable=False)
session.call_xenapi('VBD.insert', vbd_ref, vdi_ref)
return vbd_ref
def destroy_vdi(session, vdi_ref):
| 64 | 64 | 88 | 10 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | destroy_vdi | destroy_vdi | 429 | 436 | 429 | 429 | 1e81688f0d8e5ffe9e17bd09c379fe09381abc58 | bigcode/the-stack | train |
ef3fe7a749ddab145ad57d32 | train | function | def _vdi_get_rec(session, vdi_ref):
return session.call_xenapi("VDI.get_record", vdi_ref)
| def _vdi_get_rec(session, vdi_ref):
| return session.call_xenapi("VDI.get_record", vdi_ref)
| _refs(session, vm_ref):
return session.call_xenapi("VM.get_VBDs", vm_ref)
def _vbd_get_rec(session, vbd_ref):
return session.call_xenapi("VBD.get_record", vbd_ref)
def _vdi_get_rec(session, vdi_ref):
| 64 | 64 | 29 | 12 | 52 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vdi_get_rec | _vdi_get_rec | 572 | 573 | 572 | 572 | c5c641ab753fc7d43a4965bc757928abfd7b1c98 | bigcode/the-stack | train |
6d0d9bbe7f225fe266c3119c | train | function | def _hypervisor_supports_device_id(version):
version_as_string = '.'.join(str(v) for v in version)
return versionutils.is_compatible('6.1', version_as_string)
| def _hypervisor_supports_device_id(version):
| version_as_string = '.'.join(str(v) for v in version)
return versionutils.is_compatible('6.1', version_as_string)
| return device_id
else:
msg = _("Device id %(id)s specified is not supported by "
"hypervisor version %(version)s") % {'id': device_id,
'version': hypervisor_version}
raise exception.NovaException(msg)
def _hypervisor_supports_device_id(version):
| 64 | 64 | 42 | 10 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _hypervisor_supports_device_id | _hypervisor_supports_device_id | 163 | 165 | 163 | 163 | 8be73eac827967ab8593e4520a98829f31d01a2f | bigcode/the-stack | train |
0661903479125b4f886d1983 | train | function | def _is_vdi_a_snapshot(vdi_rec):
"""Ensure VDI is a snapshot, and not cached image."""
is_a_snapshot = vdi_rec['is_a_snapshot']
image_id = vdi_rec['other_config'].get('image-id')
return is_a_snapshot and not image_id
| def _is_vdi_a_snapshot(vdi_rec):
| """Ensure VDI is a snapshot, and not cached image."""
is_a_snapshot = vdi_rec['is_a_snapshot']
image_id = vdi_rec['other_config'].get('image-id')
return is_a_snapshot and not image_id
| ("VDI.get_record", vdi_ref)
yield vdi_rec
parent_uuid = _get_vhd_parent_uuid(session, vdi_ref, vdi_rec)
if not parent_uuid:
break
vdi_uuid = parent_uuid
def _is_vdi_a_snapshot(vdi_rec):
| 64 | 64 | 64 | 11 | 52 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _is_vdi_a_snapshot | _is_vdi_a_snapshot | 2,017 | 2,021 | 2,017 | 2,017 | fd604606bc6e4160763074c6075643bc4f492ef9 | bigcode/the-stack | train |
ec69d5aea2501f2c119676ee | train | function | def create_vm(session, instance, name_label, kernel, ramdisk,
use_pv_kernel=False, device_id=None):
"""Create a VM record. Returns new VM reference.
the use_pv_kernel flag indicates whether the guest is HVM or PV
There are 3 scenarios:
1. Using paravirtualization, kernel passed in
... | def create_vm(session, instance, name_label, kernel, ramdisk,
use_pv_kernel=False, device_id=None):
| """Create a VM record. Returns new VM reference.
the use_pv_kernel flag indicates whether the guest is HVM or PV
There are 3 scenarios:
1. Using paravirtualization, kernel passed in
2. Using paravirtualization, kernel within the image
3. Using hardware virtualization
"""
... | (image_type_id)
def get_vm_device_id(session, image_meta):
# NOTE: device_id should be 2 for windows VMs which run new xentools
# (>=6.1). Refer to http://support.citrix.com/article/CTX135099 for more
# information.
device_id = image_meta.properties.get('hw_device_id')
# The device_id is required... | 249 | 249 | 833 | 26 | 223 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | create_vm | create_vm | 168 | 259 | 168 | 169 | 53d1a2c3651ebc3494d3a2604a1f8014fe3e58e2 | bigcode/the-stack | train |
0e02e2b4861d463c00b46799 | train | function | def _vbd_get_rec(session, vbd_ref):
return session.call_xenapi("VBD.get_record", vbd_ref)
| def _vbd_get_rec(session, vbd_ref):
| return session.call_xenapi("VBD.get_record", vbd_ref)
| session.call_xenapi(
"VDI.add_to_other_config", vdi_ref, key, value)
def _vm_get_vbd_refs(session, vm_ref):
return session.call_xenapi("VM.get_VBDs", vm_ref)
def _vbd_get_rec(session, vbd_ref):
| 64 | 64 | 29 | 12 | 52 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vbd_get_rec | _vbd_get_rec | 568 | 569 | 568 | 568 | 2aa8dedf67c26c962976b883a6f9b1fa803f6c6e | bigcode/the-stack | train |
dc2bae9b4c8e76862726b8d9 | train | function | def cleanup_attached_vdis(session):
"""Unplug any instance VDIs left after an unclean restart."""
this_vm_ref = _get_this_vm_ref(session)
vbd_refs = session.call_xenapi('VM.get_VBDs', this_vm_ref)
for vbd_ref in vbd_refs:
try:
vdi_ref = session.call_xenapi('VBD.get_VDI', vbd_ref)
... | def cleanup_attached_vdis(session):
| """Unplug any instance VDIs left after an unclean restart."""
this_vm_ref = _get_this_vm_ref(session)
vbd_refs = session.call_xenapi('VM.get_VBDs', this_vm_ref)
for vbd_ref in vbd_refs:
try:
vdi_ref = session.call_xenapi('VBD.get_VDI', vbd_ref)
vdi_rec = session.call_xen... | , max_seconds):
if os.path.exists(dev_path):
found_path = dev_path
break
time.sleep(1)
if found_path is None:
raise exception.StorageError(
reason=_('Timeout waiting for device %s to be created') % dev)
def cleanup_attached_vdis(session):
| 66 | 66 | 221 | 8 | 58 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | cleanup_attached_vdis | cleanup_attached_vdis | 2,139 | 2,159 | 2,139 | 2,139 | e5dab9853f58988f457f01e3d1a0c22475aa46cb | bigcode/the-stack | train |
5af2193f40323da40288dd9c | train | function | def _vm_query_data_source(session, *args):
"""We're getting diagnostics stats from the RRDs which are updated every
5 seconds. It means that diagnostics information may be incomplete during
first 5 seconds of VM life. In such cases method ``query_data_source()``
may raise a ``XenAPI.Failure`` exception ... | def _vm_query_data_source(session, *args):
| """We're getting diagnostics stats from the RRDs which are updated every
5 seconds. It means that diagnostics information may be incomplete during
first 5 seconds of VM life. In such cases method ``query_data_source()``
may raise a ``XenAPI.Failure`` exception or may return a `NaN` value.
"""
t... | vm_rec['is_a_snapshot']
else:
return False
def get_power_state(session, vm_ref):
xapi_state = session.call_xenapi("VM.get_power_state", vm_ref)
return XENAPI_POWER_STATE[xapi_state]
def _vm_query_data_source(session, *args):
| 64 | 64 | 127 | 11 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vm_query_data_source | _vm_query_data_source | 1,694 | 1,708 | 1,694 | 1,694 | e3b2b79d2af7e1903397ab8104f53ed2377b9e1b | bigcode/the-stack | train |
225540d5bec33cc1ed5595e5 | train | function | def _get_vdi_chain_size(session, vdi_uuid):
"""Compute the total size of a VDI chain, starting with the specified
VDI UUID.
This will walk the VDI chain to the root, add the size of each VDI into
the total.
"""
size_bytes = 0
for vdi_rec in _walk_vdi_chain(session, vdi_uuid):
cur_vd... | def _get_vdi_chain_size(session, vdi_uuid):
| """Compute the total size of a VDI chain, starting with the specified
VDI UUID.
This will walk the VDI chain to the root, add the size of each VDI into
the total.
"""
size_bytes = 0
for vdi_rec in _walk_vdi_chain(session, vdi_uuid):
cur_vdi_uuid = vdi_rec['uuid']
vdi_size_by... | dis.values():
vdi_uuid = vdi['uuid']
vdi_ref = session.call_xenapi('VDI.get_by_uuid', vdi_uuid)
safe_destroy_vdis(session, [vdi_ref])
return vdis
def _get_vdi_chain_size(session, vdi_uuid):
| 64 | 64 | 180 | 13 | 50 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_vdi_chain_size | _get_vdi_chain_size | 1,416 | 1,432 | 1,416 | 1,416 | a7fcc29a98b0a2ee654565bad59768147ce29336 | bigcode/the-stack | train |
2ec8171505157503b9e2b2ad | train | function | def _wait_for_vhd_coalesce(session, instance, sr_ref, vdi_ref,
vdi_uuid_list):
"""Spin until the parent VHD is coalesced into one of the VDIs in the list
vdi_uuid_list is a list of acceptable final parent VDIs for vdi_ref; once
the parent of vdi_ref is in vdi_uuid_chain we consid... | def _wait_for_vhd_coalesce(session, instance, sr_ref, vdi_ref,
vdi_uuid_list):
| """Spin until the parent VHD is coalesced into one of the VDIs in the list
vdi_uuid_list is a list of acceptable final parent VDIs for vdi_ref; once
the parent of vdi_ref is in vdi_uuid_chain we consider the coalesce over.
The use case is there are any number of VDIs between those in
vdi_uuid_list... | rec_uuid = rec['uuid']
if rec_uuid in vdi_uuid_list:
continue
parent_uuid = _get_vhd_parent_uuid(session, ref, rec)
if parent_uuid not in vdi_uuid_list:
continue
if old_snapshots_only and not _is_vdi_a_snapshot(rec):
continue
children.add(... | 209 | 209 | 699 | 25 | 183 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _wait_for_vhd_coalesce | _wait_for_vhd_coalesce | 2,058 | 2,117 | 2,058 | 2,059 | b30330d05db916c94db66863a7c0909634fd5130 | bigcode/the-stack | train |
cc762b5087461386bd158200 | train | function | def _get_image_vdi_label(image_id):
return 'Glance Image %s' % image_id
| def _get_image_vdi_label(image_id):
| return 'Glance Image %s' % image_id
| kernel, ramdisk):
if kernel or ramdisk:
LOG.debug("Removing kernel/ramdisk files from dom0",
instance=instance)
disk_management.remove_kernel_ramdisk(
session, kernel_file=kernel, ramdisk_file=ramdisk)
def _get_image_vdi_label(image_id):
| 64 | 64 | 23 | 10 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_image_vdi_label | _get_image_vdi_label | 1,225 | 1,226 | 1,225 | 1,225 | a956a5212e9f3f14e9a129999a828abbcf7237a0 | bigcode/the-stack | train |
da6e60fd41285ae4be9d5686 | train | function | def safe_find_sr(session):
"""Same as _find_sr except raises a NotFound exception if SR cannot be
determined
"""
sr_ref = _find_sr(session)
if sr_ref is None:
raise exception.StorageRepositoryNotFound()
return sr_ref
| def safe_find_sr(session):
| """Same as _find_sr except raises a NotFound exception if SR cannot be
determined
"""
sr_ref = _find_sr(session)
if sr_ref is None:
raise exception.StorageRepositoryNotFound()
return sr_ref
| attempt)
attempt += 1
do_scan(sr_ref)
def scan_default_sr(session):
"""Looks for the system default SR and triggers a re-scan."""
sr_ref = safe_find_sr(session)
_scan_sr(session, sr_ref)
return sr_ref
def safe_find_sr(session):
| 64 | 64 | 58 | 6 | 57 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | safe_find_sr | safe_find_sr | 1,856 | 1,863 | 1,856 | 1,856 | 014f0319b7ad2ece7ca9672440893f601f5fdd49 | bigcode/the-stack | train |
2a8d4c0642e5afee8b1a00aa | train | function | def handle_ipxe_iso(session, instance, cd_vdi, network_info):
"""iPXE ISOs are a mechanism to allow the customer to roll their own
image.
To use this feature, a service provider needs to configure the
appropriate Nova flags, roll an iPXE ISO, then distribute that image
to customers via Glance.
... | def handle_ipxe_iso(session, instance, cd_vdi, network_info):
| """iPXE ISOs are a mechanism to allow the customer to roll their own
image.
To use this feature, a service provider needs to configure the
appropriate Nova flags, roll an iPXE ISO, then distribute that image
to customers via Glance.
NOTE: `mkisofs` is not present by default in the Dom0, so the... | if ephemeral_number:
chain_label = instance['uuid'] + "_ephemeral_%d" % ephemeral_number
try:
vm_management.transfer_vhd(session, chain_label, dest, vdi_uuid,
sr_path, seq_num)
except session.XenAPI.Failure:
msg = "Failed to transfer vhd to new host"
... | 155 | 155 | 519 | 16 | 138 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | handle_ipxe_iso | handle_ipxe_iso | 2,536 | 2,595 | 2,536 | 2,536 | 26ce1358c806a3b403da93b4056173943e6b30d4 | bigcode/the-stack | train |
9f39e5db1a33196b1b0fc032 | train | function | def _mount_filesystem(dev_path, mount_point):
"""mounts the device specified by dev_path in mount_point."""
try:
_out, err = nova.privsep.fs.mount('ext2,ext3,ext4,reiserfs',
dev_path, mount_point, None)
except processutils.ProcessExecutionError as e:
... | def _mount_filesystem(dev_path, mount_point):
| """mounts the device specified by dev_path in mount_point."""
try:
_out, err = nova.privsep.fs.mount('ext2,ext3,ext4,reiserfs',
dev_path, mount_point, None)
except processutils.ProcessExecutionError as e:
err = six.text_type(e)
return err
| _sparse_copy(src_path, dst_path, virtual_size)
else:
num_blocks = virtual_size / SECTOR_SIZE
nova.privsep.xenapi.block_copy(
src_path, dst_path, DD_BLOCKSIZE, num_blocks)
def _mount_filesystem(dev_path, mount_point):
| 64 | 64 | 84 | 11 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _mount_filesystem | _mount_filesystem | 2,397 | 2,404 | 2,397 | 2,397 | 3b1972228bbc9a383f7b5964ebb2b9c088d6189e | bigcode/the-stack | train |
80ecef9ee5fc3f3915e6eb78 | train | function | def remove_old_snapshots(session, instance, vm_ref):
"""See if there is an snapshot present that should be removed."""
LOG.debug("Starting remove_old_snapshots for VM", instance=instance)
vm_vdi_ref, vm_vdi_rec = get_vdi_for_vm_safely(session, vm_ref)
chain = _walk_vdi_chain(session, vm_vdi_rec['uuid'])... | def remove_old_snapshots(session, instance, vm_ref):
| """See if there is an snapshot present that should be removed."""
LOG.debug("Starting remove_old_snapshots for VM", instance=instance)
vm_vdi_ref, vm_vdi_rec = get_vdi_for_vm_safely(session, vm_ref)
chain = _walk_vdi_chain(session, vm_vdi_rec['uuid'])
vdi_uuid_chain = [vdi_rec['uuid'] for vdi_rec in... | snapshot_uuids]
safe_destroy_vdis(session, vdi_refs)
# ensure garbage collector has been run
_scan_sr(session, sr_ref)
LOG.info("Deleted %s snapshots.", number_of_snapshots, instance=instance)
def remove_old_snapshots(session, instance, vm_ref):
| 64 | 64 | 135 | 12 | 52 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | remove_old_snapshots | remove_old_snapshots | 647 | 654 | 647 | 647 | 75d2277eded52300e48dec7fa3dcf26d312845fb | bigcode/the-stack | train |
f7e67e1c8accde45cdb8b012 | train | function | def _log_progress_if_required(left, last_log_time, virtual_size):
if timeutils.is_older_than(last_log_time, PROGRESS_INTERVAL_SECONDS):
last_log_time = timeutils.utcnow()
complete_pct = float(virtual_size - left) / virtual_size * 100
LOG.debug("Sparse copy in progress, "
"%... | def _log_progress_if_required(left, last_log_time, virtual_size):
| if timeutils.is_older_than(last_log_time, PROGRESS_INTERVAL_SECONDS):
last_log_time = timeutils.utcnow()
complete_pct = float(virtual_size - left) / virtual_size * 100
LOG.debug("Sparse copy in progress, "
"%(complete_pct).2f%% complete. "
"%(left)s bytes ... | :
# Resizing up, resize filesystem after partition resize
nova.privsep.fs.resize2fs(partition_path, [0])
# Add back journal
nova.privsep.fs.ext_journal_enable(partition_path)
def _log_progress_if_required(left, last_log_time, virtual_size):
| 64 | 64 | 110 | 15 | 49 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _log_progress_if_required | _log_progress_if_required | 2,317 | 2,325 | 2,317 | 2,317 | 8e1d1bdd8eb2b5ac45accd67d5e33398c1014ed0 | bigcode/the-stack | train |
6067016079496962ddb5ed83 | train | function | def _make_partition(session, dev, partition_start, partition_end):
dev_path = utils.make_dev_path(dev)
# NOTE(bobball) If this runs in Dom0, parted will error trying
# to re-read the partition table and return a generic error
nova.privsep.fs.create_partition_table(
dev_path, 'msdos', check_exit... | def _make_partition(session, dev, partition_start, partition_end):
| dev_path = utils.make_dev_path(dev)
# NOTE(bobball) If this runs in Dom0, parted will error trying
# to re-read the partition table and return a generic error
nova.privsep.fs.create_partition_table(
dev_path, 'msdos', check_exit_code=not session.is_local_connection)
nova.privsep.fs.create_p... | server.independent_compute')
try:
_auto_configure_disk(session, vdi_ref, new_gb)
except exception.CannotResizeDisk as e:
LOG.warning('Attempted auto_configure_disk failed because: %s', e)
def _make_partition(session, dev, partition_start, partition_end):
| 66 | 66 | 221 | 14 | 52 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _make_partition | _make_partition | 976 | 998 | 976 | 976 | 853edc73527375fbbafa84a8488d76ab236102e7 | bigcode/the-stack | train |
f30dad98ab411773f50380e7 | train | function | def _vdi_snapshot(session, vdi_ref):
return session.call_xenapi("VDI.snapshot", vdi_ref, {})
| def _vdi_snapshot(session, vdi_ref):
| return session.call_xenapi("VDI.snapshot", vdi_ref, {})
| _rec(session, vdi_ref):
return session.call_xenapi("VDI.get_record", vdi_ref)
def _vdi_get_uuid(session, vdi_ref):
return session.call_xenapi("VDI.get_uuid", vdi_ref)
def _vdi_snapshot(session, vdi_ref):
| 64 | 64 | 28 | 11 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vdi_snapshot | _vdi_snapshot | 580 | 581 | 580 | 580 | b8e84a3e431397a23052ed3be24a3e2ac0c642ee | bigcode/the-stack | train |
c82e15260d9505764ba93713 | train | function | def get_instance_vdis_for_sr(session, vm_ref, sr_ref):
"""Return opaqueRef for all the vdis which live on sr."""
for vbd_ref in session.call_xenapi('VM.get_VBDs', vm_ref):
try:
vdi_ref = session.call_xenapi('VBD.get_VDI', vbd_ref)
if sr_ref == session.call_xenapi('VDI.get_SR', vd... | def get_instance_vdis_for_sr(session, vm_ref, sr_ref):
| """Return opaqueRef for all the vdis which live on sr."""
for vbd_ref in session.call_xenapi('VM.get_VBDs', vm_ref):
try:
vdi_ref = session.call_xenapi('VBD.get_VDI', vbd_ref)
if sr_ref == session.call_xenapi('VDI.get_SR', vdi_ref):
yield vdi_ref
except se... | vdi_ref)
# Check to make sure the record still exists. It may have
# been deleted between the get_all call and get_rec call
if vdi_rec:
yield vdi_ref, vdi_rec
def get_instance_vdis_for_sr(session, vm_ref, sr_ref):
| 64 | 64 | 113 | 15 | 48 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | get_instance_vdis_for_sr | get_instance_vdis_for_sr | 1,977 | 1,985 | 1,977 | 1,977 | 364c7ee976d2af3be34173b05cdf8cb5b48cc1e6 | bigcode/the-stack | train |
7d36fc6bc40c881958c8db3a | train | function | def is_snapshot(session, vm):
vm_rec = session.call_xenapi("VM.get_record", vm)
if 'is_a_template' in vm_rec and 'is_a_snapshot' in vm_rec:
return vm_rec['is_a_template'] and vm_rec['is_a_snapshot']
else:
return False
| def is_snapshot(session, vm):
| vm_rec = session.call_xenapi("VM.get_record", vm)
if 'is_a_template' in vm_rec and 'is_a_snapshot' in vm_rec:
return vm_rec['is_a_template'] and vm_rec['is_a_snapshot']
else:
return False
| session.call_xenapi("VM.get_record", vm)
if 'PV_kernel' in vm_rec and 'PV_ramdisk' in vm_rec:
return (vm_rec['PV_kernel'], vm_rec['PV_ramdisk'])
else:
return (None, None)
def is_snapshot(session, vm):
| 64 | 64 | 67 | 7 | 57 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | is_snapshot | is_snapshot | 1,681 | 1,686 | 1,681 | 1,681 | d75225c6c323db149dc5ad552c232b93df0c57e3 | bigcode/the-stack | train |
6372ee827243e964a7d48431 | train | function | def _check_vdi_size(context, session, instance, vdi_uuid):
flavor = instance.get_flavor()
allowed_size = (flavor.root_gb +
VHD_SIZE_CHECK_FUDGE_FACTOR_GB) * units.Gi
if not flavor.root_gb:
# root_gb=0 indicates that we're disabling size checks
return
size = _get_vdi_... | def _check_vdi_size(context, session, instance, vdi_uuid):
| flavor = instance.get_flavor()
allowed_size = (flavor.root_gb +
VHD_SIZE_CHECK_FUDGE_FACTOR_GB) * units.Gi
if not flavor.root_gb:
# root_gb=0 indicates that we're disabling size checks
return
size = _get_vdi_chain_size(session, vdi_uuid)
if size > allowed_size:
... |
'%(vdi_size_bytes)d',
{'cur_vdi_uuid': cur_vdi_uuid,
'vdi_size_bytes': vdi_size_bytes})
size_bytes += vdi_size_bytes
return size_bytes
def _check_vdi_size(context, session, instance, vdi_uuid):
| 64 | 64 | 172 | 16 | 47 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _check_vdi_size | _check_vdi_size | 1,435 | 1,452 | 1,435 | 1,435 | a8dde318b5c99f0c9efca887fc73e1c63b92ffb3 | bigcode/the-stack | train |
f04be3cd9164e29a3cbd8573 | train | function | @contextlib.contextmanager
def _dummy_vm(session, instance, vdi_ref):
"""This creates a temporary VM so that we can snapshot a VDI.
VDI's can't be snapshotted directly since the API expects a `vm_ref`. To
work around this, we need to create a temporary VM and then map the VDI to
the VM using a temporar... | @contextlib.contextmanager
def _dummy_vm(session, instance, vdi_ref):
| """This creates a temporary VM so that we can snapshot a VDI.
VDI's can't be snapshotted directly since the API expects a `vm_ref`. To
work around this, we need to create a temporary VM and then map the VDI to
the VM using a temporary VBD.
"""
name_label = "dummy"
vm_ref = create_vm(session... | {'vdi_ref': vdi_ref, 'name_label': name_label,
'virtual_size': virtual_size, 'read_only': read_only,
'sr_ref': sr_ref})
return vdi_ref
@contextlib.contextmanager
def _dummy_vm(session, instance, vdi_ref):
| 64 | 64 | 196 | 18 | 45 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _dummy_vm | _dummy_vm | 471 | 493 | 471 | 472 | dd6ecbc9eaf840b94e900b1dff0e405e3b1193c6 | bigcode/the-stack | train |
b59b5cab7d137a8017898969 | train | function | def _get_vdi_other_config(disk_type, instance=None):
"""Return metadata to store in VDI's other_config attribute.
`nova_instance_uuid` is used to associate a VDI with a particular instance
so that, if it becomes orphaned from an unclean shutdown of a
compute-worker, we can safely detach it.
"""
... | def _get_vdi_other_config(disk_type, instance=None):
| """Return metadata to store in VDI's other_config attribute.
`nova_instance_uuid` is used to associate a VDI with a particular instance
so that, if it becomes orphaned from an unclean shutdown of a
compute-worker, we can safely detach it.
"""
other_config = {'nova_disk_type': disk_type}
# ... | VDI %(vdi_ref)s from VDI '
'%(vdi_to_clone_ref)s',
{'vdi_ref': vdi_ref, 'vdi_to_clone_ref': vdi_to_clone_ref})
return vdi_ref
def _get_vdi_other_config(disk_type, instance=None):
| 64 | 64 | 136 | 14 | 49 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_vdi_other_config | _get_vdi_other_config | 532 | 546 | 532 | 532 | a0c03889d4c02cbd4241da7b983e7a95f3eb4415 | bigcode/the-stack | train |
278c7dcad22e1a5f85b34a7b | train | function | def get_all_vdi_uuids_for_vm(session, vm_ref, min_userdevice=0):
vbd_refs = _vm_get_vbd_refs(session, vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = _vbd_get_rec(session, vbd_ref)
if int(vbd_rec['userdevice']) >= min_userdevice:
vdi_ref = vbd_rec['VDI']
yield _vdi_get_uuid(se... | def get_all_vdi_uuids_for_vm(session, vm_ref, min_userdevice=0):
| vbd_refs = _vm_get_vbd_refs(session, vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = _vbd_get_rec(session, vbd_ref)
if int(vbd_rec['userdevice']) >= min_userdevice:
vdi_ref = vbd_rec['VDI']
yield _vdi_get_uuid(session, vdi_ref)
| _rec = _vdi_get_rec(session, vdi_ref)
return vdi_ref, vdi_rec
raise exception.NovaException(_("No primary VDI found for %s") % vm_ref)
def get_all_vdi_uuids_for_vm(session, vm_ref, min_userdevice=0):
| 64 | 64 | 103 | 21 | 43 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | get_all_vdi_uuids_for_vm | get_all_vdi_uuids_for_vm | 597 | 603 | 597 | 597 | 6636c7476a084ed1f2b319b14de759189f491b8c | bigcode/the-stack | train |
bb08b426960e320dc7ab7ec2 | train | function | def _child_vhds(session, sr_ref, vdi_uuid_list, old_snapshots_only=False):
"""Return the immediate children of a given VHD.
This is not recursive, only the immediate children are returned.
"""
children = set()
for ref, rec in _get_all_vdis_in_sr(session, sr_ref):
rec_uuid = rec['uuid']
... | def _child_vhds(session, sr_ref, vdi_uuid_list, old_snapshots_only=False):
| """Return the immediate children of a given VHD.
This is not recursive, only the immediate children are returned.
"""
children = set()
for ref, rec in _get_all_vdis_in_sr(session, sr_ref):
rec_uuid = rec['uuid']
if rec_uuid in vdi_uuid_list:
continue
parent_uui... | cached image."""
is_a_snapshot = vdi_rec['is_a_snapshot']
image_id = vdi_rec['other_config'].get('image-id')
return is_a_snapshot and not image_id
def _child_vhds(session, sr_ref, vdi_uuid_list, old_snapshots_only=False):
| 64 | 64 | 153 | 22 | 41 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _child_vhds | _child_vhds | 2,024 | 2,045 | 2,024 | 2,024 | add7de0d310096563e6d75116e596a94fc8c53c2 | bigcode/the-stack | train |
18d3ffdceaba17da9a4c39bd | train | function | def get_compression_level():
level = CONF.xenserver.image_compression_level
if level is not None and (level < 1 or level > 9):
LOG.warning("Invalid value '%d' for image_compression_level", level)
return None
return level
| def get_compression_level():
| level = CONF.xenserver.image_compression_level
if level is not None and (level < 1 or level > 9):
LOG.warning("Invalid value '%d' for image_compression_level", level)
return None
return level
| does not have the `uuid` module. To work around this,
# we generate the uuids here (under Python 2.6+) and
# pass them as arguments
return [uuidutils.generate_uuid() for i in range(MAX_VDI_CHAIN_SIZE)]
def get_compression_level():
| 63 | 64 | 61 | 6 | 57 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | get_compression_level | get_compression_level | 1,380 | 1,385 | 1,380 | 1,380 | 24e34475d0d8623b6e63fa50208e38549d2247e4 | bigcode/the-stack | train |
3ed4dd7126a35f3d87eaeb81 | train | function | def _add_nic_usage(session, vm_ref, diag_obj):
vif_refs = session.VM.get_VIFs(vm_ref)
for vif_ref in vif_refs:
vif_rec = session.VIF.get_record(vif_ref)
rx_rate = _vm_query_data_source(session, vm_ref,
"vif_%s_rx" % vif_rec['device'])
tx_rate = _vm... | def _add_nic_usage(session, vm_ref, diag_obj):
| vif_refs = session.VM.get_VIFs(vm_ref)
for vif_ref in vif_refs:
vif_rec = session.VIF.get_record(vif_ref)
rx_rate = _vm_query_data_source(session, vm_ref,
"vif_%s_rx" % vif_rec['device'])
tx_rate = _vm_query_data_source(session, vm_ref,
... | ):
utilisation = _vm_query_data_source(session, vm_ref, "cpu%d" % cpu_num)
if utilisation is not None:
utilisation *= 100
diag_obj.add_cpu(id=cpu_num, utilisation=utilisation)
def _add_nic_usage(session, vm_ref, diag_obj):
| 64 | 64 | 133 | 14 | 50 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _add_nic_usage | _add_nic_usage | 1,741 | 1,751 | 1,741 | 1,741 | a6c081b4bcb7b63124df934e4e046134c50914a9 | bigcode/the-stack | train |
8c6bf5add7b4e052a7fd946c | train | function | def unplug_vbd(session, vbd_ref, this_vm_ref):
# make sure that perform at least once
max_attempts = max(0, CONF.xenserver.num_vbd_unplug_retries) + 1
for num_attempt in range(1, max_attempts + 1):
try:
if num_attempt > 1:
greenthread.sleep(1)
session.VBD.unp... | def unplug_vbd(session, vbd_ref, this_vm_ref):
# make sure that perform at least once
| max_attempts = max(0, CONF.xenserver.num_vbd_unplug_retries) + 1
for num_attempt in range(1, max_attempts + 1):
try:
if num_attempt > 1:
greenthread.sleep(1)
session.VBD.unplug(vbd_ref, this_vm_ref)
return
except session.XenAPI.Failure as exc:... | VM booting, so retry if unplug failed
with VM_MISSING_PV_DRIVERS.
"""
can_retry_errs = (
'DEVICE_DETACH_REJECTED',
'INTERNAL_ERROR',
'VM_MISSING_PV_DRIVERS',
)
return err in can_retry_errs
def unplug_vbd(session, vbd_ref, this_vm_ref):
# make sure that perform at le... | 90 | 90 | 302 | 24 | 65 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | unplug_vbd | unplug_vbd | 344 | 372 | 344 | 345 | 0dee733373a8e494054d68780009b54f92a357d8 | bigcode/the-stack | train |
3d8916f5a15b0f02ad6a2f64 | train | function | def generate_iso_blank_root_disk(session, instance, vm_ref, userdevice,
name_label, size_gb):
_generate_disk(session, instance, vm_ref, userdevice, name_label,
'user', size_gb * 1024, CONF.default_ephemeral_format)
| def generate_iso_blank_root_disk(session, instance, vm_ref, userdevice,
name_label, size_gb):
| _generate_disk(session, instance, vm_ref, userdevice, name_label,
'user', size_gb * 1024, CONF.default_ephemeral_format)
| %(exc)s", {
'userdevice': userdevice,
'size_gb': size_gb,
'exc': exc})
safe_destroy_vdis(session, vdi_refs)
def generate_iso_blank_root_disk(session, instance, vm_ref, userdevice,
name_label... | 64 | 64 | 59 | 24 | 40 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | generate_iso_blank_root_disk | generate_iso_blank_root_disk | 1,132 | 1,135 | 1,132 | 1,133 | 6aa04ebc7faab7eccec74d9fa415341d82cea564 | bigcode/the-stack | train |
a4cc2ed72789eccf5a62c950 | train | function | def _resize_part_and_fs(dev, start, old_sectors, new_sectors, flags):
"""Resize partition and fileystem.
This assumes we are dealing with a single primary partition and using
ext3 or ext4.
"""
size = new_sectors - start
end = new_sectors - 1
dev_path = utils.make_dev_path(dev)
partitio... | def _resize_part_and_fs(dev, start, old_sectors, new_sectors, flags):
| """Resize partition and fileystem.
This assumes we are dealing with a single primary partition and using
ext3 or ext4.
"""
size = new_sectors - start
end = new_sectors - 1
dev_path = utils.make_dev_path(dev)
partition_path = utils.make_dev_path(dev, partition=1)
# Replay journal i... | .debug('Writing partition table %(primary_first)d %(primary_last)d'
' to %(dev_path)s...',
{'primary_first': primary_first, 'primary_last': primary_last,
'dev_path': dev_path})
_make_partition(session, dev, "%ds" % primary_first, "%ds" % primary_last)
LOG.debug('Writi... | 101 | 101 | 338 | 20 | 81 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _resize_part_and_fs | _resize_part_and_fs | 2,277 | 2,314 | 2,277 | 2,277 | 9a1eddd7f5e96e7d62ede80b28c6901e5c1d3c4f | bigcode/the-stack | train |
42cbaa9b4f28ef050980097f | train | function | def migrate_vhd(session, instance, vdi_uuid, dest, sr_path, seq_num,
ephemeral_number=0):
LOG.debug("Migrating VHD '%(vdi_uuid)s' with seq_num %(seq_num)d",
{'vdi_uuid': vdi_uuid, 'seq_num': seq_num},
instance=instance)
chain_label = instance['uuid']
if ephemeral_... | def migrate_vhd(session, instance, vdi_uuid, dest, sr_path, seq_num,
ephemeral_number=0):
| LOG.debug("Migrating VHD '%(vdi_uuid)s' with seq_num %(seq_num)d",
{'vdi_uuid': vdi_uuid, 'seq_num': seq_num},
instance=instance)
chain_label = instance['uuid']
if ephemeral_number:
chain_label = instance['uuid'] + "_ephemeral_%d" % ephemeral_number
try:
vm_ma... | _vdi_info(session, vdi_ref, disk_type, vdi_label,
disk_type, instance)
return {'uuid': vdi_uuid, 'ref': vdi_ref}
def migrate_vhd(session, instance, vdi_uuid, dest, sr_path, seq_num,
ephemeral_number=0):
| 64 | 64 | 175 | 26 | 38 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | migrate_vhd | migrate_vhd | 2,512 | 2,526 | 2,512 | 2,513 | 67e3fdb0a848517ae936b35599d53844888297a1 | bigcode/the-stack | train |
f4975b72cef4accae22b4e75 | train | function | def is_enough_free_mem(session, instance):
flavor = instance.get_flavor()
mem = int(flavor.memory_mb) * units.Mi
host_free_mem = int(session.call_xenapi("host.compute_free_memory",
session.host_ref))
return host_free_mem >= mem
| def is_enough_free_mem(session, instance):
| flavor = instance.get_flavor()
mem = int(flavor.memory_mb) * units.Mi
host_free_mem = int(session.call_xenapi("host.compute_free_memory",
session.host_ref))
return host_free_mem >= mem
| utting down VM (hard) failed'))
return False
return True
def is_vm_shutdown(session, vm_ref):
state = get_power_state(session, vm_ref)
if state == power_state.SHUTDOWN:
return True
return False
def is_enough_free_mem(session, instance):
| 64 | 64 | 62 | 10 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | is_enough_free_mem | is_enough_free_mem | 310 | 315 | 310 | 310 | ad6c4e088b629d3011e22df1a8b5a7c24dd01064 | bigcode/the-stack | train |
14d4687576f725f8b4c2de03 | train | function | def _vdi_get_uuid(session, vdi_ref):
return session.call_xenapi("VDI.get_uuid", vdi_ref)
| def _vdi_get_uuid(session, vdi_ref):
| return session.call_xenapi("VDI.get_uuid", vdi_ref)
| (session, vbd_ref):
return session.call_xenapi("VBD.get_record", vbd_ref)
def _vdi_get_rec(session, vdi_ref):
return session.call_xenapi("VDI.get_record", vdi_ref)
def _vdi_get_uuid(session, vdi_ref):
| 64 | 64 | 29 | 12 | 52 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vdi_get_uuid | _vdi_get_uuid | 576 | 577 | 576 | 576 | 3e74556076d8258a8a6f89fa00e243f9aef3b941 | bigcode/the-stack | train |
38771609c735f756780eb2a7 | train | function | def _get_dom0_ref(session):
vms = session.call_xenapi("VM.get_all_records_where",
'field "domid"="0" and '
'field "resident_on"="%s"' %
session.host_ref)
return list(vms.keys())[0]
| def _get_dom0_ref(session):
| vms = session.call_xenapi("VM.get_all_records_where",
'field "domid"="0" and '
'field "resident_on"="%s"' %
session.host_ref)
return list(vms.keys())[0]
| will log error
pass
LOG.debug('Destroying VBD for VDI %s done.', vdi_ref)
def _get_sys_hypervisor_uuid():
with open('/sys/hypervisor/uuid') as f:
return f.readline().strip()
def _get_dom0_ref(session):
| 64 | 64 | 61 | 8 | 56 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_dom0_ref | _get_dom0_ref | 2,204 | 2,209 | 2,204 | 2,204 | e85bd1492356e3d5a80cf594d70b256f4369a901 | bigcode/the-stack | train |
4be1931129c310a7721e2da3 | train | function | def try_auto_configure_disk(session, vdi_ref, new_gb):
if CONF.xenserver.independent_compute:
raise exception.NotSupportedWithOption(
operation='auto_configure_disk',
option='CONF.xenserver.independent_compute')
try:
_auto_configure_disk(session, vdi_ref, new_gb)
exce... | def try_auto_configure_disk(session, vdi_ref, new_gb):
| if CONF.xenserver.independent_compute:
raise exception.NotSupportedWithOption(
operation='auto_configure_disk',
option='CONF.xenserver.independent_compute')
try:
_auto_configure_disk(session, vdi_ref, new_gb)
except exception.CannotResizeDisk as e:
LOG.warning... | raise exception.CannotResizeDisk(reason=reason)
new_sectors = new_gb * units.Gi / SECTOR_SIZE
_resize_part_and_fs(dev, start, old_sectors, new_sectors, flags)
def try_auto_configure_disk(session, vdi_ref, new_gb):
| 64 | 64 | 100 | 16 | 48 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | try_auto_configure_disk | try_auto_configure_disk | 965 | 973 | 965 | 965 | d4c05d12caae07520475ce5557db2d2ed2b2902a | bigcode/the-stack | train |
8c5af2934241ad3a14043b24 | train | function | def _vm_get_vbd_refs(session, vm_ref):
return session.call_xenapi("VM.get_VBDs", vm_ref)
| def _vm_get_vbd_refs(session, vm_ref):
| return session.call_xenapi("VM.get_VBDs", vm_ref)
| _config(vdi_type, instance=instance)
for key, value in other_config.items():
if key not in existing_other_config:
session.call_xenapi(
"VDI.add_to_other_config", vdi_ref, key, value)
def _vm_get_vbd_refs(session, vm_ref):
| 64 | 64 | 29 | 12 | 52 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vm_get_vbd_refs | _vm_get_vbd_refs | 564 | 565 | 564 | 564 | 65cd6a1efcd025340effdd87a7b48906bafa7cd1 | bigcode/the-stack | train |
c4ee2bbec3dd8d6084d176d8 | train | function | def compile_diagnostics(vm_rec):
"""Compile VM diagnostics data."""
try:
keys = []
diags = {}
vm_uuid = vm_rec["uuid"]
xml = _get_rrd(_get_rrd_server(), vm_uuid)
if xml:
rrd = minidom.parseString(xml)
for i, node in enumerate(rrd.firstChild.childNo... | def compile_diagnostics(vm_rec):
| """Compile VM diagnostics data."""
try:
keys = []
diags = {}
vm_uuid = vm_rec["uuid"]
xml = _get_rrd(_get_rrd_server(), vm_uuid)
if xml:
rrd = minidom.parseString(xml)
for i, node in enumerate(rrd.firstChild.childNodes):
# Provide t... | is in Bytes. Converting it to MB.
total_mem /= units.Mi
if free_mem is not None:
# free_mem provided from XenServer is in KB. Converting it to MB.
used_mem = total_mem - free_mem / units.Ki
diag_obj.memory_details = diagnostics.MemoryDiagnostics(
maximum=total_mem,... | 86 | 86 | 289 | 7 | 79 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | compile_diagnostics | compile_diagnostics | 1,781 | 1,813 | 1,781 | 1,781 | 05136109aae895da2e5bcf082c91f485ba3c6034 | bigcode/the-stack | train |
af5dde78d79db387c69a833d | train | function | def attach_cd(session, vm_ref, vdi_ref, userdevice):
"""Create an empty VBD, then insert the CD."""
vbd_ref = create_vbd(session, vm_ref, None, userdevice,
vbd_type='cd', read_only=True,
bootable=True, empty=True,
unpluggable=False)
... | def attach_cd(session, vm_ref, vdi_ref, userdevice):
| """Create an empty VBD, then insert the CD."""
vbd_ref = create_vbd(session, vm_ref, None, userdevice,
vbd_type='cd', read_only=True,
bootable=True, empty=True,
unpluggable=False)
session.call_xenapi('VBD.insert', vbd_ref, vdi_ref)
... | to indicate this is an
# attached nova (or cinder) volume
session.call_xenapi('VBD.add_to_other_config',
vbd_ref, 'osvol', 'True')
return vbd_ref
def attach_cd(session, vm_ref, vdi_ref, userdevice):
| 64 | 64 | 97 | 15 | 48 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | attach_cd | attach_cd | 419 | 426 | 419 | 419 | cadfbfc04fb85608c7662811858735b1fac2c5af | bigcode/the-stack | train |
1ffc88fbd9bdc18c0ec7e700 | train | function | def _snapshot_attached_here_impl(session, instance, vm_ref, label, userdevice,
post_snapshot_callback):
"""Snapshot the root disk only. Return a list of uuids for the vhds
in the chain.
"""
LOG.debug("Starting snapshot for VM", instance=instance)
# Memorize the VDI... | def _snapshot_attached_here_impl(session, instance, vm_ref, label, userdevice,
post_snapshot_callback):
| """Snapshot the root disk only. Return a list of uuids for the vhds
in the chain.
"""
LOG.debug("Starting snapshot for VM", instance=instance)
# Memorize the VDI chain so we can poll for coalesce
vm_vdi_ref, vm_vdi_rec = get_vdi_for_vm_safely(session, vm_ref,
... | _delete_snapshots_in_vdi_chain(session, instance, vdi_uuid_chain, sr_ref)
@contextlib.contextmanager
def snapshot_attached_here(session, instance, vm_ref, label, userdevice='0',
post_snapshot_callback=None):
# impl method allow easier patching for tests
return _snapshot_attached... | 112 | 112 | 375 | 24 | 88 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _snapshot_attached_here_impl | _snapshot_attached_here_impl | 665 | 697 | 665 | 666 | 2f4f3e511ed7c26d8b057a40d694bba1c2726a64 | bigcode/the-stack | train |
ca9e05a92a30f1bfa0c9c4e2 | train | function | def _add_disk_usage(session, vm_ref, diag_obj):
vbd_refs = session.VM.get_VBDs(vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = session.VBD.get_record(vbd_ref)
read_bytes = _vm_query_data_source(session, vm_ref,
"vbd_%s_read" % vbd_rec['device'])
writ... | def _add_disk_usage(session, vm_ref, diag_obj):
| vbd_refs = session.VM.get_VBDs(vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = session.VBD.get_record(vbd_ref)
read_bytes = _vm_query_data_source(session, vm_ref,
"vbd_%s_read" % vbd_rec['device'])
write_bytes = _vm_query_data_source(session, vm_ref,... | vm_query_data_source(session, vm_ref,
"vif_%s_tx" % vif_rec['device'])
diag_obj.add_nic(mac_address=vif_rec['MAC'],
rx_rate=rx_rate,
tx_rate=tx_rate)
def _add_disk_usage(session, vm_ref, diag_obj):
| 64 | 64 | 127 | 13 | 51 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _add_disk_usage | _add_disk_usage | 1,754 | 1,762 | 1,754 | 1,754 | 7443da812185cd07ac8633c6d610443d46d9185b | bigcode/the-stack | train |
f3243b883c600dfa3153b799 | train | function | def _fetch_image(context, session, instance, name_label, image_id, image_type,
image_handler):
"""Fetch image from glance based on image type.
Returns: A single filename if image_type is KERNEL or RAMDISK
A list of dictionaries that describe VDIs, otherwise
"""
if image_ty... | def _fetch_image(context, session, instance, name_label, image_id, image_type,
image_handler):
| """Fetch image from glance based on image type.
Returns: A single filename if image_type is KERNEL or RAMDISK
A list of dictionaries that describe VDIs, otherwise
"""
if image_type == ImageType.DISK_VHD:
vdis = _fetch_vhd_image(context, session, instance, image_id,
... | = session.call_xenapi('VDI.get_by_uuid', vdi['uuid'])
_set_vdi_info(session, vdi_ref, vdi_type, name_label, vdi_type,
instance)
return vdis
def _fetch_image(context, session, instance, name_label, image_id, image_type,
image_handler):
| 72 | 72 | 243 | 23 | 48 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _fetch_image | _fetch_image | 1,344 | 1,369 | 1,344 | 1,345 | ce6a3f58ab4399c4ca2c9eb0695e293b980852bf | bigcode/the-stack | train |
cc093e4d3f3da4c49d04fd4d | train | function | def clean_shutdown_vm(session, instance, vm_ref):
if is_vm_shutdown(session, vm_ref):
LOG.warning("VM already halted, skipping shutdown...",
instance=instance)
return True
LOG.debug("Shutting down VM (cleanly)", instance=instance)
try:
session.call_xenapi('VM.cle... | def clean_shutdown_vm(session, instance, vm_ref):
| if is_vm_shutdown(session, vm_ref):
LOG.warning("VM already halted, skipping shutdown...",
instance=instance)
return True
LOG.debug("Shutting down VM (cleanly)", instance=instance)
try:
session.call_xenapi('VM.clean_shutdown', vm_ref)
except session.XenAPI.Fa... | vm_ref):
"""Destroys a VM record."""
try:
session.VM.destroy(vm_ref)
except session.XenAPI.Failure:
LOG.exception(_('Destroy VM failed'))
return
LOG.debug("VM destroyed", instance=instance)
def clean_shutdown_vm(session, instance, vm_ref):
| 64 | 64 | 106 | 11 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | clean_shutdown_vm | clean_shutdown_vm | 273 | 285 | 273 | 273 | 590d4d494567f229a87e0e1e26a3f30f7b0c42b9 | bigcode/the-stack | train |
eaa46391af381898bb730666 | train | function | def update_vdi_virtual_size(session, instance, vdi_ref, new_gb):
virtual_size = _vdi_get_virtual_size(session, vdi_ref)
new_disk_size = new_gb * units.Gi
msg = ("Resizing up VDI %(vdi_ref)s from %(virtual_size)d "
"to %(new_disk_size)d")
LOG.debug(msg, {'vdi_ref': vdi_ref, 'virtual_size': vi... | def update_vdi_virtual_size(session, instance, vdi_ref, new_gb):
| virtual_size = _vdi_get_virtual_size(session, vdi_ref)
new_disk_size = new_gb * units.Gi
msg = ("Resizing up VDI %(vdi_ref)s from %(virtual_size)d "
"to %(new_disk_size)d")
LOG.debug(msg, {'vdi_ref': vdi_ref, 'virtual_size': virtual_size,
'new_disk_size': new_disk_size},
... | (session, vdi_ref):
size = session.call_xenapi('VDI.get_virtual_size', vdi_ref)
return int(size)
def _vdi_resize(session, vdi_ref, new_size):
resize_func_name = _get_resize_func_name(session)
session.call_xenapi(resize_func_name, vdi_ref, str(new_size))
def update_vdi_virtual_size(session, instance, v... | 93 | 93 | 310 | 18 | 75 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | update_vdi_virtual_size | update_vdi_virtual_size | 860 | 887 | 860 | 860 | bb234c5a24588606417a0a6f1f3c70e2cb353747 | bigcode/the-stack | train |
458af3e46b16dd6a2ad4ca71 | train | function | def _scan_sr(session, sr_ref=None, max_attempts=4):
if sr_ref:
# NOTE(johngarbutt) xenapi will collapse any duplicate requests
# for SR.scan if there is already a scan in progress.
# However, we don't want that, because the scan may have started
# before we modified the underlying VH... | def _scan_sr(session, sr_ref=None, max_attempts=4):
| if sr_ref:
# NOTE(johngarbutt) xenapi will collapse any duplicate requests
# for SR.scan if there is already a scan in progress.
# However, we don't want that, because the scan may have started
# before we modified the underlying VHDs on disk through a plugin.
# Using our own... |
break
return diags
except expat.ExpatError as e:
LOG.exception(_('Unable to parse rrd of %s'), e)
return {"Unable to retrieve diagnostics": e}
def fetch_bandwidth(session):
bw = host_network.fetch_all_bandwidth(session)
return bw
def _scan_sr(session, sr_ref=N... | 81 | 81 | 272 | 16 | 64 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _scan_sr | _scan_sr | 1,821 | 1,846 | 1,821 | 1,821 | e73a3d566d50dcac65b1003d306e4fdfa19ebb61 | bigcode/the-stack | train |
d2d1301b1c0cf0f5d7623b92 | train | function | def scan_default_sr(session):
"""Looks for the system default SR and triggers a re-scan."""
sr_ref = safe_find_sr(session)
_scan_sr(session, sr_ref)
return sr_ref
| def scan_default_sr(session):
| """Looks for the system default SR and triggers a re-scan."""
sr_ref = safe_find_sr(session)
_scan_sr(session, sr_ref)
return sr_ref
| _40':
if attempt < max_attempts:
ctxt.reraise = False
LOG.warning("Retry SR scan due to error: %s",
exc)
greenthread.sleep(2 ** attempt)
... | 64 | 64 | 44 | 6 | 58 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | scan_default_sr | scan_default_sr | 1,849 | 1,853 | 1,849 | 1,849 | 8d0b5864d5f613fc29d57699ccd695cc918fcba3 | bigcode/the-stack | train |
85cda318dcd427d5a045d37e | train | class | class ImageType(object):
"""Enumeration class for distinguishing different image types
| 0 - kernel image (goes on dom0's filesystem)
| 1 - ramdisk image (goes on dom0's filesystem)
| 2 - disk image (local SR, partitioned by objectstore plugin)
| 3 - raw disk image (local SR, NOT partitioned by plu... | class ImageType(object):
| """Enumeration class for distinguishing different image types
| 0 - kernel image (goes on dom0's filesystem)
| 1 - ramdisk image (goes on dom0's filesystem)
| 2 - disk image (local SR, partitioned by objectstore plugin)
| 3 - raw disk image (local SR, NOT partitioned by plugin)
| 4 - vhd disk i... | USED,
'Suspended': power_state.SUSPENDED,
'Crashed': power_state.CRASHED}
SECTOR_SIZE = 512
MBR_SIZE_SECTORS = 63
MBR_SIZE_BYTES = MBR_SIZE_SECTORS * SECTOR_SIZE
MAX_VDI_CHAIN_SIZE = 16
PROGRESS_INTERVAL_SECONDS = 300
DD_BLOCKSIZE = 65536
# Fudge factor to allow for the VHD chain to be slightly larger than
#... | 147 | 147 | 490 | 5 | 141 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | ImageType | ImageType | 94 | 142 | 94 | 94 | af3c880bf32a7dd959fa1c9ac6966cb1a317ed9c | bigcode/the-stack | train |
78b00ee1f12c7bd683bda485 | train | function | def _find_cached_image(session, image_id, sr_ref):
"""Returns the vdi-ref of the cached image."""
name_label = _get_image_vdi_label(image_id)
# For not pooled hosts, only name_lable is enough to get a cached image.
# When in a xapi pool, each host may have a cached image using the
# same name while ... | def _find_cached_image(session, image_id, sr_ref):
| """Returns the vdi-ref of the cached image."""
name_label = _get_image_vdi_label(image_id)
# For not pooled hosts, only name_lable is enough to get a cached image.
# When in a xapi pool, each host may have a cached image using the
# same name while xapi api will search all of them. Add SR to the fil... | Error:
continue
cached_time = vdi_rec['other_config'].get('cached-time')
cached_images[image_id] = {'vdi_ref': vdi_ref,
'cached_time': cached_time}
return cached_images
def _find_cached_image(session, image_id, sr_ref):
| 64 | 64 | 216 | 13 | 50 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _find_cached_image | _find_cached_image | 813 | 828 | 813 | 813 | af802b01d73337a9bb5e9b85605a336ad6f78376 | bigcode/the-stack | train |
e6bf570776d390ddf26c262e | train | function | def get_power_state(session, vm_ref):
xapi_state = session.call_xenapi("VM.get_power_state", vm_ref)
return XENAPI_POWER_STATE[xapi_state]
| def get_power_state(session, vm_ref):
| xapi_state = session.call_xenapi("VM.get_power_state", vm_ref)
return XENAPI_POWER_STATE[xapi_state]
| .call_xenapi("VM.get_record", vm)
if 'is_a_template' in vm_rec and 'is_a_snapshot' in vm_rec:
return vm_rec['is_a_template'] and vm_rec['is_a_snapshot']
else:
return False
def get_power_state(session, vm_ref):
| 64 | 64 | 39 | 9 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | get_power_state | get_power_state | 1,689 | 1,691 | 1,689 | 1,689 | 8a428dcc6fede9b6826ef7894477a93396eb3af8 | bigcode/the-stack | train |
1b71670190591d5f557f3636 | train | function | def set_other_config_pci(session, vm_ref, params):
"""Set the pci key of other-config parameter to params."""
other_config = session.call_xenapi("VM.get_other_config", vm_ref)
other_config['pci'] = params
session.call_xenapi("VM.set_other_config", vm_ref, other_config)
| def set_other_config_pci(session, vm_ref, params):
| """Set the pci key of other-config parameter to params."""
other_config = session.call_xenapi("VM.get_other_config", vm_ref)
other_config['pci'] = params
session.call_xenapi("VM.set_other_config", vm_ref, other_config)
| = exc.details[:3]
if error == 'CommandNotFound':
LOG.warning("ISO creation tool '%s' does not exist.",
CONF.xenserver.ipxe_mkisofs_cmd, instance=instance)
else:
raise
def set_other_config_pci(session, vm_ref, params):
| 64 | 64 | 71 | 13 | 50 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | set_other_config_pci | set_other_config_pci | 2,598 | 2,602 | 2,598 | 2,598 | 085ddcd2f2c7c85b6deb1c48297b9c9d9c993aab | bigcode/the-stack | train |
692d37bcdddd450ab1cf6eda | train | function | def lookup_kernel_ramdisk(session, vm):
vm_rec = session.call_xenapi("VM.get_record", vm)
if 'PV_kernel' in vm_rec and 'PV_ramdisk' in vm_rec:
return (vm_rec['PV_kernel'], vm_rec['PV_ramdisk'])
else:
return (None, None)
| def lookup_kernel_ramdisk(session, vm):
| vm_rec = session.call_xenapi("VM.get_record", vm)
if 'PV_kernel' in vm_rec and 'PV_ramdisk' in vm_rec:
return (vm_rec['PV_kernel'], vm_rec['PV_ramdisk'])
else:
return (None, None)
|
# everything
mount_required = key or net or metadata
if not mount_required:
return
with vdi_attached(session, vdi_ref, read_only=False) as dev:
_mounted_processing(dev, key, net, metadata)
def lookup_kernel_ramdisk(session, vm):
| 64 | 64 | 70 | 9 | 55 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | lookup_kernel_ramdisk | lookup_kernel_ramdisk | 1,673 | 1,678 | 1,673 | 1,673 | 16ffa976372164af90c3f39f8902101292a6dc37 | bigcode/the-stack | train |
bd249a7cb35361dc1355eb0d | train | function | def get_this_vm_uuid(session):
if CONF.xenserver.independent_compute:
LOG.error("This host has been configured with the independent "
"compute flag. An operation has been attempted which is "
"incompatible with this flag, but should have been "
"caught ... | def get_this_vm_uuid(session):
| if CONF.xenserver.independent_compute:
LOG.error("This host has been configured with the independent "
"compute flag. An operation has been attempted which is "
"incompatible with this flag, but should have been "
"caught earlier. Please raise a bug ag... | _ref)
def _get_sys_hypervisor_uuid():
with open('/sys/hypervisor/uuid') as f:
return f.readline().strip()
def _get_dom0_ref(session):
vms = session.call_xenapi("VM.get_all_records_where",
'field "domid"="0" and '
'field "resident_on"="%s"' ... | 100 | 100 | 334 | 7 | 93 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | get_this_vm_uuid | get_this_vm_uuid | 2,212 | 2,238 | 2,212 | 2,212 | 74b0452282433cb03196dea2530192d9ded3c8ca | bigcode/the-stack | train |
80c0d558266259a59e2eebb6 | train | function | def _safe_find_iso_sr(session):
"""Same as _find_iso_sr except raises a NotFound exception if SR
cannot be determined
"""
sr_ref = _find_iso_sr(session)
if sr_ref is None:
raise exception.NotFound(_('Cannot find SR of content-type ISO'))
return sr_ref
| def _safe_find_iso_sr(session):
| """Same as _find_iso_sr except raises a NotFound exception if SR
cannot be determined
"""
sr_ref = _find_iso_sr(session)
if sr_ref is None:
raise exception.NotFound(_('Cannot find SR of content-type ISO'))
return sr_ref
| XenAPI is unable to find a Storage Repository to "
"install guest instances on. Please check your "
"configuration (e.g. set a default SR for the pool) "
"and/or configure the flag 'sr_matching_filter'.")
return None
def _safe_find_iso_sr(session):
| 64 | 64 | 68 | 8 | 55 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _safe_find_iso_sr | _safe_find_iso_sr | 1,903 | 1,910 | 1,903 | 1,903 | 315cbf2fbf939bc441d932b6608f1c3e325b79bb | bigcode/the-stack | train |
a094a9c38712ca56753f2266 | train | function | def _fetch_disk_image(context, session, instance, name_label, image_id,
image_type):
"""Fetch the image from Glance
NOTE:
Unlike _fetch_vhd_image, this method does not use the Glance
plugin; instead, it streams the disks through domU to the VDI
directly.
Returns: A single... | def _fetch_disk_image(context, session, instance, name_label, image_id,
image_type):
| """Fetch the image from Glance
NOTE:
Unlike _fetch_vhd_image, this method does not use the Glance
plugin; instead, it streams the disks through domU to the VDI
directly.
Returns: A single filename if image_type is KERNEL_RAMDISK
A list of dictionaries that describe VDIs, otherwise... | vdi_uuid=%(cur_vdi_uuid)s vdi_size_bytes='
'%(vdi_size_bytes)d',
{'cur_vdi_uuid': cur_vdi_uuid,
'vdi_size_bytes': vdi_size_bytes})
size_bytes += vdi_size_bytes
return size_bytes
def _check_vdi_size(context, session, instance, vdi_uuid):
flavor = i... | 256 | 256 | 888 | 21 | 235 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _fetch_disk_image | _fetch_disk_image | 1,455 | 1,541 | 1,455 | 1,456 | 6d24c0d85e346e1d64ea9e7569a519cabac13927 | bigcode/the-stack | train |
1c0ff02f4b510bffeaa4353a | train | function | def _delete_snapshots_in_vdi_chain(session, instance, vdi_uuid_chain, sr_ref):
possible_snapshot_parents = vdi_uuid_chain[1:]
if len(possible_snapshot_parents) == 0:
LOG.debug("No VHD chain.", instance=instance)
return
snapshot_uuids = _child_vhds(session, sr_ref, possible_snapshot_parents... | def _delete_snapshots_in_vdi_chain(session, instance, vdi_uuid_chain, sr_ref):
| possible_snapshot_parents = vdi_uuid_chain[1:]
if len(possible_snapshot_parents) == 0:
LOG.debug("No VHD chain.", instance=instance)
return
snapshot_uuids = _child_vhds(session, sr_ref, possible_snapshot_parents,
old_snapshots_only=True)
number_of_snaps... | _ref in vbd_refs:
vdi_ref = session.call_xenapi("VBD.get_VDI", vbd_ref)
_try_strip_base_mirror_from_vdi(session, vdi_ref)
def _delete_snapshots_in_vdi_chain(session, instance, vdi_uuid_chain, sr_ref):
| 64 | 64 | 203 | 21 | 43 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _delete_snapshots_in_vdi_chain | _delete_snapshots_in_vdi_chain | 622 | 644 | 622 | 622 | 2c644198c22384e0fd721b792372a43264c3e9d9 | bigcode/the-stack | train |
45b24f5e85d84ec8fe5ea0ac | train | function | def preconfigure_instance(session, instance, vdi_ref, network_info):
"""Makes alterations to the image before launching as part of spawn.
"""
key = str(instance['key_data'])
net = netutils.get_injected_network_template(network_info)
metadata = instance['metadata']
# As mounting the image VDI is... | def preconfigure_instance(session, instance, vdi_ref, network_info):
| """Makes alterations to the image before launching as part of spawn.
"""
key = str(instance['key_data'])
net = netutils.get_injected_network_template(network_info)
metadata = instance['metadata']
# As mounting the image VDI is expensive, we only want do it once,
# if at all, so determine wh... | _label", name_label)
n = len(vm_refs)
if n == 0:
return None
elif n > 1:
raise exception.InstanceExists(name=name_label)
else:
return vm_refs[0]
def preconfigure_instance(session, instance, vdi_ref, network_info):
| 64 | 64 | 149 | 15 | 49 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | preconfigure_instance | preconfigure_instance | 1,655 | 1,670 | 1,655 | 1,655 | a9572c35a0204a505d973c83142b30b4a19a20a0 | bigcode/the-stack | train |
6a57203e8fac6335e0106048 | train | function | def generate_ephemeral(session, instance, vm_ref, first_userdevice,
instance_name_label, total_size_gb):
# NOTE(johngarbutt): max possible size of a VHD disk is 2043GB
sizes = get_ephemeral_disk_sizes(total_size_gb)
first_userdevice = int(first_userdevice)
vdi_refs = []
try:
... | def generate_ephemeral(session, instance, vm_ref, first_userdevice,
instance_name_label, total_size_gb):
# NOTE(johngarbutt): max possible size of a VHD disk is 2043GB
| sizes = get_ephemeral_disk_sizes(total_size_gb)
first_userdevice = int(first_userdevice)
vdi_refs = []
try:
for userdevice, size_gb in enumerate(sizes, start=first_userdevice):
ref = generate_single_ephemeral(session, instance, vm_ref,
use... | _gb * 1024,
CONF.default_ephemeral_format, fs_label)
def generate_ephemeral(session, instance, vm_ref, first_userdevice,
instance_name_label, total_size_gb):
# NOTE(johngarbutt): max possible size of a VHD disk is 2043GB
| 66 | 66 | 223 | 49 | 17 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | generate_ephemeral | generate_ephemeral | 1,108 | 1,129 | 1,108 | 1,110 | 1684b0496a46d89820e949c481c05708fbedaced | bigcode/the-stack | train |
8d51a40633a219cef325cdc1 | train | function | def _get_this_vm_ref(session):
return session.call_xenapi("VM.get_by_uuid", get_this_vm_uuid(session))
| def _get_this_vm_ref(session):
| return session.call_xenapi("VM.get_by_uuid", get_this_vm_uuid(session))
| nova.privsep.xenapi.xenstore_read('domid')
vm_key, _ = nova.privsep.xenapi.xenstore_read(
'/local/domain/%s/vm' % domid.strip())
return vm_key.strip()[4:]
def _get_this_vm_ref(session):
| 63 | 64 | 27 | 8 | 55 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_this_vm_ref | _get_this_vm_ref | 2,241 | 2,242 | 2,241 | 2,241 | ffbd63dd6bdea716296c7f65851e860ad5c6372d | bigcode/the-stack | train |
2b0883f48b17b72fc29918cd | train | function | def _walk_vdi_chain(session, vdi_uuid):
"""Yield vdi_recs for each element in a VDI chain."""
scan_default_sr(session)
while True:
vdi_ref = session.call_xenapi("VDI.get_by_uuid", vdi_uuid)
vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
yield vdi_rec
parent_uuid = ... | def _walk_vdi_chain(session, vdi_uuid):
| """Yield vdi_recs for each element in a VDI chain."""
scan_default_sr(session)
while True:
vdi_ref = session.call_xenapi("VDI.get_by_uuid", vdi_uuid)
vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
yield vdi_rec
parent_uuid = _get_vhd_parent_uuid(session, vdi_ref, v... | ']
vdi_uuid = vdi_rec['uuid']
LOG.debug('VHD %(vdi_uuid)s has parent %(parent_uuid)s',
{'vdi_uuid': vdi_uuid, 'parent_uuid': parent_uuid})
return parent_uuid
def _walk_vdi_chain(session, vdi_uuid):
| 64 | 64 | 122 | 12 | 51 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _walk_vdi_chain | _walk_vdi_chain | 2,002 | 2,014 | 2,002 | 2,002 | 3a6b3ecfaa1931326266483657f8ee95edf75941 | bigcode/the-stack | train |
50c3df9173751dbfbf34b4d1 | train | function | def determine_disk_image_type(image_meta):
"""Disk Image Types are used to determine where the kernel will reside
within an image. To figure out which type we're dealing with, we use
the following rules:
1. If we're using Glance, we can use the image_type field to
determine the image_type
2... | def determine_disk_image_type(image_meta):
| """Disk Image Types are used to determine where the kernel will reside
within an image. To figure out which type we're dealing with, we use
the following rules:
1. If we're using Glance, we can use the image_type field to
determine the image_type
2. If we're not using Glance, then we need t... | API.Failure, IOError, OSError) as e:
# We look for XenAPI and OS failures.
LOG.exception(_("Failed to fetch glance image"), instance=instance)
e.args = e.args + ([dict(type=ImageType.to_string(image_type),
uuid=vdi_uuid,
file=file... | 78 | 78 | 261 | 8 | 69 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | determine_disk_image_type | determine_disk_image_type | 1,544 | 1,576 | 1,544 | 1,544 | 58e609adcd250931b5c74bfbb1e340a2c6d65aef | bigcode/the-stack | train |
8e144662269836d19772018f | train | function | def _find_cached_images(session, sr_ref):
"""Return a dict {image_id: {'vdi_ref': vdi_ref, 'cached_time':
cached_time}} representing all cached images.
"""
cached_images = {}
for vdi_ref, vdi_rec in _get_all_vdis_in_sr(session, sr_ref):
try:
image_id = vdi_rec['other_config']['im... | def _find_cached_images(session, sr_ref):
| """Return a dict {image_id: {'vdi_ref': vdi_ref, 'cached_time':
cached_time}} representing all cached images.
"""
cached_images = {}
for vdi_ref, vdi_rec in _get_all_vdis_in_sr(session, sr_ref):
try:
image_id = vdi_rec['other_config']['image-id']
except KeyError:
... | 24) \
>= keep_days:
destroy_cached_vdi(vdi_uuid, vdi_ref)
else:
LOG.debug("vdi %s can't be destroyed because the cached time is"
" not specified", vdi_uuid)
return destroyed
def _find_cached_images(session, sr_ref):
| 64 | 64 | 141 | 10 | 53 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _find_cached_images | _find_cached_images | 795 | 810 | 795 | 795 | c8269b0be80687f7270d60fb6403cacc61986e91 | bigcode/the-stack | train |
679c8c19d1767724e71f1d91 | train | function | def generate_single_ephemeral(session, instance, vm_ref, userdevice,
size_gb, instance_name_label=None):
if instance_name_label is None:
instance_name_label = instance["name"]
name_label = "%s ephemeral" % instance_name_label
fs_label = "ephemeral"
# TODO(johngarbu... | def generate_single_ephemeral(session, instance, vm_ref, userdevice,
size_gb, instance_name_label=None):
| if instance_name_label is None:
instance_name_label = instance["name"]
name_label = "%s ephemeral" % instance_name_label
fs_label = "ephemeral"
# TODO(johngarbutt) need to move DEVICE_EPHEMERAL from vmops to use it here
label_number = int(userdevice) - 4
if label_number > 0:
nam... | while left_to_allocate > 0:
size_gb = min(max_size_gb, left_to_allocate)
yield size_gb
left_to_allocate -= size_gb
def generate_single_ephemeral(session, instance, vm_ref, userdevice,
size_gb, instance_name_label=None):
| 64 | 64 | 181 | 25 | 38 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | generate_single_ephemeral | generate_single_ephemeral | 1,090 | 1,105 | 1,090 | 1,091 | 3b3e3dabd493d868e10db757e286bcfc2a85ed5c | bigcode/the-stack | train |
b9a07ceba5bb1a35f7b297b3 | train | function | def generate_swap(session, instance, vm_ref, userdevice, name_label, swap_mb):
# NOTE(jk0): We use a FAT32 filesystem for the Windows swap
# partition because that is what parted supports.
is_windows = instance['os_type'] == "windows"
fs_type = "vfat" if is_windows else "swap"
if CONF.xenserver.ind... | def generate_swap(session, instance, vm_ref, userdevice, name_label, swap_mb):
# NOTE(jk0): We use a FAT32 filesystem for the Windows swap
# partition because that is what parted supports.
| is_windows = instance['os_type'] == "windows"
fs_type = "vfat" if is_windows else "swap"
if CONF.xenserver.independent_compute and fs_type != "swap":
raise exception.NotSupportedWithOption(
operation='swap drives for Windows',
option='CONF.xenserver.independent_compute')
... | safe_destroy_vdis(session, [vdi_ref])
return vdi_ref
def generate_swap(session, instance, vm_ref, userdevice, name_label, swap_mb):
# NOTE(jk0): We use a FAT32 filesystem for the Windows swap
# partition because that is what parted supports.
| 64 | 64 | 145 | 47 | 16 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | generate_swap | generate_swap | 1,060 | 1,072 | 1,060 | 1,062 | f7d102b12f36027069fba6fd7f36f51cc68f7d5a | bigcode/the-stack | train |
8aeee6f8b5f99615579607ff | train | function | def create_vbd(session, vm_ref, vdi_ref, userdevice, vbd_type='disk',
read_only=False, bootable=False, osvol=False,
empty=False, unpluggable=True):
"""Create a VBD record and returns its reference."""
vbd_rec = {}
vbd_rec['VM'] = vm_ref
if vdi_ref is None:
vdi_ref =... | def create_vbd(session, vm_ref, vdi_ref, userdevice, vbd_type='disk',
read_only=False, bootable=False, osvol=False,
empty=False, unpluggable=True):
| """Create a VBD record and returns its reference."""
vbd_rec = {}
vbd_rec['VM'] = vm_ref
if vdi_ref is None:
vdi_ref = 'OpaqueRef:NULL'
vbd_rec['VDI'] = vdi_ref
vbd_rec['userdevice'] = str(userdevice)
vbd_rec['bootable'] = bootable
vbd_rec['mode'] = read_only and 'RO' or 'RW'
... | % vbd_ref)
def destroy_vbd(session, vbd_ref):
"""Destroy VBD from host database."""
try:
session.call_xenapi('VBD.destroy', vbd_ref)
except session.XenAPI.Failure:
LOG.exception(_('Unable to destroy VBD'))
raise exception.StorageError(
reason=_('Unable to destroy V... | 129 | 129 | 430 | 45 | 84 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | create_vbd | create_vbd | 385 | 416 | 385 | 387 | 8ae42e642c3b42d061ac58549cecb1f2c8c8b29c | bigcode/the-stack | train |
edc274dfff818292e69ec071 | train | function | def create_image(context, session, instance, name_label, image_id,
image_type, image_handler):
"""Creates VDI from the image stored in the local cache. If the image
is not present in the cache, it streams it from glance.
Returns: A list of dictionaries that describe VDIs
"""
cache_... | def create_image(context, session, instance, name_label, image_id,
image_type, image_handler):
| """Creates VDI from the image stored in the local cache. If the image
is not present in the cache, it streams it from glance.
Returns: A list of dictionaries that describe VDIs
"""
cache_images = CONF.xenserver.cache_images.lower()
# Determine if the image is cacheable
if image_type == Ima... | new_vdi_ref, 'image-id')
vdi_uuid = session.call_xenapi('VDI.get_uuid', new_vdi_ref)
return downloaded, vdi_uuid
downloaded, vdi_uuid = _create_cached_image_impl(context, session,
instance, name_label,
... | 134 | 134 | 448 | 22 | 111 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | create_image | create_image | 1,291 | 1,341 | 1,291 | 1,292 | d0040ed07b3e286c06c9decf935bbbf5731bef54 | bigcode/the-stack | train |
02b57d23d53cb17f857c5066 | train | function | def _set_vdi_info(session, vdi_ref, vdi_type, name_label, description,
instance):
existing_other_config = session.call_xenapi('VDI.get_other_config',
vdi_ref)
session.call_xenapi('VDI.set_name_label', vdi_ref, name_label)
session.call_xenapi... | def _set_vdi_info(session, vdi_ref, vdi_type, name_label, description,
instance):
| existing_other_config = session.call_xenapi('VDI.get_other_config',
vdi_ref)
session.call_xenapi('VDI.set_name_label', vdi_ref, name_label)
session.call_xenapi('VDI.set_name_description', vdi_ref, description)
other_config = _get_vdi_other_config(vdi_typ... | while creating a volume
# hence information about instance may or may not be present
if instance:
other_config['nova_instance_uuid'] = instance['uuid']
return other_config
def _set_vdi_info(session, vdi_ref, vdi_type, name_label, description,
instance):
| 64 | 64 | 146 | 24 | 39 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _set_vdi_info | _set_vdi_info | 549 | 561 | 549 | 550 | 72f4f950ea5d09179d0371eb0fcce3835e00ec91 | bigcode/the-stack | train |
5890b75a6ef0efeb0e1278fd | train | function | def _vdi_resize(session, vdi_ref, new_size):
resize_func_name = _get_resize_func_name(session)
session.call_xenapi(resize_func_name, vdi_ref, str(new_size))
| def _vdi_resize(session, vdi_ref, new_size):
| resize_func_name = _get_resize_func_name(session)
session.call_xenapi(resize_func_name, vdi_ref, str(new_size))
| 'VDI.resize_online'
return 'VDI.resize'
def _vdi_get_virtual_size(session, vdi_ref):
size = session.call_xenapi('VDI.get_virtual_size', vdi_ref)
return int(size)
def _vdi_resize(session, vdi_ref, new_size):
| 64 | 64 | 45 | 14 | 50 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _vdi_resize | _vdi_resize | 855 | 857 | 855 | 855 | 69be9097d0c1e884cf59674f74b4d11a719f2324 | bigcode/the-stack | train |
2f69b75c88c4d3cf78ef383d | train | function | def is_vm_shutdown(session, vm_ref):
state = get_power_state(session, vm_ref)
if state == power_state.SHUTDOWN:
return True
return False
| def is_vm_shutdown(session, vm_ref):
| state = get_power_state(session, vm_ref)
if state == power_state.SHUTDOWN:
return True
return False
| (hard)", instance=instance)
try:
session.call_xenapi('VM.hard_shutdown', vm_ref)
except session.XenAPI.Failure:
LOG.exception(_('Shutting down VM (hard) failed'))
return False
return True
def is_vm_shutdown(session, vm_ref):
| 64 | 64 | 38 | 9 | 54 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | is_vm_shutdown | is_vm_shutdown | 303 | 307 | 303 | 303 | 4779f51549964747089c8af088208b55246ffaca | bigcode/the-stack | train |
c7e56b615469e1423cd76d64 | train | function | def _get_sys_hypervisor_uuid():
with open('/sys/hypervisor/uuid') as f:
return f.readline().strip()
| def _get_sys_hypervisor_uuid():
| with open('/sys/hypervisor/uuid') as f:
return f.readline().strip()
| )
finally:
try:
destroy_vbd(session, vbd_ref)
except exception.StorageError:
# destroy_vbd() will log error
pass
LOG.debug('Destroying VBD for VDI %s done.', vdi_ref)
def _get_sys_hypervisor_uuid():
| 64 | 64 | 30 | 9 | 55 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _get_sys_hypervisor_uuid | _get_sys_hypervisor_uuid | 2,199 | 2,201 | 2,199 | 2,199 | d1331a4d11173c6b82caf3c295d454d49641156c | bigcode/the-stack | train |
443af053a0c87b8c9b271ae7 | train | function | def fetch_bandwidth(session):
bw = host_network.fetch_all_bandwidth(session)
return bw
| def fetch_bandwidth(session):
| bw = host_network.fetch_all_bandwidth(session)
return bw
| _row):
diags[keys[j]] = value.firstChild.data
break
return diags
except expat.ExpatError as e:
LOG.exception(_('Unable to parse rrd of %s'), e)
return {"Unable to retrieve diagnostics": e}
def fetch_bandwidth(session):
| 64 | 64 | 21 | 6 | 58 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | fetch_bandwidth | fetch_bandwidth | 1,816 | 1,818 | 1,816 | 1,816 | ec0b044dfde5af228e087f94b7e2037b1e9bc2ae | bigcode/the-stack | train |
4c6cf2e6596bc5b4c57b63d7 | train | function | def _import_migrated_vhds(session, instance, chain_label, disk_type,
vdi_label):
"""Move and possibly link VHDs via the XAPI plugin."""
imported_vhds = vm_management.receive_vhd(session, chain_label,
get_sr_path(session),
... | def _import_migrated_vhds(session, instance, chain_label, disk_type,
vdi_label):
| """Move and possibly link VHDs via the XAPI plugin."""
imported_vhds = vm_management.receive_vhd(session, chain_label,
get_sr_path(session),
_make_uuid_stack())
# Now we rescan the SR so we find the VHDs
scan_de... | _label, "ephemeral",
vdi_label)
userdevice = 3 + chain_number
ephemeral_vdis[str(userdevice)] = ephemeral_vdi
return ephemeral_vdis
def _import_migrated_vhds(session, instance, chain_label, disk_type,
vdi_label):
| 64 | 64 | 184 | 24 | 39 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _import_migrated_vhds | _import_migrated_vhds | 2,492 | 2,509 | 2,492 | 2,493 | f661bbd665662ed36ab493cfd3756af988f322a6 | bigcode/the-stack | train |
7ce6e9c129b8508b906a97ae | train | function | def compile_info(session, vm_ref):
"""Fill record with VM status information."""
return hardware.InstanceInfo(state=get_power_state(session, vm_ref))
| def compile_info(session, vm_ref):
| """Fill record with VM status information."""
return hardware.InstanceInfo(state=get_power_state(session, vm_ref))
| `` exception or may return a `NaN` value.
"""
try:
value = session.VM.query_data_source(*args)
except session.XenAPI.Failure:
return None
if math.isnan(value):
return None
return value
def compile_info(session, vm_ref):
| 64 | 64 | 31 | 8 | 55 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | compile_info | compile_info | 1,711 | 1,713 | 1,711 | 1,711 | 0d5c5fef7a352416458fe4132b4fa9636844ecd9 | bigcode/the-stack | train |
8b5c1aa64ebcfbf7ba56fe5a | train | function | def _create_kernel_image(context, session, instance, name_label, image_id,
image_type):
"""Creates kernel/ramdisk file from the image stored in the cache.
If the image is not present in the cache, fetch it from glance.
Returns: A list of dictionaries that describe VDIs
"""
... | def _create_kernel_image(context, session, instance, name_label, image_id,
image_type):
| """Creates kernel/ramdisk file from the image stored in the cache.
If the image is not present in the cache, fetch it from glance.
Returns: A list of dictionaries that describe VDIs
"""
if CONF.xenserver.independent_compute:
raise exception.NotSupportedWithOption(
operation='Non... | utils.save_and_reraise_exception():
msg = "Error while generating config drive"
LOG.debug(msg, instance=instance, exc_info=True)
safe_destroy_vdis(session, [vdi_ref])
def _create_kernel_image(context, session, instance, name_label, image_id,
image_type):
| 64 | 64 | 207 | 21 | 43 | mertakozcan/nova | nova/virt/xenapi/vm_utils.py | Python | _create_kernel_image | _create_kernel_image | 1,173 | 1,196 | 1,173 | 1,174 | 780487ae6e04ad475917dfa32e60990be41338a6 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.