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
294de5378805d02af8a8c90f
train
function
def create_covar_matrix_vectorised(overlap_array,variances): """Create the covariance matrix for a single wavelength slice. As input takes the output of the drizzle class, overlap_array, and the variances of the individual fibres Dis been refactored by Francesco to add 0-th order vectorizatio...
def create_covar_matrix_vectorised(overlap_array,variances):
"""Create the covariance matrix for a single wavelength slice. As input takes the output of the drizzle class, overlap_array, and the variances of the individual fibres Dis been refactored by Francesco to add 0-th order vectorization. Reason is: 1) old function `create_covar_matrix` (...
ances)): if np.isfinite(overlap_array[xA+covarS,yA+covarS,f]): xC = xA +covarS + xB yC = yA + covarS + yB a = overlap_array[xA+covarS,yA+covarS,f]*np.sqrt(variances[f]) if np.isfinite(a) == False: a =...
237
237
791
14
222
rscalzo/sami
general/covar.py
Python
create_covar_matrix_vectorised
create_covar_matrix_vectorised
61
130
61
61
23a7a83cb7229614137156dee99e7b46ef1f2c6b
bigcode/the-stack
train
6ed2c280592bfc19d702c2c9
train
function
def create_covar_matrix_newest(overlap_array,variances): """Create the covariance matrix for a single wavelength slice. As input takes the output of the drizzle class, overlap_array, and the variances of the individual fibres Dis been refactored by Francesco to add 0-th order vectorization. ...
def create_covar_matrix_newest(overlap_array,variances):
"""Create the covariance matrix for a single wavelength slice. As input takes the output of the drizzle class, overlap_array, and the variances of the individual fibres Dis been refactored by Francesco to add 0-th order vectorization. Reason is: 1) old function `create_covar_matrix` (...
.isfinite(overlap_array[xA+covarS,yA+covarS,:])) if len(valid[0])>0: xC = xA +covarS + xB yC = yA + covarS + yB a = overlap_array[xA+covarS,yA+covarS,valid[0]]*np.sqrt(variances[valid]) a[np.where(~np.isfinite(a))] = 1.0 b =...
256
256
1,148
14
241
rscalzo/sami
general/covar.py
Python
create_covar_matrix_newest
create_covar_matrix_newest
134
217
134
134
886fef2eb66b3c957e4e515b4796dd78cfe81e04
bigcode/the-stack
train
7b3c1d8413d114c6f3de93bc
train
function
def clean_string(s): output_string = '' for x in s: if x != '#': output_string += x else: output_string = output_string[:-1] return output_string
def clean_string(s):
output_string = '' for x in s: if x != '#': output_string += x else: output_string = output_string[:-1] return output_string
bd" # # Your task is to process a string with "#" symbols. # # Examples # "abc#d##c" ==> "ac" # "abc##d######" ==> "" # "#######" ==> "" # "" ==> "" def clean_string(s):
64
64
45
5
59
shiishii/My-Codewars-Python-Solutions
6kyu/Backspaces in string/BackspacesInString.py
Python
clean_string
clean_string
11
18
11
11
c736a77093e829381b6095da50aaec6709b6262b
bigcode/the-stack
train
85101bf2fb44f3177119d685
train
class
class MessageTemplate(db.Document): openid = db.StringField(fefault=None) form_id = db.StringField(default=None) created_ts = db.DateTimeField(default=datetime.utcnow) meta = { 'collection': 'message_template', 'indexes': [ { 'fields': ['created_ts'], 'expireAfterSeconds':EXPIRE_AFTER_SECONDS, }...
class MessageTemplate(db.Document):
openid = db.StringField(fefault=None) form_id = db.StringField(default=None) created_ts = db.DateTimeField(default=datetime.utcnow) meta = { 'collection': 'message_template', 'indexes': [ { 'fields': ['created_ts'], 'expireAfterSeconds':EXPIRE_AFTER_SECONDS, }, ], }
#coding:utf8 from flask_wechat_utils.utils import now_ts from flask_wechat_utils.config import db from config import EXPIRE_AFTER_SECONDS from datetime import datetime class MessageTemplate(db.Document):
43
64
88
6
36
cllen/flask-wechat-utils
flask_wechat_utils/message_template/models.py
Python
MessageTemplate
MessageTemplate
8
22
8
9
bf3a327f699340e66b6eb683d1332ecdbca1d1a2
bigcode/the-stack
train
18457378e731eed22d2b8e7d
train
class
class TestGetEquivalentDtype(unittest.TestCase): @parameterized.expand(TESTS) def test_get_equivalent_dtype(self, im, input_dtype): out_dtype = get_equivalent_dtype(input_dtype, type(im)) self.assertEqual(out_dtype, im.dtype) def test_native_type(self): """the get_equivalent_dtype c...
class TestGetEquivalentDtype(unittest.TestCase): @parameterized.expand(TESTS)
def test_get_equivalent_dtype(self, im, input_dtype): out_dtype = get_equivalent_dtype(input_dtype, type(im)) self.assertEqual(out_dtype, im.dtype) def test_native_type(self): """the get_equivalent_dtype currently doesn't change the build-in type""" n_type = [float, int, bool] ...
(np.float32)] TESTS = [] for p in TEST_NDARRAYS: for im_dtype in DTYPES: TESTS.append((p(np.array(1.0, dtype=np.float32)), im_dtype)) class TestGetEquivalentDtype(unittest.TestCase): @parameterized.expand(TESTS)
64
64
127
18
46
dylanbuchi/MONAI
tests/test_get_equivalent_dtype.py
Python
TestGetEquivalentDtype
TestGetEquivalentDtype
29
41
29
30
da2b38a2c788ced1a7862023fbead47278bde532
bigcode/the-stack
train
c378c1963b2a66b069d8e4b4
train
class
class FirmwareInfraConsts(): ADMIN_STATE_TRIGGER = "trigger" ADMIN_STATE_TRIGGER_IMMEDIATE = "trigger-immediate" ADMIN_STATE_TRIGGERED = "triggered" ADMIN_STATE_UNTRIGGERED = "untriggered" ADMIN_STATE_USER_ACK = "user-ack" AUTO_DELETE_FALSE = "false" AUTO_DELETE_NO = "no" AUTO_DELETE_TRU...
class FirmwareInfraConsts():
ADMIN_STATE_TRIGGER = "trigger" ADMIN_STATE_TRIGGER_IMMEDIATE = "trigger-immediate" ADMIN_STATE_TRIGGERED = "triggered" ADMIN_STATE_UNTRIGGERED = "untriggered" ADMIN_STATE_USER_ACK = "user-ack" AUTO_DELETE_FALSE = "false" AUTO_DELETE_NO = "no" AUTO_DELETE_TRUE = "true" AUTO_DELETE_YE...
"""This module contains the general information for FirmwareInfra ManagedObject.""" from ...ucscentralmo import ManagedObject from ...ucscentralcoremeta import UcsCentralVersion, MoPropertyMeta, MoMeta from ...ucscentralmeta import VersionMeta class FirmwareInfraConsts():
55
64
174
5
49
ragupta-git/ucscentralsdk
ucscentralsdk/mometa/firmware/FirmwareInfra.py
Python
FirmwareInfraConsts
FirmwareInfraConsts
8
26
8
8
dcbe557e4e3376f2018d148cab3f1a4887d2099a
bigcode/the-stack
train
a48f1ddc7b480693ad8556f1
train
class
class FirmwareInfra(ManagedObject): """This is FirmwareInfra class.""" consts = FirmwareInfraConsts() naming_props = set([]) mo_meta = MoMeta("FirmwareInfra", "firmwareInfra", "fw-infra", VersionMeta.Version101a, "InputOutput", 0x1ff, [], ["admin"], [u'firmwareSystem'], [u'faultInst'], ["Get"]) p...
class FirmwareInfra(ManagedObject):
"""This is FirmwareInfra class.""" consts = FirmwareInfraConsts() naming_props = set([]) mo_meta = MoMeta("FirmwareInfra", "firmwareInfra", "fw-infra", VersionMeta.Version101a, "InputOutput", 0x1ff, [], ["admin"], [u'firmwareSystem'], [u'faultInst'], ["Get"]) prop_meta = { "admin_state": ...
"""This module contains the general information for FirmwareInfra ManagedObject.""" from ...ucscentralmo import ManagedObject from ...ucscentralcoremeta import UcsCentralVersion, MoPropertyMeta, MoMeta from ...ucscentralmeta import VersionMeta class FirmwareInfraConsts(): ADMIN_STATE_TRIGGER = "trigger" ADMI...
231
256
1,225
7
224
ragupta-git/ucscentralsdk
ucscentralsdk/mometa/firmware/FirmwareInfra.py
Python
FirmwareInfra
FirmwareInfra
29
89
29
29
6e91714b70e60c375a20f5369749fef95c4cf288
bigcode/the-stack
train
7ef4576b870b7e9553c6b1a2
train
function
def get_host_ref(session, cluster=None): """Get reference to a host within the cluster specified.""" if cluster is None: results = session._call_method(vim_util, "get_objects", "HostSystem") _cancel_retrieve_if_necessary(session, results) host_mor =...
def get_host_ref(session, cluster=None):
"""Get reference to a host within the cluster specified.""" if cluster is None: results = session._call_method(vim_util, "get_objects", "HostSystem") _cancel_retrieve_if_necessary(session, results) host_mor = results.objects[0].obj else: ...
by VM's consumed = int(res_usage.overallUsage / units.Mi) mem_info['free'] = mem_info['total'] - consumed stats = {'vcpus': vcpus, 'mem': mem_info} return stats def get_host_ref(session, cluster=None):
64
64
155
9
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_host_ref
get_host_ref
1,033
1,049
1,033
1,033
05572afa80c0f6b4babd176666b846c4038b75ab
bigcode/the-stack
train
47c9c4611736446ce8a7c8fc
train
function
def _get_vm_ref_from_uuid(session, instance_uuid): """Get reference to the VM with the uuid specified. This method reads all of the names of the VM's that are running on the backend, then it filters locally the matching instance_uuid. It is far more optimal to use _get_vm_ref_from_vm_uuid. """ ...
def _get_vm_ref_from_uuid(session, instance_uuid):
"""Get reference to the VM with the uuid specified. This method reads all of the names of the VM's that are running on the backend, then it filters locally the matching instance_uuid. It is far more optimal to use _get_vm_ref_from_vm_uuid. """ vms = session._call_method(vim_util, "get_objec...
_get_object_for_value) @vm_ref_cache_from_name def get_vm_ref_from_name(session, vm_name): return (_get_vm_ref_from_vm_uuid(session, vm_name) or _get_vm_ref_from_name(session, vm_name)) def _get_vm_ref_from_uuid(session, instance_uuid):
64
64
121
12
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_vm_ref_from_uuid
_get_vm_ref_from_uuid
905
916
905
905
efe3db2fb5f95103c6c1e95589688a258baec58e
bigcode/the-stack
train
41567f3f24de3e88edffa7b5
train
function
def get_stats_from_cluster(session, cluster): """Get the aggregate resource stats of a cluster.""" vcpus = 0 mem_info = {'total': 0, 'free': 0} # Get the Host and Resource Pool Managed Object Refs prop_dict = session._call_method(vim_util, "get_dynamic_properties", ...
def get_stats_from_cluster(session, cluster):
"""Get the aggregate resource stats of a cluster.""" vcpus = 0 mem_info = {'total': 0, 'free': 0} # Get the Host and Resource Pool Managed Object Refs prop_dict = session._call_method(vim_util, "get_dynamic_properties", cluster, "ClusterComputeResource", ...
_for_vm(session, instance): """Get the hostname of the ESXi host currently running an instance.""" host_ref = get_host_ref_for_vm(session, instance) return session._call_method(vim_util, "get_dynamic_property", host_ref, "HostSystem", "name") def get_vm_state(session, inst...
123
123
411
9
113
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_stats_from_cluster
get_stats_from_cluster
994
1,030
994
994
a362a94b1f0c91bd8442edce2752daaac58639f8
bigcode/the-stack
train
c50118c9bed93c5ec173c729
train
function
def get_dict_mor(session, list_obj): """The input is a list of objects in the form (manage_object,display_name) The managed object will be in the form { value = "domain-1002", _type = "ClusterComputeResource" } Output data format: | dict_mors = { | 'respool-1001': { 'cluster_mo...
def get_dict_mor(session, list_obj):
"""The input is a list of objects in the form (manage_object,display_name) The managed object will be in the form { value = "domain-1002", _type = "ClusterComputeResource" } Output data format: | dict_mors = { | 'respool-1001': { 'cluster_mor': clusterMor, | ...
# entity_path could be unique cluster and/or resource-pool name res_mor = find_entity_mor(res, entity_path) cls_mor = find_entity_mor(cls, entity_path) cls_mor.extend(res_mor) for mor in cls_mor: list_obj.append((mor.obj, mor.propSet[0].val)) return get_dict_mor(session,...
96
96
321
10
86
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_dict_mor
get_dict_mor
1,177
1,211
1,177
1,177
e739a33f9a73cecc6802680f3c0a6574f2b469fe
bigcode/the-stack
train
6cc1dcdaccc36cb1fd12a72d
train
function
def get_all_cluster_refs_by_name(session, path_list): """Get reference to the Cluster, ResourcePool with the path specified. The path is the display name. This can be the full path as well. The input will have the list of clusters and resource pool names """ cls = get_all_cluster_mors(session) ...
def get_all_cluster_refs_by_name(session, path_list):
"""Get reference to the Cluster, ResourcePool with the path specified. The path is the display name. This can be the full path as well. The input will have the list of clusters and resource pool names """ cls = get_all_cluster_mors(session) if not cls: return {} res = get_all_res_po...
entity_name): """Returns managed object ref for given cluster or resource pool name.""" return [mor for mor in entity_list if (hasattr(mor, 'propSet') and mor.propSet[0].val == entity_name)] def get_all_cluster_refs_by_name(session, path_list):
63
64
211
12
51
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_all_cluster_refs_by_name
get_all_cluster_refs_by_name
1,153
1,174
1,153
1,153
bf162b2a9c05c34ff7eee0c5e19b29218f0a185a
bigcode/the-stack
train
04a9ac1c6a1161256f13c666
train
function
def _get_object_for_value(results, value): for object in results.objects: if object.propSet[0].val == value: return object.obj
def _get_object_for_value(results, value):
for object in results.objects: if object.propSet[0].val == value: return object.obj
_get_token(results): """Get the token from the property results.""" return getattr(results, 'token', None) def _get_reference_for_value(results, value): for object in results.objects: if object.obj.value == value: return object def _get_object_for_value(results, value):
64
64
34
10
53
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_object_for_value
_get_object_for_value
851
854
851
851
cd9354edd81b6cd5ec6910f20b208fdf29a3866b
bigcode/the-stack
train
ef24256786d6c8f516d459c9
train
function
def _find_controller_slot(controller_keys, taken, max_unit_number): for controller_key in controller_keys: for unit_number in range(max_unit_number): if unit_number not in taken.get(controller_key, []): return controller_key, unit_number
def _find_controller_slot(controller_keys, taken, max_unit_number):
for controller_key in controller_keys: for unit_number in range(max_unit_number): if unit_number not in taken.get(controller_key, []): return controller_key, unit_number
_device_disk_type(vmdk_device) adapter_type = adapter_type_dict.get(vmdk_controller_key) return VmdkInfo(vmdk_file_path, adapter_type, disk_type, capacity_in_bytes, vmdk_device) def _find_controller_slot(controller_keys, taken, max_unit_number):
64
64
53
14
50
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_find_controller_slot
_find_controller_slot
528
532
528
528
2135627238afd3ec7861862569dd140aa3e5dd44
bigcode/the-stack
train
8c0bee7120428679db8c4db6
train
function
def propset_dict(propset): """Turn a propset list into a dictionary PropSet is an optional attribute on ObjectContent objects that are returned by the VMware API. You can read more about these at: | http://pubs.vmware.com/vsphere-51/index.jsp | #com.vmware.wssdk.apiref.doc/ | vmo...
def propset_dict(propset):
"""Turn a propset list into a dictionary PropSet is an optional attribute on ObjectContent objects that are returned by the VMware API. You can read more about these at: | http://pubs.vmware.com/vsphere-51/index.jsp | #com.vmware.wssdk.apiref.doc/ | vmodl.query.PropertyCollector....
", "host") if not host_ret or not host_ret.ManagedObjectReference: msg = _('No host available on cluster') raise exception.NoValidHost(reason=msg) host_mor = host_ret.ManagedObjectReference[0] return host_mor def propset_dict(propset):...
64
64
142
7
56
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
propset_dict
propset_dict
1,052
1,069
1,052
1,052
aae757d1f9f38b82588e1d2dea34babeb440b8ea
bigcode/the-stack
train
cac0b2b2831f3d78047005b8
train
function
def get_vmdk_volume_disk(hardware_devices, path=None): if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk"): if not path or path == device.b...
def get_vmdk_volume_disk(hardware_devices, path=None):
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk"): if not path or path == device.backing.fileName: return device
if (device.__class__.__name__ == "VirtualDisk" and device.backing.__class__.__name__ == "VirtualDiskFlatVer2BackingInfo" and device.backing.uuid == uuid): return device def get_vmdk_volume_disk(hardware_devices, path=None):
64
64
77
14
49
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_volume_disk
get_vmdk_volume_disk
1,096
1,103
1,096
1,096
4acd4ab98c039af62ead35402fc752890f66d953
bigcode/the-stack
train
1c70dfabb60c498a5f62afd7
train
function
def search_vm_ref_by_identifier(session, identifier): """Searches VM reference using the identifier. This method is primarily meant to separate out part of the logic for vm_ref search that could be use directly in the special case of migrating the instance. For querying VM linked to an instance always ...
def search_vm_ref_by_identifier(session, identifier):
"""Searches VM reference using the identifier. This method is primarily meant to separate out part of the logic for vm_ref search that could be use directly in the special case of migrating the instance. For querying VM linked to an instance always use get_vm_ref instead. """ vm_ref = (_get...
uuid'] vm_ref = (search_vm_ref_by_identifier(session, uuid) or _get_vm_ref_from_name(session, instance['name'])) if vm_ref is None: raise exception.InstanceNotFound(instance_id=uuid) return vm_ref def search_vm_ref_by_identifier(session, identifier):
64
64
122
10
53
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
search_vm_ref_by_identifier
search_vm_ref_by_identifier
957
968
957
957
dc0c70698a3d8a853c0e19f2db3abe689c54270d
bigcode/the-stack
train
d96ce53f5510b2e90d7308c8
train
function
def reconfigure_vm(session, vm_ref, config_spec): """Reconfigure a VM according to the config spec.""" reconfig_task = session._call_method(session.vim, "ReconfigVM_Task", vm_ref, spec=config_spec) session._wait_for_task(recon...
def reconfigure_vm(session, vm_ref, config_spec):
"""Reconfigure a VM according to the config spec.""" reconfig_task = session._call_method(session.vim, "ReconfigVM_Task", vm_ref, spec=config_spec) session._wait_for_task(reconfig_task)
sourceDatacenter=dc_ref, destName=dest) session._wait_for_task(vmdk_copy_task) LOG.debug("Copied Virtual Disk %(source)s to %(dest)s", {'source': source, 'dest': dest}) def reconfigure_vm(session, vm_ref, config_spec):
64
64
62
12
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
reconfigure_vm
reconfigure_vm
1,330
1,335
1,330
1,330
62a94ade130a3fba3a107b83c06dab1f2e70b577
bigcode/the-stack
train
04c2f108e3cabb6990184662
train
class
class CpuLimits(object): def __init__(self, cpu_limit=None, cpu_reservation=None, cpu_shares_level=None, cpu_shares_share=None): """CpuLimits object holds instance cpu limits for convenience.""" self.cpu_limit = cpu_limit self.cpu_reservation = cpu_reservation self....
class CpuLimits(object):
def __init__(self, cpu_limit=None, cpu_reservation=None, cpu_shares_level=None, cpu_shares_share=None): """CpuLimits object holds instance cpu limits for convenience.""" self.cpu_limit = cpu_limit self.cpu_reservation = cpu_reservation self.cpu_shares_level = cpu_sha...
value is the VM reference. The VM name is unique. This # is either the UUID of the instance or UUID-rescue in the case # that this is a rescue VM. This is in order to prevent # unnecessary communication with the backend. _VM_REFS_CACHE = {} class CpuLimits(object):
63
64
88
5
58
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
CpuLimits
CpuLimits
54
62
54
55
91947f142aba5c219abf48347a5bf84dce70d156
bigcode/the-stack
train
20f89c2b89fe266539571415
train
function
def get_all_res_pool_mors(session): """Get all the resource pools in the vCenter.""" try: results = session._call_method(vim_util, "get_objects", "ResourcePool") _cancel_retrieve_if_necessary(session, results) return results.objects excep...
def get_all_res_pool_mors(session):
"""Get all the resource pools in the vCenter.""" try: results = session._call_method(vim_util, "get_objects", "ResourcePool") _cancel_retrieve_if_necessary(session, results) return results.objects except Exception as excep: LOG.wa...
, "get_objects", "ClusterComputeResource", ["name"]) _cancel_retrieve_if_necessary(session, results) return results.objects except Exception as excep: LOG.warning(_LW("Failed to get cluster references %s"), excep) def get_all_res_pool_mors(session):
64
64
87
9
55
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_all_res_pool_mors
get_all_res_pool_mors
1,129
1,138
1,129
1,129
dbdeec901a857a171de20c1c8533a6b0698115ed
bigcode/the-stack
train
bdccb3c18a736a6da7bccc75
train
function
def detach_virtual_disk_spec(client_factory, device, destroy_disk=False): """Builds spec for the detach of an already existing Virtual Disk from VM. """ virtual_device_config = client_factory.create( 'ns0:VirtualDeviceConfigSpec') virtual_device_config.operation = "remove" ...
def detach_virtual_disk_spec(client_factory, device, destroy_disk=False):
"""Builds spec for the detach of an already existing Virtual Disk from VM. """ virtual_device_config = client_factory.create( 'ns0:VirtualDeviceConfigSpec') virtual_device_config.operation = "remove" if destroy_disk: virtual_device_config.fileOperation = "destroy"...
virtual_disk.controllerKey = controller_key virtual_disk.unitNumber = unit_number or 0 virtual_disk.capacityInKB = disk_size or 0 virtual_device_config.device = virtual_disk return virtual_device_config def detach_virtual_disk_spec(client_factory, device, destroy_disk=False):
64
64
90
14
49
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
detach_virtual_disk_spec
detach_virtual_disk_spec
712
722
712
712
3a759e1b7e99881f4b0bec09537f2ac07046be34
bigcode/the-stack
train
6dc13b4d4c66553a91a869f4
train
function
def get_vmdk_backed_disk_uuid(hardware_devices, volume_uuid): if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk" and device.backing.__c...
def get_vmdk_backed_disk_uuid(hardware_devices, volume_uuid):
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk" and device.backing.__class__.__name__ == "VirtualDiskFlatVer2Backing...
param propset: a property "set" from ObjectContent :return: dictionary representing property set """ if propset is None: return {} return {prop.name: prop.val for prop in propset} def get_vmdk_backed_disk_uuid(hardware_devices, volume_uuid):
64
64
103
16
48
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_backed_disk_uuid
get_vmdk_backed_disk_uuid
1,072
1,081
1,072
1,072
c0abdaba42a60ccbce4bcf05eb4cdfbee240a81f
bigcode/the-stack
train
6fd5b4fa3c101fdc8358bf39
train
function
@vm_ref_cache_from_name def get_vm_ref_from_name(session, vm_name): return (_get_vm_ref_from_vm_uuid(session, vm_name) or _get_vm_ref_from_name(session, vm_name))
@vm_ref_cache_from_name def get_vm_ref_from_name(session, vm_name):
return (_get_vm_ref_from_vm_uuid(session, vm_name) or _get_vm_ref_from_name(session, vm_name))
vms = session._call_method(vim_util, "get_objects", "VirtualMachine", ["name"]) return _get_object_from_results(session, vms, vm_name, _get_object_for_value) @vm_ref_cache_from_name def get_vm_ref_from_name(session, vm_name):
64
64
46
18
46
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vm_ref_from_name
get_vm_ref_from_name
899
902
899
900
7b412190c1a7f5c92890fbd4604287389fccc2c2
bigcode/the-stack
train
cd3ba5e706c03cfc74889919
train
function
def get_all_cluster_mors(session): """Get all the clusters in the vCenter.""" try: results = session._call_method(vim_util, "get_objects", "ClusterComputeResource", ["name"]) _cancel_retrieve_if_necessary(session, results) return results.objects ...
def get_all_cluster_mors(session):
"""Get all the clusters in the vCenter.""" try: results = session._call_method(vim_util, "get_objects", "ClusterComputeResource", ["name"]) _cancel_retrieve_if_necessary(session, results) return results.objects except Exception as excep: ...
"""Get the resource pool.""" # Get the root resource pool of the cluster res_pool_ref = session._call_method(vim_util, "get_dynamic_property", cluster, "ClusterComputeResource", ...
64
64
87
8
55
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_all_cluster_mors
get_all_cluster_mors
1,117
1,126
1,117
1,117
534f73c08132731ca2763c571b67cac174a1d30e
bigcode/the-stack
train
8f3f26ada6220e23b9606190
train
function
def get_ephemerals(session, vm_ref): devices = [] hardware_devices = session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device") if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devic...
def get_ephemerals(session, vm_ref):
devices = [] hardware_devices = session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device") if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in h...
, vm_ref, devices): """Detach specified devices from VM.""" client_factory = session.vim.client.factory config_spec = _detach_and_delete_devices_config_spec( client_factory, devices) reconfigure_vm(session, vm_ref, config_spec) def get_ephemerals(session, vm_ref):
64
64
134
10
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_ephemerals
get_ephemerals
1,460
1,475
1,460
1,460
8b5bb22acc8c127a653c1c097d1f072327d7c8c2
bigcode/the-stack
train
0c1935046057e204149dc091
train
function
def vm_ref_cache_update(id, vm_ref): _VM_REFS_CACHE[id] = vm_ref
def vm_ref_cache_update(id, vm_ref):
_VM_REFS_CACHE[id] = vm_ref
_reservation or self.cpu_limits.cpu_shares_level) def vm_refs_cache_reset(): global _VM_REFS_CACHE _VM_REFS_CACHE = {} def vm_ref_cache_delete(id): _VM_REFS_CACHE.pop(id, None) def vm_ref_cache_update(id, vm_ref):
64
64
22
10
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
vm_ref_cache_update
vm_ref_cache_update
91
92
91
91
5d13f5f4233d774a67efe61017d16e66593dcd62
bigcode/the-stack
train
4124c48a4bf5ef91ba16e891
train
function
def _get_token(results): """Get the token from the property results.""" return getattr(results, 'token', None)
def _get_token(results):
"""Get the token from the property results.""" return getattr(results, 'token', None)
. The correct fix is to handle paginated results as they are returned # from the relevant vim_util function. However, vim_util is currently # effectively deprecated as we migrate to oslo.vmware. This duplication will be # removed when we fix it properly in oslo.vmware. def _get_token(results):
64
64
26
6
58
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_token
_get_token
840
842
840
840
dd6a6b4b078da8d1a16d95b873c67f0b07fcd9e1
bigcode/the-stack
train
b284ebf9476a1717d56d5359
train
function
def _vm_ref_cache(id, func, session, data): vm_ref = vm_ref_cache_get(id) if not vm_ref: vm_ref = func(session, data) vm_ref_cache_update(id, vm_ref) return vm_ref
def _vm_ref_cache(id, func, session, data):
vm_ref = vm_ref_cache_get(id) if not vm_ref: vm_ref = func(session, data) vm_ref_cache_update(id, vm_ref) return vm_ref
): _VM_REFS_CACHE.pop(id, None) def vm_ref_cache_update(id, vm_ref): _VM_REFS_CACHE[id] = vm_ref def vm_ref_cache_get(id): return _VM_REFS_CACHE.get(id) def _vm_ref_cache(id, func, session, data):
64
64
53
13
51
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_vm_ref_cache
_vm_ref_cache
99
104
99
99
d369aadaf139baf47ea5e51be40e12c6408552eb
bigcode/the-stack
train
71ef382748c372df20215208
train
function
def _get_device_disk_type(device): if getattr(device.backing, 'thinProvisioned', False): return constants.DISK_TYPE_THIN else: if getattr(device.backing, 'eagerlyScrub', False): return constants.DISK_TYPE_EAGER_ZEROED_THICK else: return constants.DEFAULT_DISK_TYPE...
def _get_device_disk_type(device):
if getattr(device.backing, 'thinProvisioned', False): return constants.DISK_TYPE_THIN else: if getattr(device.backing, 'eagerlyScrub', False): return constants.DISK_TYPE_EAGER_ZEROED_THICK else: return constants.DEFAULT_DISK_TYPE
InKB, which has # rounding inaccuracies. Use that only if the more accurate # attribute is absent. if hasattr(device, 'capacityInBytes'): return device.capacityInBytes else: return device.capacityInKB * units.Ki def _get_device_disk_type(device):
64
64
74
8
55
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_device_disk_type
_get_device_disk_type
464
471
464
464
79c198ee038ab29ec5012732d0f271f1154767c5
bigcode/the-stack
train
7184e771e6460f71617c959b
train
function
def _detach_and_delete_devices_config_spec(client_factory, devices): config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') device_config_spec = [] for device in devices: virtual_device_config = client_factory.create( 'ns0:VirtualDeviceConfigSpec') ...
def _detach_and_delete_devices_config_spec(client_factory, devices):
config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') device_config_spec = [] for device in devices: virtual_device_config = client_factory.create( 'ns0:VirtualDeviceConfigSpec') virtual_device_config.operation = "remove" virtual_device_c...
off the VM", instance=instance) except vexc.InvalidPowerStateException: LOG.debug("VM already powered off", instance=instance) def get_ephemeral_name(id): return 'ephemeral_%d.vmdk' % id def _detach_and_delete_devices_config_spec(client_factory, devices):
64
64
112
13
50
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_detach_and_delete_devices_config_spec
_detach_and_delete_devices_config_spec
1,438
1,449
1,438
1,438
5a95afcf9b46c2d4ef8a9c5264398a803f70280d
bigcode/the-stack
train
11d9c91c4f1fc5166b91d18e
train
function
def get_vmdk_detach_config_spec(client_factory, device, destroy_disk=False): """Builds the vmdk detach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') device_config_spec = [] virtual_device_config_spec = detach_virtual_disk_spec(client...
def get_vmdk_detach_config_spec(client_factory, device, destroy_disk=False):
"""Builds the vmdk detach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') device_config_spec = [] virtual_device_config_spec = detach_virtual_disk_spec(client_factory, device, ...
_factory, datastore, controller_key, file_path, cdrom_unit_number) device_confi...
64
64
99
19
44
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_detach_config_spec
get_vmdk_detach_config_spec
424
437
424
425
302cfabfa02e904ba7c9faeadc41168d61690d43
bigcode/the-stack
train
d3258e9d0b7a773ddc6c4edc
train
function
def get_ephemeral_name(id): return 'ephemeral_%d.vmdk' % id
def get_ephemeral_name(id):
return 'ephemeral_%d.vmdk' % id
im, "PowerOffVM_Task", vm_ref) session._wait_for_task(poweroff_task) LOG.debug("Powered off the VM", instance=instance) except vexc.InvalidPowerStateException: LOG.debug("VM already powered off", instance=instance) def get_ephemeral_name(id):
64
64
21
7
57
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_ephemeral_name
get_ephemeral_name
1,434
1,435
1,434
1,434
675c7f00938eb0c6ca069b35990a9f283e8b8f0c
bigcode/the-stack
train
4c1a3ee61d541fee46a51829
train
function
def get_res_pool_ref(session, cluster): """Get the resource pool.""" # Get the root resource pool of the cluster res_pool_ref = session._call_method(vim_util, "get_dynamic_property", cluster, ...
def get_res_pool_ref(session, cluster):
"""Get the resource pool.""" # Get the root resource pool of the cluster res_pool_ref = session._call_method(vim_util, "get_dynamic_property", cluster, "ClusterComputeResource", ...
__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk"): if not path or path == device.backing.fileName: return device def get_res_pool_ref(session, cluster):
64
64
66
9
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_res_pool_ref
get_res_pool_ref
1,106
1,114
1,106
1,106
79c120916063a8f7d3fe9d4ccd921e28f6a1c07d
bigcode/the-stack
train
e0f92b28f62e22a81f149d5f
train
function
def create_virtual_disk(session, dc_ref, adapter_type, disk_type, virtual_disk_path, size_in_kb): # Create a Virtual Disk of the size of the flat vmdk file. This is # done just to generate the meta-data file whose specifics # depend on the size of the disk, thin/thick provisioning an...
def create_virtual_disk(session, dc_ref, adapter_type, disk_type, virtual_disk_path, size_in_kb): # Create a Virtual Disk of the size of the flat vmdk file. This is # done just to generate the meta-data file whose specifics # depend on the size of the disk, thin/thick provisioning an...
LOG.debug("Creating Virtual Disk of size " "%(vmdk_file_size_in_kb)s KB and adapter type " "%(adapter_type)s on the data store", {"vmdk_file_size_in_kb": size_in_kb, "adapter_type": adapter_type}) vmdk_create_spec = get_vmdk_create_spec( ses...
LOG.exception(exc, instance=instance) def create_virtual_disk(session, dc_ref, adapter_type, disk_type, virtual_disk_path, size_in_kb): # Create a Virtual Disk of the size of the flat vmdk file. This is # done just to generate the meta-data file whose specifics # depend on th...
90
90
301
81
9
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
create_virtual_disk
create_virtual_disk
1,271
1,301
1,271
1,276
c4966381c78df352d84509ce10d9ed3893f570ac
bigcode/the-stack
train
d6e6bd62c13616ee15456fdf
train
function
def _get_vm_ref_from_name(session, vm_name): """Get reference to the VM with the name specified.""" vms = session._call_method(vim_util, "get_objects", "VirtualMachine", ["name"]) return _get_object_from_results(session, vms, vm_name, _get_object_for_value...
def _get_vm_ref_from_name(session, vm_name):
"""Get reference to the VM with the name specified.""" vms = session._call_method(vim_util, "get_objects", "VirtualMachine", ["name"]) return _get_object_from_results(session, vms, vm_name, _get_object_for_value)
) else: return None def _cancel_retrieve_if_necessary(session, results): token = _get_token(results) if token: results = session._call_method(vim_util, "cancel_retrieve", token) def _get_vm_ref_from_name(...
64
64
70
12
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_vm_ref_from_name
_get_vm_ref_from_name
891
896
891
891
5bfe051a0cd51f25a7ebd65afbb428c4d197bdce
bigcode/the-stack
train
06754b3dff5b906a457a1ffd
train
function
def _is_ide_controller(device): return device.__class__.__name__ == 'VirtualIDEController'
def _is_ide_controller(device):
return device.__class__.__name__ == 'VirtualIDEController'
k_device) def _find_controller_slot(controller_keys, taken, max_unit_number): for controller_key in controller_keys: for unit_number in range(max_unit_number): if unit_number not in taken.get(controller_key, []): return controller_key, unit_number def _is_ide_controller(device)...
64
64
22
8
55
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_is_ide_controller
_is_ide_controller
535
536
535
535
0cc991db9ceed73570779b74d852179499c3f63c
bigcode/the-stack
train
962755a8c8908cff5d905175
train
function
def get_attach_port_index(session, vm_ref): """Get the first free port index.""" ports = _get_vm_port_indices(session, vm_ref) # No ports are configured on the VM if not ports: return 0 ports.sort() configured_ports_len = len(ports) # Find the first free port index for port_index...
def get_attach_port_index(session, vm_ref):
"""Get the first free port index.""" ports = _get_vm_port_indices(session, vm_ref) # No ports are configured on the VM if not ports: return 0 ports.sort() configured_ports_len = len(ports) # Find the first free port index for port_index in range(configured_ports_len): if ...
is not None: options = extra_config.OptionValue for option in options: if (option.key.startswith('nvp.iface-id.') and option.value != 'free'): ports.append(int(option.key.split('.')[2])) return ports def get_attach_port_index(session, vm_ref):
64
64
106
10
53
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_attach_port_index
get_attach_port_index
1,390
1,402
1,390
1,390
c91c0e70bec96c945ef8e4ef9b1fbf97dec1d06b
bigcode/the-stack
train
62cb2357c0b6dca2e2f57b05
train
function
def power_on_instance(session, instance, vm_ref=None): """Power on the specified instance.""" if vm_ref is None: vm_ref = get_vm_ref(session, instance) LOG.debug("Powering on the VM", instance=instance) try: poweron_task = session._call_method( sessi...
def power_on_instance(session, instance, vm_ref=None):
"""Power on the specified instance.""" if vm_ref is None: vm_ref = get_vm_ref(session, instance) LOG.debug("Powering on the VM", instance=instance) try: poweron_task = session._call_method( session.vim, "PowerOnVM_...
_spec): """Reconfigure a VM according to the config spec.""" reconfig_task = session._call_method(session.vim, "ReconfigVM_Task", vm_ref, spec=config_spec) session._wait_for_task(reconfig_task) def power_on_instance(session, i...
64
64
125
12
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
power_on_instance
power_on_instance
1,338
1,352
1,338
1,338
e7e253f9722a17d984b01c37c557abb879d6b88d
bigcode/the-stack
train
ab7d0c4ea08130065ca083c0
train
function
def _get_vm_port_indices(session, vm_ref): extra_config = session._call_method(vim_util, 'get_dynamic_property', vm_ref, 'VirtualMachine', 'config.extraConfig') ports = [] if extra_config ...
def _get_vm_port_indices(session, vm_ref):
extra_config = session._call_method(vim_util, 'get_dynamic_property', vm_ref, 'VirtualMachine', 'config.extraConfig') ports = [] if extra_config is not None: options = extra_config...
et_dict(elem.propSet) dictionary.update(propdict) token = _get_token(props) if not token: break props = session._call_method(vim_util, "continue_to_get_objects", token) return dictionary def _g...
64
64
105
11
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_vm_port_indices
_get_vm_port_indices
1,375
1,387
1,375
1,375
010147fe5e3b1a8a7c6ada6c3fcea7ba408ef925
bigcode/the-stack
train
85a1560d5ed085d07a4c2ecf
train
function
def _find_allocated_slots(devices): """Return dictionary which maps controller_key to list of allocated unit numbers for that controller_key. """ taken = {} for device in devices: if hasattr(device, 'controllerKey') and hasattr(device, 'unitNumber'): unit_numbers = taken.setdefau...
def _find_allocated_slots(devices):
"""Return dictionary which maps controller_key to list of allocated unit numbers for that controller_key. """ taken = {} for device in devices: if hasattr(device, 'controllerKey') and hasattr(device, 'unitNumber'): unit_numbers = taken.setdefault(device.controllerKey, []) ...
== 'VirtualIDEController' def _is_scsi_controller(device): return device.__class__.__name__ in ['VirtualLsiLogicController', 'VirtualLsiLogicSASController', 'VirtualBusLogicController', 'Par...
64
64
125
9
55
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_find_allocated_slots
_find_allocated_slots
546
559
546
546
a0988d008a1617688426d2a2d1ad9ed56fad7478
bigcode/the-stack
train
6856c7400a2fea0a935ed196
train
class
class ExtraSpecs(object): def __init__(self, cpu_limits=None, hw_version=None, storage_policy=None): """ExtraSpecs object holds extra_specs for the instance.""" if cpu_limits is None: cpu_limits = CpuLimits() self.cpu_limits = cpu_limits self.hw_version ...
class ExtraSpecs(object):
def __init__(self, cpu_limits=None, hw_version=None, storage_policy=None): """ExtraSpecs object holds extra_specs for the instance.""" if cpu_limits is None: cpu_limits = CpuLimits() self.cpu_limits = cpu_limits self.hw_version = hw_version self.s...
_shares_share=None): """CpuLimits object holds instance cpu limits for convenience.""" self.cpu_limit = cpu_limit self.cpu_reservation = cpu_reservation self.cpu_shares_level = cpu_shares_level self.cpu_shares_share = cpu_shares_share class ExtraSpecs(object):
64
64
110
5
58
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
ExtraSpecs
ExtraSpecs
65
79
65
66
cf4893049bfcf5fce6f49be920b6e9df040541ca
bigcode/the-stack
train
3c30f2307ef7a9b94f4b2d5f
train
function
def create_virtual_disk_spec(client_factory, controller_key, disk_type=constants.DEFAULT_DISK_TYPE, file_path=None, disk_size=None, linked_clone=False, unit_number=None, ...
def create_virtual_disk_spec(client_factory, controller_key, disk_type=constants.DEFAULT_DISK_TYPE, file_path=None, disk_size=None, linked_clone=False, unit_number=None, ...
"""Builds spec for the creation of a new/ attaching of an already existing Virtual Disk to the VM. """ virtual_device_config = client_factory.create( 'ns0:VirtualDeviceConfigSpec') virtual_device_config.operation = "add" if (file_path is None) or linked_clone: ...
cdrom_device_backing.fileName = file_path cdrom.backing = cdrom_device_backing cdrom.controllerKey = controller_key cdrom.unitNumber = cdrom_unit_number cdrom.key = -1 connectable_spec = client_factory.create('ns0:VirtualDeviceConnectInfo') connectable_spec.startConnected = True connectab...
164
164
548
46
117
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
create_virtual_disk_spec
create_virtual_disk_spec
650
709
650
656
987787b76be52486665648ddd968c016fd01bfd0
bigcode/the-stack
train
f514ae558df5828a332b27aa
train
function
def _get_object_for_optionvalue(results, value): for object in results.objects: if hasattr(object, "propSet") and object.propSet: if object.propSet[0].val.value == value: return object.obj
def _get_object_for_optionvalue(results, value):
for object in results.objects: if hasattr(object, "propSet") and object.propSet: if object.propSet[0].val.value == value: return object.obj
for object in results.objects: if object.obj.value == value: return object def _get_object_for_value(results, value): for object in results.objects: if object.propSet[0].val == value: return object.obj def _get_object_for_optionvalue(results, value):
64
64
50
11
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_object_for_optionvalue
_get_object_for_optionvalue
857
861
857
857
3827e3818f23d02f08512c86c65bcdd952d3fdf2
bigcode/the-stack
train
b241553f155c558f264b3558
train
function
def get_vnc_port(session): """Return VNC port for an VM or None if there is no available port.""" min_port = CONF.vmware.vnc_port port_total = CONF.vmware.vnc_port_total allocated_ports = _get_allocated_vnc_ports(session) max_port = min_port + port_total for port in range(min_port, max_port): ...
def get_vnc_port(session):
"""Return VNC port for an VM or None if there is no available port.""" min_port = CONF.vmware.vnc_port port_total = CONF.vmware.vnc_port_total allocated_ports = _get_allocated_vnc_ports(session) max_port = min_port + port_total for port in range(min_port, max_port): if port not in alloca...
= client_factory.create('ns0:OptionValue') opt_port.key = "RemoteDisplay.vnc.port" opt_port.value = port extras = [opt_enabled, opt_port] virtual_machine_config_spec.extraConfig = extras return virtual_machine_config_spec def get_vnc_port(session):
64
64
114
7
56
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vnc_port
get_vnc_port
797
807
797
797
e379a641f483ffa556c5cb276838070610a589c6
bigcode/the-stack
train
5ab6ec398e2a33b62ebd5570
train
function
def get_vmdk_adapter_type(adapter_type): """Return the adapter type to be used in vmdk descriptor. Adapter type in vmdk descriptor is same for LSI-SAS, LSILogic & ParaVirtual because Virtual Disk Manager API does not recognize the newer controller types. """ if adapter_type in [constants.ADAPTE...
def get_vmdk_adapter_type(adapter_type):
"""Return the adapter type to be used in vmdk descriptor. Adapter type in vmdk descriptor is same for LSI-SAS, LSILogic & ParaVirtual because Virtual Disk Manager API does not recognize the newer controller types. """ if adapter_type in [constants.ADAPTER_TYPE_LSILOGICSAS, ...
_mor(session, obj_ref, "resourcePool") dict_mors[obj_ref.value] = {'cluster_mor': obj_ref, 'res_pool_mor': res_pool_ref, 'name': path, }...
64
64
126
10
53
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_adapter_type
get_vmdk_adapter_type
1,214
1,226
1,214
1,214
f38664b1dede1a15b376e499c1b21169f994da22
bigcode/the-stack
train
d8cee2f825c3324a1eb9d10d
train
function
def _get_vm_ref_from_extraconfig(session, instance_uuid): """Get reference to the VM with the uuid specified.""" vms = session._call_method(vim_util, "get_objects", "VirtualMachine", ['config.extraConfig["nvp.vm-uuid"]']) return _get_object_from_results(session, vms, instance_uuid, ...
def _get_vm_ref_from_extraconfig(session, instance_uuid):
"""Get reference to the VM with the uuid specified.""" vms = session._call_method(vim_util, "get_objects", "VirtualMachine", ['config.extraConfig["nvp.vm-uuid"]']) return _get_object_from_results(session, vms, instance_uuid, _get_object_for_optionvalue)
session.vim, "FindAllByUuid", session.vim.service_content.searchIndex, uuid=instance_uuid, vmSearch=True, instanceUuid=True) if vm_refs: return vm_refs[0] def _get_vm_ref_from_extraconfig(session, instance_uuid):
64
64
83
15
49
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_vm_ref_from_extraconfig
_get_vm_ref_from_extraconfig
938
943
938
938
9a35c0ad5f405546250d8045c1d61efed20ea053
bigcode/the-stack
train
d58b936b281b02182ee1f11e
train
function
def vm_ref_cache_get(id): return _VM_REFS_CACHE.get(id)
def vm_ref_cache_get(id):
return _VM_REFS_CACHE.get(id)
global _VM_REFS_CACHE _VM_REFS_CACHE = {} def vm_ref_cache_delete(id): _VM_REFS_CACHE.pop(id, None) def vm_ref_cache_update(id, vm_ref): _VM_REFS_CACHE[id] = vm_ref def vm_ref_cache_get(id):
64
64
17
7
56
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
vm_ref_cache_get
vm_ref_cache_get
95
96
95
95
4b7b8208d4c8e77858de06f7f14bd90d9e603242
bigcode/the-stack
train
48af41929d8d6622ef5c43c3
train
function
def create_virtual_cdrom_spec(client_factory, datastore, controller_key, file_path, cdrom_unit_number): """Builds spec for the creation of a new Virtual CDROM to the VM.""" config_spec = clien...
def create_virtual_cdrom_spec(client_factory, datastore, controller_key, file_path, cdrom_unit_number):
"""Builds spec for the creation of a new Virtual CDROM to the VM.""" config_spec = client_factory.create( 'ns0:VirtualDeviceConfigSpec') config_spec.operation = "add" cdrom = client_factory.create('ns0:VirtualCdrom') cdrom_device_backing = client_factory.create( 'ns0:VirtualCdromIs...
Type = get_vmdk_adapter_type(adapter_type) create_vmdk_spec.diskType = disk_type create_vmdk_spec.capacityKb = size_in_kb return create_vmdk_spec def create_virtual_cdrom_spec(client_factory, datastore, controller_key, ...
71
71
238
26
44
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
create_virtual_cdrom_spec
create_virtual_cdrom_spec
617
647
617
621
33d5e486591310c5ac38f04c5e9373cf9c1448f3
bigcode/the-stack
train
3d255024fce5b6da44823574
train
function
def get_vm_create_spec(client_factory, instance, name, data_store_name, vif_infos, extra_specs, os_type=constants.DEFAULT_OS_TYPE, profile_spec=None): """Builds the VM Create spec.""" config_spec = client_factory.create('ns0:VirtualMachineConf...
def get_vm_create_spec(client_factory, instance, name, data_store_name, vif_infos, extra_specs, os_type=constants.DEFAULT_OS_TYPE, profile_spec=None):
"""Builds the VM Create spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') config_spec.name = name config_spec.guestId = os_type # The name is the unique identifier for the VM. This will either be the # instance UUID or the instance UUID with suffix '-rescue' for VM's t...
instance['uuid'] return _vm_ref_cache(id, func, session, instance) return wrapper def vm_ref_cache_from_name(func): @functools.wraps(func) def wrapper(session, name): id = name return _vm_ref_cache(id, func, session, name) return wrapper # the config key which stores the VNC ...
227
227
759
37
189
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vm_create_spec
get_vm_create_spec
138
226
138
141
36d4fe48ce063122dde6d6250c82f3e1a7d82fdc
bigcode/the-stack
train
846b9c8b0265f0c84eb95ce9
train
function
def _get_object_from_results(session, results, value, func): while results: token = _get_token(results) object = func(results, value) if object: if token: session._call_method(vim_util, "cancel_retrieve", ...
def _get_object_from_results(session, results, value, func):
while results: token = _get_token(results) object = func(results, value) if object: if token: session._call_method(vim_util, "cancel_retrieve", token) return object if t...
def _get_object_for_optionvalue(results, value): for object in results.objects: if hasattr(object, "propSet") and object.propSet: if object.propSet[0].val.value == value: return object.obj def _get_object_from_results(session, results, value, func):
64
64
96
14
49
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_object_from_results
_get_object_from_results
864
880
864
864
ef387c7e4e29f1b06e6f10dfe5ddf1c0fd1347b9
bigcode/the-stack
train
f62f96a8d1537acff4c915b1
train
function
def _get_allocated_vnc_ports(session): """Return an integer set of all allocated VNC ports.""" # TODO(rgerganov): bug #1256944 # The VNC port should be unique per host, not per vCenter vnc_ports = set() result = session._call_method(vim_util, "get_objects", "Virtual...
def _get_allocated_vnc_ports(session):
"""Return an integer set of all allocated VNC ports.""" # TODO(rgerganov): bug #1256944 # The VNC port should be unique per host, not per vCenter vnc_ports = set() result = session._call_method(vim_util, "get_objects", "VirtualMachine", [VNC_CONFIG_KEY]) while r...
) max_port = min_port + port_total for port in range(min_port, max_port): if port not in allocated_ports: return port raise exception.ConsolePortRangeExhausted(min_port=min_port, max_port=max_port) def _get_allocated_vnc_ports(session):
64
64
193
10
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_allocated_vnc_ports
_get_allocated_vnc_ports
810
832
810
810
4812d97c8528587f77534bfb5a39b7498bb52f62
bigcode/the-stack
train
82c31a044f4df75655c63295
train
function
def get_network_attach_config_spec(client_factory, vif_info, index): """Builds the vif attach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') vif_spec = _create_vif_spec(client_factory, vif_info) config_spec.deviceChange = [vif_spec] if vif_info['iface_id'] is not...
def get_network_attach_config_spec(client_factory, vif_info, index):
"""Builds the vif attach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') vif_spec = _create_vif_spec(client_factory, vif_info) config_spec.deviceChange = [vif_spec] if vif_info['iface_id'] is not None: config_spec.extraConfig = [_iface_id_option_value(clie...
net_device.key = -47 net_device.addressType = "manual" net_device.macAddress = mac_address net_device.wakeOnLanEnabled = True network_spec.device = net_device return network_spec def get_network_attach_config_spec(client_factory, vif_info, index):
64
64
107
14
49
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_network_attach_config_spec
get_network_attach_config_spec
337
346
337
337
bfe4a3cc649d1391757edf3e306b8acbbd7a71d0
bigcode/the-stack
train
c531de10fe404ddc4b689d8a
train
function
def get_vm_state(session, instance): vm_ref = get_vm_ref(session, instance) vm_state = session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "runtime.powerState") return vm_state
def get_vm_state(session, instance):
vm_ref = get_vm_ref(session, instance) vm_state = session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "runtime.powerState") return vm_state
instance): """Get the hostname of the ESXi host currently running an instance.""" host_ref = get_host_ref_for_vm(session, instance) return session._call_method(vim_util, "get_dynamic_property", host_ref, "HostSystem", "name") def get_vm_state(session, instance):
64
64
54
8
56
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vm_state
get_vm_state
987
991
987
987
f18f49bb293178959d2e7461469d8bdc665e1be9
bigcode/the-stack
train
5ed1d0446b970d34694e9df4
train
function
def get_vm_detach_port_index(session, vm_ref, iface_id): extra_config = session._call_method(vim_util, 'get_dynamic_property', vm_ref, 'VirtualMachine', 'config.extraConfig') if extra_config i...
def get_vm_detach_port_index(session, vm_ref, iface_id):
extra_config = session._call_method(vim_util, 'get_dynamic_property', vm_ref, 'VirtualMachine', 'config.extraConfig') if extra_config is not None: options = extra_config.OptionValue ...
configured_ports_len = len(ports) # Find the first free port index for port_index in range(configured_ports_len): if port_index != ports[port_index]: return port_index return configured_ports_len def get_vm_detach_port_index(session, vm_ref, iface_id):
64
64
100
15
48
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vm_detach_port_index
get_vm_detach_port_index
1,405
1,415
1,405
1,405
0e908d2485f9627087a77db0714dd4f1d14687ac
bigcode/the-stack
train
c5ae241d6b2702573a9b3b68
train
function
def detach_devices_from_vm(session, vm_ref, devices): """Detach specified devices from VM.""" client_factory = session.vim.client.factory config_spec = _detach_and_delete_devices_config_spec( client_factory, devices) reconfigure_vm(session, vm_ref, config_spec)
def detach_devices_from_vm(session, vm_ref, devices):
"""Detach specified devices from VM.""" client_factory = session.vim.client.factory config_spec = _detach_and_delete_devices_config_spec( client_factory, devices) reconfigure_vm(session, vm_ref, config_spec)
virtual_device_config.operation = "remove" virtual_device_config.device = device virtual_device_config.fileOperation = "destroy" device_config_spec.append(virtual_device_config) config_spec.deviceChange = device_config_spec return config_spec def detach_devices_from_vm(session, v...
64
64
60
12
51
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
detach_devices_from_vm
detach_devices_from_vm
1,452
1,457
1,452
1,452
618da81d54b84633ecf3a4b366ea78a021b21719
bigcode/the-stack
train
ecacc60b43948249aa8571db
train
function
def get_vmdk_backed_disk_device(hardware_devices, uuid): if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk" and device.backing.__class_...
def get_vmdk_backed_disk_device(hardware_devices, uuid):
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk" and device.backing.__class__.__name__ == "VirtualDiskFlatVer2Backing...
__.__name__ == "VirtualDisk" and device.backing.__class__.__name__ == "VirtualDiskFlatVer2BackingInfo" and volume_uuid in device.backing.fileName): return device.backing.uuid def get_vmdk_backed_disk_device(hardware_devices, uuid):
64
64
97
15
48
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_backed_disk_device
get_vmdk_backed_disk_device
1,084
1,093
1,084
1,084
4182034c5f98123a355ca192c1e15629f62f063a
bigcode/the-stack
train
a85b347007699b66de30fccc
train
function
def copy_virtual_disk(session, dc_ref, source, dest): """Copy a sparse virtual disk to a thin virtual disk. This is also done to generate the meta-data file whose specifics depend on the size of the disk, thin/thick provisioning and the storage adapter type. :param session: - session for c...
def copy_virtual_disk(session, dc_ref, source, dest):
"""Copy a sparse virtual disk to a thin virtual disk. This is also done to generate the meta-data file whose specifics depend on the size of the disk, thin/thick provisioning and the storage adapter type. :param session: - session for connection :param dc_ref: - data center reference o...
) LOG.debug("Created Virtual Disk of size %(vmdk_file_size_in_kb)s" " KB and type %(disk_type)s", {"vmdk_file_size_in_kb": size_in_kb, "disk_type": disk_type}) def copy_virtual_disk(session, dc_ref, source, dest):
68
68
228
13
55
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
copy_virtual_disk
copy_virtual_disk
1,304
1,327
1,304
1,304
d3228b80eb970cad0505713477a3505b37bdced9
bigcode/the-stack
train
095da7175ab2b62afa55acf8
train
function
def get_values_from_object_properties(session, props): """Get the specific values from a object list. The object values will be returned as a dictionary. """ dictionary = {} while props: for elem in props.objects: propdict = propset_dict(elem.propSet) dictionary.upda...
def get_values_from_object_properties(session, props):
"""Get the specific values from a object list. The object values will be returned as a dictionary. """ dictionary = {} while props: for elem in props.objects: propdict = propset_dict(elem.propSet) dictionary.update(propdict) token = _get_token(props) ...
"PowerOnVM_Task", vm_ref) session._wait_for_task(poweron_task) LOG.debug("Powered on the VM", instance=instance) except vexc.InvalidPowerStateException: LOG.debug("VM already powered on", instance=instance) def get_values_from_object_properties(session, props):
64
64
107
10
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_values_from_object_properties
get_values_from_object_properties
1,355
1,372
1,355
1,355
5853851daddf97cd25301d025aeb80f71c7875a7
bigcode/the-stack
train
10bfd4c0d9b972e4a1276cfb
train
function
def relocate_vm_spec(client_factory, datastore=None, host=None, disk_move_type="moveAllDiskBackingsAndAllowSharing"): """Builds the VM relocation spec.""" rel_spec = client_factory.create('ns0:VirtualMachineRelocateSpec') rel_spec.datastore = datastore rel_spec.diskMoveType = disk_m...
def relocate_vm_spec(client_factory, datastore=None, host=None, disk_move_type="moveAllDiskBackingsAndAllowSharing"):
"""Builds the VM relocation spec.""" rel_spec = client_factory.create('ns0:VirtualMachineRelocateSpec') rel_spec.datastore = datastore rel_spec.diskMoveType = disk_move_type if host: rel_spec.host = host return rel_spec
if snapshot: clone_spec.snapshot = snapshot if config is not None: clone_spec.config = config clone_spec.template = template return clone_spec def relocate_vm_spec(client_factory, datastore=None, host=None, disk_move_type="moveAllDiskBackingsAndAllowSharing"):
64
64
88
27
36
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
relocate_vm_spec
relocate_vm_spec
739
747
739
740
947072126c2adc0938f50c941dd0ae06c13ffe26
bigcode/the-stack
train
bbfc57805d16877e2a5b33bd
train
function
def _get_vm_ref_from_vm_uuid(session, instance_uuid): """Get reference to the VM. The method will make use of FindAllByUuid to get the VM reference. This method finds all VM's on the backend that match the instance_uuid, more specifically all VM's on the backend that have 'config_spec.instanceUuid'...
def _get_vm_ref_from_vm_uuid(session, instance_uuid):
"""Get reference to the VM. The method will make use of FindAllByUuid to get the VM reference. This method finds all VM's on the backend that match the instance_uuid, more specifically all VM's on the backend that have 'config_spec.instanceUuid' set to 'instance_uuid'. """ vm_refs = session...
_vm_uuid. """ vms = session._call_method(vim_util, "get_objects", "VirtualMachine", ["name"]) return _get_object_from_results(session, vms, instance_uuid, _get_object_for_value) def _get_vm_ref_from_vm_uuid(session, instance_uuid):
64
64
140
13
51
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_vm_ref_from_vm_uuid
_get_vm_ref_from_vm_uuid
919
935
919
919
a449da8e21ab2965d4ff52510d5df5c888a8870f
bigcode/the-stack
train
f16f2c3cc4f57f3de09e04a1
train
function
def create_controller_spec(client_factory, key, adapter_type=constants.DEFAULT_ADAPTER_TYPE): """Builds a Config Spec for the LSI or Bus Logic Controller's addition which acts as the controller for the virtual hard disk to be attached to the VM. """ # Create a controller f...
def create_controller_spec(client_factory, key, adapter_type=constants.DEFAULT_ADAPTER_TYPE):
"""Builds a Config Spec for the LSI or Bus Logic Controller's addition which acts as the controller for the virtual hard disk to be attached to the VM. """ # Create a controller for the Virtual Hard Disk virtual_device_config = client_factory.create( 'ns0:VirtualDevic...
_factory, vcpus, memory_mb): """Provides updates for a VM spec.""" resize_spec = client_factory.create('ns0:VirtualMachineConfigSpec') resize_spec.numCPUs = vcpus resize_spec.memoryMB = memory_mb return resize_spec def create_controller_spec(client_factory, key, adapter_ty...
78
78
261
19
58
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
create_controller_spec
create_controller_spec
237
263
237
238
0dc66fda3456d60861652a0e0de7fa47973474a7
bigcode/the-stack
train
cab95bb1532168e8b0c7dce7
train
function
def get_host_name_for_vm(session, instance): """Get the hostname of the ESXi host currently running an instance.""" host_ref = get_host_ref_for_vm(session, instance) return session._call_method(vim_util, "get_dynamic_property", host_ref, "HostSystem", "name")
def get_host_name_for_vm(session, instance):
"""Get the hostname of the ESXi host currently running an instance.""" host_ref = get_host_ref_for_vm(session, instance) return session._call_method(vim_util, "get_dynamic_property", host_ref, "HostSystem", "name")
"""Get a MoRef to the ESXi host currently running an instance.""" vm_ref = get_vm_ref(session, instance) return session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "runtime.host") def get_host_name_for_vm(session, instance):
64
64
64
10
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_host_name_for_vm
get_host_name_for_vm
979
984
979
979
cf91d8888bfa953d475960cb90fd7f6a827e14d8
bigcode/the-stack
train
170b7cae636ab5bcf221cf05
train
function
def clone_vm_spec(client_factory, location, power_on=False, snapshot=None, template=False, config=None): """Builds the VM clone spec.""" clone_spec = client_factory.create('ns0:VirtualMachineCloneSpec') clone_spec.location = location clone_spec.powerOn = power_on if snapshot: ...
def clone_vm_spec(client_factory, location, power_on=False, snapshot=None, template=False, config=None):
"""Builds the VM clone spec.""" clone_spec = client_factory.create('ns0:VirtualMachineCloneSpec') clone_spec.location = location clone_spec.powerOn = power_on if snapshot: clone_spec.snapshot = snapshot if config is not None: clone_spec.config = config clone_spec.template = t...
ConfigSpec') virtual_device_config.operation = "remove" if destroy_disk: virtual_device_config.fileOperation = "destroy" virtual_device_config.device = device return virtual_device_config def clone_vm_spec(client_factory, location, power_on=False, snapshot=None, template=False...
64
64
101
23
40
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
clone_vm_spec
clone_vm_spec
725
736
725
726
8ad4fb41c9b8f251c4c5487b00e310e375db325a
bigcode/the-stack
train
87e766d08536c15e6ae632ef
train
function
def power_off_instance(session, instance, vm_ref=None): """Power off the specified instance.""" if vm_ref is None: vm_ref = get_vm_ref(session, instance) LOG.debug("Powering off the VM", instance=instance) try: poweroff_task = session._call_method(session.vim, ...
def power_off_instance(session, instance, vm_ref=None):
"""Power off the specified instance.""" if vm_ref is None: vm_ref = get_vm_ref(session, instance) LOG.debug("Powering off the VM", instance=instance) try: poweroff_task = session._call_method(session.vim, "PowerOffVM_Task", vm_ref) sessi...
if extra_config is not None: options = extra_config.OptionValue for option in options: if (option.key.startswith('nvp.iface-id.') and option.value == iface_id): return int(option.key.split('.')[2]) def power_off_instance(session, instance, vm_ref=None):
64
64
123
12
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
power_off_instance
power_off_instance
1,418
1,431
1,418
1,418
59b11ebb62a0a2e1be0f1bbda78303a1907f3b04
bigcode/the-stack
train
b62c9455a6347e1c8c38a691
train
function
def get_machine_id_change_spec(client_factory, machine_id_str): """Builds the machine id change config spec.""" virtual_machine_config_spec = client_factory.create( 'ns0:VirtualMachineConfigSpec') opt = client_factory.create('ns0:OptionValue') opt.key = "machine.id" ...
def get_machine_id_change_spec(client_factory, machine_id_str):
"""Builds the machine id change config spec.""" virtual_machine_config_spec = client_factory.create( 'ns0:VirtualMachineConfigSpec') opt = client_factory.create('ns0:OptionValue') opt.key = "machine.id" opt.value = machine_id_str virtual_machine_config_spec.ext...
rel_spec = client_factory.create('ns0:VirtualMachineRelocateSpec') rel_spec.datastore = datastore rel_spec.diskMoveType = disk_move_type if host: rel_spec.host = host return rel_spec def get_machine_id_change_spec(client_factory, machine_id_str):
64
64
91
13
50
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_machine_id_change_spec
get_machine_id_change_spec
750
759
750
750
e887577321284d200a66996441303ae073f68582
bigcode/the-stack
train
35b02f7d0ba888abd2abdf03
train
function
def _get_device_capacity(device): # Devices pre-vSphere-5.5 only reports capacityInKB, which has # rounding inaccuracies. Use that only if the more accurate # attribute is absent. if hasattr(device, 'capacityInBytes'): return device.capacityInBytes else: return device.capacityInKB * ...
def _get_device_capacity(device): # Devices pre-vSphere-5.5 only reports capacityInKB, which has # rounding inaccuracies. Use that only if the more accurate # attribute is absent.
if hasattr(device, 'capacityInBytes'): return device.capacityInBytes else: return device.capacityInKB * units.Ki
extra_config.append(opt) config_spec.extraConfig = extra_config return config_spec def _get_device_capacity(device): # Devices pre-vSphere-5.5 only reports capacityInKB, which has # rounding inaccuracies. Use that only if the more accurate # attribute is absent.
64
64
76
45
18
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_device_capacity
_get_device_capacity
454
461
454
457
a65e3d60c0d782bdad31833ba56164bbef8180e0
bigcode/the-stack
train
fb8e2bc2256fd6f7d325e86f
train
function
def get_add_vswitch_port_group_spec(client_factory, vswitch_name, port_group_name, vlan_id): """Builds the virtual switch port group add spec.""" vswitch_port_group_spec = client_factory.create('ns0:HostPortGroupSpec') vswitch_port_group_spec.name = port_group_name vs...
def get_add_vswitch_port_group_spec(client_factory, vswitch_name, port_group_name, vlan_id):
"""Builds the virtual switch port group add spec.""" vswitch_port_group_spec = client_factory.create('ns0:HostPortGroupSpec') vswitch_port_group_spec.name = port_group_name vswitch_port_group_spec.vswitchName = vswitch_name # VLAN ID of 0 means that VLAN tagging is not to be done for the network. ...
('ns0:OptionValue') opt.key = "machine.id" opt.value = machine_id_str virtual_machine_config_spec.extraConfig = [opt] return virtual_machine_config_spec def get_add_vswitch_port_group_spec(client_factory, vswitch_name, port_group_name, vlan_id):
64
64
185
23
40
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_add_vswitch_port_group_spec
get_add_vswitch_port_group_spec
762
778
762
763
2a278c81f95890ca9891efcbca224ed760f19c86
bigcode/the-stack
train
ad0885739e4aa583ad1b6251
train
function
def find_entity_mor(entity_list, entity_name): """Returns managed object ref for given cluster or resource pool name.""" return [mor for mor in entity_list if (hasattr(mor, 'propSet') and mor.propSet[0].val == entity_name)]
def find_entity_mor(entity_list, entity_name):
"""Returns managed object ref for given cluster or resource pool name.""" return [mor for mor in entity_list if (hasattr(mor, 'propSet') and mor.propSet[0].val == entity_name)]
def get_dynamic_property_mor(session, mor_ref, attribute): """Get the value of an attribute for a given managed object.""" return session._call_method(vim_util, "get_dynamic_property", mor_ref, mor_ref._type, attribute) def find_entity_mor(entity_list, entity_name):
64
64
59
11
53
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
find_entity_mor
find_entity_mor
1,147
1,150
1,147
1,147
336bad6ac261160b85d18efc4ba9dec61f670471
bigcode/the-stack
train
8190ebf8e84a61ebb34db2cd
train
function
def _create_vif_spec(client_factory, vif_info): """Builds a config spec for the addition of a new network adapter to the VM. """ network_spec = client_factory.create('ns0:VirtualDeviceConfigSpec') network_spec.operation = "add" # Keep compatible with other Hyper vif model parameter. vif_inf...
def _create_vif_spec(client_factory, vif_info):
"""Builds a config spec for the addition of a new network adapter to the VM. """ network_spec = client_factory.create('ns0:VirtualDeviceConfigSpec') network_spec.operation = "add" # Keep compatible with other Hyper vif model parameter. vif_info['vif_model'] = convert_vif_model(vif_info['vif...
'ns0:VirtualLsiLogicController') virtual_controller.key = key virtual_controller.busNumber = 0 virtual_controller.sharedBus = "noSharing" virtual_device_config.device = virtual_controller return virtual_device_config def convert_vif_model(name): """Converts stan...
164
164
549
12
151
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_create_vif_spec
_create_vif_spec
278
334
278
278
5ec09839d26e689f64053947822644da3d3ad387
bigcode/the-stack
train
e241c566e30fbbeaf5cf9013
train
function
def convert_vif_model(name): """Converts standard VIF_MODEL types to the internal VMware ones.""" if name == network_model.VIF_MODEL_E1000: return 'VirtualE1000' if name == network_model.VIF_MODEL_E1000E: return 'VirtualE1000e' if name not in ALL_SUPPORTED_NETWORK_DEVICES: msg = ...
def convert_vif_model(name):
"""Converts standard VIF_MODEL types to the internal VMware ones.""" if name == network_model.VIF_MODEL_E1000: return 'VirtualE1000' if name == network_model.VIF_MODEL_E1000E: return 'VirtualE1000e' if name not in ALL_SUPPORTED_NETWORK_DEVICES: msg = _('%s is not supported.') % n...
= client_factory.create( 'ns0:VirtualLsiLogicController') virtual_controller.key = key virtual_controller.busNumber = 0 virtual_controller.sharedBus = "noSharing" virtual_device_config.device = virtual_controller return virtual_device_config def convert_vif_model(nam...
64
64
100
7
56
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
convert_vif_model
convert_vif_model
266
275
266
266
e5e0e0d03234fbb48146e09f8654e16ae20c1d61
bigcode/the-stack
train
44eacdf1e16a75d9351495fe
train
function
def get_vmdk_create_spec(client_factory, size_in_kb, adapter_type=constants.DEFAULT_ADAPTER_TYPE, disk_type=constants.DEFAULT_DISK_TYPE): """Builds the virtual disk create spec.""" create_vmdk_spec = client_factory.create('ns0:FileBackedVirtualDiskSpec') cre...
def get_vmdk_create_spec(client_factory, size_in_kb, adapter_type=constants.DEFAULT_ADAPTER_TYPE, disk_type=constants.DEFAULT_DISK_TYPE):
"""Builds the virtual disk create spec.""" create_vmdk_spec = client_factory.create('ns0:FileBackedVirtualDiskSpec') create_vmdk_spec.adapterType = get_vmdk_adapter_type(adapter_type) create_vmdk_spec.diskType = disk_type create_vmdk_spec.capacityKb = size_in_kb return create_vmdk_spec
== "VirtualDiskRawDiskMappingVer1BackingInfo" and device.backing.lunUuid == uuid): return device def get_vmdk_create_spec(client_factory, size_in_kb, adapter_type=constants.DEFAULT_ADAPTER_TYPE, disk_type=constants.DEFAULT_DI...
64
64
118
35
28
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_create_spec
get_vmdk_create_spec
606
614
606
608
8e1ea1638a90ee56f8285ab14f5cc8b354169f4d
bigcode/the-stack
train
fc1f6a3306d686579fa2b617
train
function
def vm_ref_cache_from_instance(func): @functools.wraps(func) def wrapper(session, instance): id = instance['uuid'] return _vm_ref_cache(id, func, session, instance) return wrapper
def vm_ref_cache_from_instance(func): @functools.wraps(func)
def wrapper(session, instance): id = instance['uuid'] return _vm_ref_cache(id, func, session, instance) return wrapper
, func, session, data): vm_ref = vm_ref_cache_get(id) if not vm_ref: vm_ref = func(session, data) vm_ref_cache_update(id, vm_ref) return vm_ref def vm_ref_cache_from_instance(func): @functools.wraps(func)
64
64
49
17
46
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
vm_ref_cache_from_instance
vm_ref_cache_from_instance
107
112
107
108
da9df2e4d67e47cbdb19568e59c749af8e1ab96f
bigcode/the-stack
train
dec436ef1ba112d0c620795d
train
function
def create_vm(session, instance, vm_folder, config_spec, res_pool_ref): """Create VM on ESX host.""" LOG.debug("Creating VM on the ESX host", instance=instance) vm_create_task = session._call_method( session.vim, "CreateVM_Task", vm_folder, config=config_spec, pool=res_pool_ref) ...
def create_vm(session, instance, vm_folder, config_spec, res_pool_ref):
"""Create VM on ESX host.""" LOG.debug("Creating VM on the ESX host", instance=instance) vm_create_task = session._call_method( session.vim, "CreateVM_Task", vm_folder, config=config_spec, pool=res_pool_ref) try: task_info = session._wait_for_task(vm_create_task) exce...
Virtual because Virtual Disk Manager API does not recognize the newer controller types. """ if adapter_type in [constants.ADAPTER_TYPE_LSILOGICSAS, constants.ADAPTER_TYPE_PARAVIRTUAL]: vmdk_adapter_type = constants.DEFAULT_ADAPTER_TYPE else: vmdk_adapter_type ...
97
97
326
17
79
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
create_vm
create_vm
1,229
1,254
1,229
1,229
810e29d173ce63c7e77d66b54f2ace6944352d89
bigcode/the-stack
train
631bce767fb99d37ae455f24
train
function
def get_rdm_disk(hardware_devices, uuid): """Gets the RDM disk key.""" if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk" and device.ba...
def get_rdm_disk(hardware_devices, uuid):
"""Gets the RDM disk key.""" if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice for device in hardware_devices: if (device.__class__.__name__ == "VirtualDisk" and device.backing.__class__.__name__ == ...
1], None # create new controller with the specified type and return its spec controller_key = -101 controller_spec = create_controller_spec(client_factory, controller_key, adapter_type) return controller_key, 0, controller_spec def get_rdm_disk(hardware_devi...
64
64
106
11
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_rdm_disk
get_rdm_disk
593
603
593
593
b6bb34f664b3dd97b79e3510dd6fda74a0bf3dec
bigcode/the-stack
train
ed90d1d7e73bc280b99d1794
train
function
def get_network_detach_config_spec(client_factory, device, port_index): """Builds the vif detach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') virtual_device_config = client_factory.create( 'ns0:VirtualDeviceConfigSpec') virtual_device_co...
def get_network_detach_config_spec(client_factory, device, port_index):
"""Builds the vif detach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') virtual_device_config = client_factory.create( 'ns0:VirtualDeviceConfigSpec') virtual_device_config.operation = "remove" virtual_device_config.device = device ...
.deviceChange = [vif_spec] if vif_info['iface_id'] is not None: config_spec.extraConfig = [_iface_id_option_value(client_factory, vif_info['iface_id'], index)] return config_spec def get_n...
64
64
206
15
48
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_network_detach_config_spec
get_network_detach_config_spec
349
366
349
349
f1e477130cc74456717ab29ea8295ecf253a0a54
bigcode/the-stack
train
974efa6913ebab922fe03578
train
function
def get_host_ref_for_vm(session, instance): """Get a MoRef to the ESXi host currently running an instance.""" vm_ref = get_vm_ref(session, instance) return session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "runtime.host")
def get_host_ref_for_vm(session, instance):
"""Get a MoRef to the ESXi host currently running an instance.""" vm_ref = get_vm_ref(session, instance) return session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "runtime.host")
_ref instead. """ vm_ref = (_get_vm_ref_from_vm_uuid(session, identifier) or _get_vm_ref_from_extraconfig(session, identifier) or _get_vm_ref_from_uuid(session, identifier)) return vm_ref def get_host_ref_for_vm(session, instance):
64
64
64
10
53
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_host_ref_for_vm
get_host_ref_for_vm
971
976
971
971
b116bdb144789017dbade7e30867ea45f3b31fed
bigcode/the-stack
train
d7f3197b1930349c6beac2d8
train
function
def _cancel_retrieve_if_necessary(session, results): token = _get_token(results) if token: results = session._call_method(vim_util, "cancel_retrieve", token)
def _cancel_retrieve_if_necessary(session, results):
token = _get_token(results) if token: results = session._call_method(vim_util, "cancel_retrieve", token)
._call_method(vim_util, "cancel_retrieve", token) return object if token: results = session._call_method(vim_util, "continue_to_get_objects", ...
64
64
44
12
51
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_cancel_retrieve_if_necessary
_cancel_retrieve_if_necessary
883
888
883
883
88218af15341b405392e425b9056a33a1277d463
bigcode/the-stack
train
38c485231047c685097cb1a1
train
function
def get_vm_extra_config_spec(client_factory, extra_opts): """Builds extra spec fields from a dictionary.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') # add the key value pairs extra_config = [] for key, value in extra_opts.iteritems(): opt = client_factory.create('n...
def get_vm_extra_config_spec(client_factory, extra_opts):
"""Builds extra spec fields from a dictionary.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') # add the key value pairs extra_config = [] for key, value in extra_opts.iteritems(): opt = client_factory.create('ns0:OptionValue') opt.key = key opt.value =...
device_config_spec = [] virtual_device_config_spec = detach_virtual_disk_spec(client_factory, device, destroy_disk) device_config_spec.append(virtual_device_config_spec) config_spec.devi...
64
64
107
12
51
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vm_extra_config_spec
get_vm_extra_config_spec
440
451
440
440
b68e1fc72aa857fda291ac793af505dceda84238
bigcode/the-stack
train
71c24db0a8dce73ba056fb77
train
function
def destroy_vm(session, instance, vm_ref=None): """Destroy a VM instance. Assumes VM is powered off.""" try: if not vm_ref: vm_ref = get_vm_ref(session, instance) LOG.debug("Destroying the VM", instance=instance) destroy_task = session._call_method(session.vim, "Destroy_Task"...
def destroy_vm(session, instance, vm_ref=None):
"""Destroy a VM instance. Assumes VM is powered off.""" try: if not vm_ref: vm_ref = get_vm_ref(session, instance) LOG.debug("Destroying the VM", instance=instance) destroy_task = session._call_method(session.vim, "Destroy_Task", vm...
)s\'. An invalid os type may be ' 'one cause of this instance creation failure'), {'ostype': config_spec.guestId}) LOG.debug("Created VM on the ESX host", instance=instance) return task_info.result def destroy_vm(session, instance, vm_ref=None):
64
64
117
11
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
destroy_vm
destroy_vm
1,257
1,268
1,257
1,257
6c32d93b802808b5e525a0a813c3fa8b460e4ae1
bigcode/the-stack
train
9b7f7aca94efc79c403f8402
train
function
def get_vmdk_attach_config_spec(client_factory, disk_type=constants.DEFAULT_DISK_TYPE, file_path=None, disk_size=None, linked_clone=False, controller_key=None, ...
def get_vmdk_attach_config_spec(client_factory, disk_type=constants.DEFAULT_DISK_TYPE, file_path=None, disk_size=None, linked_clone=False, controller_key=None, ...
"""Builds the vmdk attach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') device_config_spec = [] virtual_device_config_spec = create_virtual_disk_spec(client_factory, controller_key, disk_type, file_path, ...
Id = profile_id.uniqueId return storage_profile_spec def get_vmdk_attach_config_spec(client_factory, disk_type=constants.DEFAULT_DISK_TYPE, file_path=None, disk_size=None, linked_clone...
64
64
148
51
12
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_attach_config_spec
get_vmdk_attach_config_spec
380
400
380
387
4957b29ce161d0b4c0e0ddaaa89ee68b315c67b5
bigcode/the-stack
train
39ca41d009c1c0ac54eee09f
train
function
def get_cdrom_attach_config_spec(client_factory, datastore, file_path, controller_key, cdrom_unit_number): """Builds and returns the cdrom attach config spec.""" config_spec = clie...
def get_cdrom_attach_config_spec(client_factory, datastore, file_path, controller_key, cdrom_unit_number):
"""Builds and returns the cdrom attach config spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') device_config_spec = [] virtual_device_config_spec = create_virtual_cdrom_spec(client_factory, datastore, ...
, linked_clone, unit_number, device_name) device_config_spec.append(virtual_device_config_spec) config_spec.deviceChange = device_config_spec return config_spec def get_cdrom_attach_config_spec(client_factory, datastore, ...
64
64
119
27
36
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_cdrom_attach_config_spec
get_cdrom_attach_config_spec
403
421
403
407
8d8fa1797e31554d588ebbf2d3afab061d7d1f78
bigcode/the-stack
train
4ec50afcefa56c8c702cdd23
train
function
def vm_ref_cache_from_name(func): @functools.wraps(func) def wrapper(session, name): id = name return _vm_ref_cache(id, func, session, name) return wrapper
def vm_ref_cache_from_name(func): @functools.wraps(func)
def wrapper(session, name): id = name return _vm_ref_cache(id, func, session, name) return wrapper
_ref_cache_from_instance(func): @functools.wraps(func) def wrapper(session, instance): id = instance['uuid'] return _vm_ref_cache(id, func, session, instance) return wrapper def vm_ref_cache_from_name(func): @functools.wraps(func)
64
64
47
17
46
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
vm_ref_cache_from_name
vm_ref_cache_from_name
115
120
115
116
91b566de3336928906b19462d027745b93f4e96d
bigcode/the-stack
train
fc745bd55410cfc9584e5dd4
train
function
def get_vnc_config_spec(client_factory, port): """Builds the vnc config spec.""" virtual_machine_config_spec = client_factory.create( 'ns0:VirtualMachineConfigSpec') opt_enabled = client_factory.create('ns0:OptionValue') opt_enabled.key = "RemoteDisplay.vnc.enabled" ...
def get_vnc_config_spec(client_factory, port):
"""Builds the vnc config spec.""" virtual_machine_config_spec = client_factory.create( 'ns0:VirtualMachineConfigSpec') opt_enabled = client_factory.create('ns0:OptionValue') opt_enabled.key = "RemoteDisplay.vnc.enabled" opt_enabled.value = "true" opt_port = c...
aming = client_factory.create('ns0:HostNicTeamingPolicy') nicteaming.notifySwitches = True policy.nicTeaming = nicteaming vswitch_port_group_spec.policy = policy return vswitch_port_group_spec def get_vnc_config_spec(client_factory, port):
64
64
135
11
52
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vnc_config_spec
get_vnc_config_spec
781
794
781
781
80d669b9fac488dc0739d2f120563a7261d68618
bigcode/the-stack
train
6d82785a3af710656e8b1d0b
train
function
@vm_ref_cache_from_instance def get_vm_ref(session, instance): """Get reference to the VM through uuid or vm name.""" uuid = instance['uuid'] vm_ref = (search_vm_ref_by_identifier(session, uuid) or _get_vm_ref_from_name(session, instance['name'])) if vm_ref is None: raise exception...
@vm_ref_cache_from_instance def get_vm_ref(session, instance):
"""Get reference to the VM through uuid or vm name.""" uuid = instance['uuid'] vm_ref = (search_vm_ref_by_identifier(session, uuid) or _get_vm_ref_from_name(session, instance['name'])) if vm_ref is None: raise exception.InstanceNotFound(instance_id=uuid) return vm_ref
_method(vim_util, "get_objects", "VirtualMachine", ['config.extraConfig["nvp.vm-uuid"]']) return _get_object_from_results(session, vms, instance_uuid, _get_object_for_optionvalue) @vm_ref_cache_from_instance def get_vm_ref(session, instance):
64
64
87
15
49
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vm_ref
get_vm_ref
946
954
946
947
5df1d848b723d23a78f23adfb8821e668c796bf0
bigcode/the-stack
train
20fd2e4e7c4d1ae926b135e1
train
function
def get_storage_profile_spec(session, storage_policy): """Gets the vm profile spec configured for storage policy.""" profile_id = pbm.get_profile_id_by_name(session, storage_policy) if profile_id: client_factory = session.vim.client.factory storage_profile_spec = client_factory.create( ...
def get_storage_profile_spec(session, storage_policy):
"""Gets the vm profile spec configured for storage policy.""" profile_id = pbm.get_profile_id_by_name(session, storage_policy) if profile_id: client_factory = session.vim.client.factory storage_profile_spec = client_factory.create( 'ns0:VirtualMachineDefinedProfileSpec') ...
wiring # according to these values. If they are changed then this will # break networking to and from the interface. config_spec.extraConfig = [_iface_id_option_value(client_factory, 'free', port_ind...
64
64
91
10
53
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_storage_profile_spec
get_storage_profile_spec
369
377
369
369
6da04485f78f58ce26bf6836df0360d971fc0a29
bigcode/the-stack
train
5962f938562e7768e4a6934a
train
function
def allocate_controller_key_and_unit_number(client_factory, devices, adapter_type): """This function inspects the current set of hardware devices and returns controller_key and unit_number that can be used for attaching a new virtual disk to adapter with the given...
def allocate_controller_key_and_unit_number(client_factory, devices, adapter_type):
"""This function inspects the current set of hardware devices and returns controller_key and unit_number that can be used for attaching a new virtual disk to adapter with the given adapter_type. """ if devices.__class__.__name__ == "ArrayOfVirtualDevice": devices = devices.VirtualDevice ...
'unitNumber'): unit_numbers = taken.setdefault(device.controllerKey, []) unit_numbers.append(device.unitNumber) if _is_scsi_controller(device): # the SCSI controller sits on its own bus unit_numbers = taken.setdefault(device.key, []) unit_numbers.appe...
86
86
287
16
69
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
allocate_controller_key_and_unit_number
allocate_controller_key_and_unit_number
562
590
562
563
f67a52533990cafe3b7307f7f9af5d0d03992743
bigcode/the-stack
train
3454b86a02d456377f5f6a9f
train
function
def vm_ref_cache_delete(id): _VM_REFS_CACHE.pop(id, None)
def vm_ref_cache_delete(id):
_VM_REFS_CACHE.pop(id, None)
def has_cpu_limits(self): return bool(self.cpu_limits.cpu_limit or self.cpu_limits.cpu_reservation or self.cpu_limits.cpu_shares_level) def vm_refs_cache_reset(): global _VM_REFS_CACHE _VM_REFS_CACHE = {} def vm_ref_cache_delete(id):
63
64
18
7
56
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
vm_ref_cache_delete
vm_ref_cache_delete
87
88
87
87
94a24efbfbbaff0d9d805a070c66f6f33cd39170
bigcode/the-stack
train
07f809d33164eec784d07d64
train
function
def _is_scsi_controller(device): return device.__class__.__name__ in ['VirtualLsiLogicController', 'VirtualLsiLogicSASController', 'VirtualBusLogicController', 'ParaVirtualSCSIController']
def _is_scsi_controller(device):
return device.__class__.__name__ in ['VirtualLsiLogicController', 'VirtualLsiLogicSASController', 'VirtualBusLogicController', 'ParaVirtualSCSIController']
controller_keys: for unit_number in range(max_unit_number): if unit_number not in taken.get(controller_key, []): return controller_key, unit_number def _is_ide_controller(device): return device.__class__.__name__ == 'VirtualIDEController' def _is_scsi_controller(device):
64
64
49
8
56
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_is_scsi_controller
_is_scsi_controller
539
543
539
539
589b4d2af2cad3391f103f206cc534c60ba1573f
bigcode/the-stack
train
2d32d08ed8c133b9d5d1d81d
train
function
def get_vm_resize_spec(client_factory, vcpus, memory_mb): """Provides updates for a VM spec.""" resize_spec = client_factory.create('ns0:VirtualMachineConfigSpec') resize_spec.numCPUs = vcpus resize_spec.memoryMB = memory_mb return resize_spec
def get_vm_resize_spec(client_factory, vcpus, memory_mb):
"""Provides updates for a VM spec.""" resize_spec = client_factory.create('ns0:VirtualMachineConfigSpec') resize_spec.numCPUs = vcpus resize_spec.memoryMB = memory_mb return resize_spec
_factory.create('ns0:ManagedByInfo') managed_by.extensionKey = constants.EXTENSION_KEY managed_by.type = constants.EXTENSION_TYPE_INSTANCE config_spec.managedBy = managed_by return config_spec def get_vm_resize_spec(client_factory, vcpus, memory_mb):
64
64
65
15
48
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vm_resize_spec
get_vm_resize_spec
229
234
229
229
758fe38d25bb82df8a4d4ef2443da8716c8b228b
bigcode/the-stack
train
942e764a0669a44f8d9341c0
train
function
def get_dynamic_property_mor(session, mor_ref, attribute): """Get the value of an attribute for a given managed object.""" return session._call_method(vim_util, "get_dynamic_property", mor_ref, mor_ref._type, attribute)
def get_dynamic_property_mor(session, mor_ref, attribute):
"""Get the value of an attribute for a given managed object.""" return session._call_method(vim_util, "get_dynamic_property", mor_ref, mor_ref._type, attribute)
get_objects", "ResourcePool") _cancel_retrieve_if_necessary(session, results) return results.objects except Exception as excep: LOG.warning(_LW("Failed to get resource pool references " "%s"), excep) def get_dynamic_property_mor(session, mor_ref,...
64
64
53
13
51
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_dynamic_property_mor
get_dynamic_property_mor
1,141
1,144
1,141
1,141
0c5f8018cd767569787ade35ccfddf05e4e5229e
bigcode/the-stack
train
35aa52d1b3427984f7d95a3e
train
function
def get_vmdk_info(session, vm_ref, uuid=None): """Returns information for the primary VMDK attached to the given VM.""" hardware_devices = session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device") if hardware_devices.__class__.__name__...
def get_vmdk_info(session, vm_ref, uuid=None):
"""Returns information for the primary VMDK attached to the given VM.""" hardware_devices = session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device") if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_de...
def _get_device_capacity(device): # Devices pre-vSphere-5.5 only reports capacityInKB, which has # rounding inaccuracies. Use that only if the more accurate # attribute is absent. if hasattr(device, 'capacityInBytes'): return device.capacityInBytes else: return device.capacityInKB...
165
165
551
14
150
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
get_vmdk_info
get_vmdk_info
474
525
474
474
44cf919824304ac55fcfa872442d0ac00c89f1bc
bigcode/the-stack
train
5499ebf91e6d80c875aae26e
train
function
def _get_reference_for_value(results, value): for object in results.objects: if object.obj.value == value: return object
def _get_reference_for_value(results, value):
for object in results.objects: if object.obj.value == value: return object
# effectively deprecated as we migrate to oslo.vmware. This duplication will be # removed when we fix it properly in oslo.vmware. def _get_token(results): """Get the token from the property results.""" return getattr(results, 'token', None) def _get_reference_for_value(results, value):
64
64
29
10
54
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_get_reference_for_value
_get_reference_for_value
845
848
845
845
478d4a8ac275c9323ec543691cb185cdcba81bb3
bigcode/the-stack
train
963819626e8e3e4e5395e048
train
function
def vm_refs_cache_reset(): global _VM_REFS_CACHE _VM_REFS_CACHE = {}
def vm_refs_cache_reset():
global _VM_REFS_CACHE _VM_REFS_CACHE = {}
self.cpu_limits = cpu_limits self.hw_version = hw_version self.storage_policy = storage_policy def has_cpu_limits(self): return bool(self.cpu_limits.cpu_limit or self.cpu_limits.cpu_reservation or self.cpu_limits.cpu_shares_level) def vm_refs_cache_r...
64
64
22
6
58
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
vm_refs_cache_reset
vm_refs_cache_reset
82
84
82
82
48293f2b003416bb82d375376a0b5154526781a9
bigcode/the-stack
train
1301d50c2ca809e9fcc42abf
train
function
def _iface_id_option_value(client_factory, iface_id, port_index): opt = client_factory.create('ns0:OptionValue') opt.key = "nvp.iface-id.%d" % port_index opt.value = iface_id return opt
def _iface_id_option_value(client_factory, iface_id, port_index):
opt = client_factory.create('ns0:OptionValue') opt.key = "nvp.iface-id.%d" % port_index opt.value = iface_id return opt
'config.extraConfig["RemoteDisplay.vnc.port"]' VmdkInfo = collections.namedtuple('VmdkInfo', ['path', 'adapter_type', 'disk_type', 'capacity_in_bytes', 'device']) def _iface_id_...
63
64
56
15
48
orbitfp7/nova
nova/virt/vmwareapi/vm_util.py
Python
_iface_id_option_value
_iface_id_option_value
131
135
131
131
d4755b7e532fe9459933033217cefb567d624730
bigcode/the-stack
train
eb46731f789764f677b7ec3b
train
function
def main(argv=None) -> int: initialize() return package_manager.run(**vars(package_manager.parse_args(argv)))
def main(argv=None) -> int:
initialize() return package_manager.run(**vars(package_manager.parse_args(argv)))
_package.packages import nanopb from pw_package.packages import protobuf # pylint: disable=unused-import from pw_package.packages import stm32cube # pylint: disable=unused-import def initialize(): package_manager.register(nanopb.NanoPB) def main(argv=None) -> int:
64
64
24
8
56
octml/pigweed
pw_package/py/pw_package/pigweed_packages.py
Python
main
main
35
37
35
35
b00c891edd62788a3f55d2fa972c35a31298cf0e
bigcode/the-stack
train
7d6afa0a5cd44f29402781c7
train
function
def initialize(): package_manager.register(nanopb.NanoPB)
def initialize():
package_manager.register(nanopb.NanoPB)
from pw_package.packages import micro_ecc # pylint: disable=unused-import from pw_package.packages import nanopb from pw_package.packages import protobuf # pylint: disable=unused-import from pw_package.packages import stm32cube # pylint: disable=unused-import def initialize():
64
64
15
3
60
octml/pigweed
pw_package/py/pw_package/pigweed_packages.py
Python
initialize
initialize
31
32
31
31
0b09ebe4f94a48ca2b0457416f8c5954e4d02eb3
bigcode/the-stack
train
ca298a78f9be5a6d82b65e5a
train
class
class ServicePackageQuotaHistoryServicePackage(object): """ NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. """ """ Attributes: swagger_types (dict): The key is attribute name and the value is attribute...
class ServicePackageQuotaHistoryServicePackage(object):
""" NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. """ """ Attributes: swagger_types (dict): The key is attribute name and the value is attribute type. attribute_map (dict): The key is attribute ...
# coding: utf-8 """ Billing API Billing API allows users to retrieve billing reports and service package details. OpenAPI spec version: 1.4.7 Generated by: https://github.com/swagger-api/swagger-codegen.git """ from pprint import pformat from six import iteritems import re class ServicePackage...
79
256
1,420
9
69
GQMai/mbed-cloud-sdk-python
src/mbed_cloud/_backends/billing/models/service_package_quota_history_service_package.py
Python
ServicePackageQuotaHistoryServicePackage
ServicePackageQuotaHistoryServicePackage
19
235
19
19
176b67e82bd3246f343e9d15637eb43dc9dda778
bigcode/the-stack
train
fb38b76443a4c430f1741ad6
train
function
def get_action_num(): return 3
def get_action_num():
return 3
7, 8], [7, 8, 9], [8, 9, 10], [9, 10, 11], [10, 11]] # In our case, we have 3 actions (stay, go-left, go-right) def get_action_num():
64
64
10
5
59
jooncco/coindrop-game-ai-agent
project/q_learning_.py
Python
get_action_num
get_action_num
28
29
28
28
442c2168e37d0689bb11dd2e0786580e800f70d6
bigcode/the-stack
train
587fc868142236e1c403510f
train
function
def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument("-n", "--num_episode", help="# of the episode (size of training data)", type=int, required=True) parser.add_argument("-e", "--epsilon", help="the probability of random movement, 0~1", ...
def main():
import argparse parser = argparse.ArgumentParser() parser.add_argument("-n", "--num_episode", help="# of the episode (size of training data)", type=int, required=True) parser.add_argument("-e", "--epsilon", help="the probability of random movement, 0~1", type...
, score, game_info, params): epsilon = params[0] policy = make_policy(Q, epsilon, get_action_num()) action_probs = policy(get_state(counter, score, game_info)) action = np.random.choice(np.arange(len(action_probs)), p=action_probs) return action def main():
66
66
223
3
62
jooncco/coindrop-game-ai-agent
project/q_learning_.py
Python
main
main
245
270
245
245
a6af6d63f45c3718960fc058e70d2ac8c502e21a
bigcode/the-stack
train
ced7fd438950f310abc77f8d
train
function
def get_state(counter, score, game_info): basket_location, item_location = game_info def howMany(y, item_info, x_tuple): count = 0 for item in item_info: if item[2] == y and item[1] in x_tuple: count += 1 return count def isGreedy(game_info):...
def get_state(counter, score, game_info):
basket_location, item_location = game_info def howMany(y, item_info, x_tuple): count = 0 for item in item_info: if item[2] == y and item[1] in x_tuple: count += 1 return count def isGreedy(game_info): state = max_value = 0 # ...
, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [9, 10, 11], [10, 11]] # In our case, we have 3 actions (stay, go-left, go-right) def get_action_num(): return 3 ## this function return policy function to choose the action based on Q value. def make_policy(Q, epsilon, nA): def policy_fn(observation)...
188
188
629
10
178
jooncco/coindrop-game-ai-agent
project/q_learning_.py
Python
get_state
get_state
41
128
41
41
687ecbbb21ff1d78cd318f5b2b3e3de1f9d0a08a
bigcode/the-stack
train