Skip to content

Commit

Permalink
Changed Vm create/update terminology for CPU allocation to aid in tra…
Browse files Browse the repository at this point in the history
…nsparency. Changed terminology to core/socket rather than vcpu/socket
  • Loading branch information
grdavies-ntnx committed Jun 2, 2021
1 parent 933ac6d commit adb22a4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ A log of changes by version and date.
:header: "Version", "Date", "Notes"
:widths: 10, 10, 60

"1.4.3", "6/1/2021", "Changed Vm create/update terminology for CPU allocation to aid in transparency. Changed terminology to core/socket rather than vcpu/socket."
"1.4.2", "6/1/2021", "Updated vCPU/socket calculation for Vms.update to match that in Vms.create."
"1.4.1", "6/1/2021", "Updated Images.search_uuid to also check for a match with the uuid of the image disk."
"1.4.0", "5/20/2021", "Added functions to the VMs class for CRUD operations to related to the management of virtual machines. Added function to the VolumeGroups class for CRUD operations to related to the management of volumes and volume groups."
Expand Down
2 changes: 1 addition & 1 deletion ntnx_api/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module module

__version_info__ = ('1', '4', '2')
__version_info__ = ('1', '4', '3')
__version__ = '.'.join(__version_info__)
40 changes: 19 additions & 21 deletions ntnx_api/prism.py
Original file line number Diff line number Diff line change
Expand Up @@ -3033,7 +3033,7 @@ def _vm_serial_port_spec(port_index:int=None, port_type:str='null', **kwargs):

return serial_port

def create(self, name:str, vcpus:int, memory_gb:int, sockets:int=1, vcpu_reservation_hz:int=0, memory_reservation_gb:int=0, description:str='',
def create(self, name:str, cores:int, memory_gb:int, sockets:int=1, vcpu_reservation_hz:int=0, memory_reservation_gb:int=0, description:str='',
power_state:str='on', disks:list=[], storage_container_uuid:str=None, nics:list=[], gpus:list=[], serial_ports:list=[], timezone:str='UTC',
sysprep:str=None, cloudinit:str=None, add_cdrom:bool=True, ha_priority:int=0, machine_type:str='pc', wait:bool=True, clusteruuid:str=None):
""" Create a new virtual machine.
Expand All @@ -3042,12 +3042,12 @@ def create(self, name:str, vcpus:int, memory_gb:int, sockets:int=1, vcpu_reserva
:type name: str
:param description: A description for the VM (default='')
:type description: str, optional
:param vcpus: The number of vCPUs to be assigned to this VM
:type vcpus: int
:param memory_gb: The amount of memory in GB to be assigne to this VM
:type memory_gb: int
:param cores: The number of virtual CPU cores per virtual CPU socket
:type cores: int
:param sockets: The number of virtual CPU sockets to distribute the defined vCPUs over (default=1)
:type sockets: int, optional
:param memory_gb: The amount of memory in GB to be assigne to this VM
:type memory_gb: int
:param vcpu_reservation_hz: A CPU reservation in hz for this VM. Only applicable on the ESXi hypervisor. (default=0)
:type vcpu_reservation_hz: int, optional
:param memory_reservation_gb: An amount of memory to lock to this VM. Only applicable on the ESXi hypervisor. (default=0)
Expand Down Expand Up @@ -3154,8 +3154,8 @@ def create(self, name:str, vcpus:int, memory_gb:int, sockets:int=1, vcpu_reserva
'name': name,
'description': description,
'memory_mb': int(bm_memory_mb),
'num_vcpus': cores,
'sockets': sockets,
'num_vcpus': (vcpus/sockets),
'power_state': 'OFF',
'timezone': timezone,
'ha_priority': ha_priority,
Expand Down Expand Up @@ -4054,7 +4054,7 @@ def power_state(self, uuid:str, desired_state:str='on', wait:bool=True, clusteru
else:
return False

def update_name(self, name:str, new_name:str=None, vcpus:int=None, memory_gb:int=None, sockets:int=None, vcpu_reservation_hz:int=None,
def update_name(self, name:str, new_name:str=None, cores:int=None, sockets:int=None, memory_gb:int=None, vcpu_reservation_hz:int=None,
memory_reservation_gb:int=None, description:str=None, disks:list=[], nics:list=[], gpus:list=[], serial_ports:list=[], timezone:str=None,
add_cdrom:bool=None, ha_priority:int=None, force:bool=False, wait:bool=True, clusteruuid:str=None):
"""Updates a specific virtual machine by the vm name provided.
Expand All @@ -4063,12 +4063,12 @@ def update_name(self, name:str, new_name:str=None, vcpus:int=None, memory_gb:int
:type name: str
:param new_name: A new name for the virtual machine.
:type new_name: str, optional
:param vcpus: The number of vCPUs to be assigned to this VM
:type vcpus: int
:param memory_gb: The amount of memory in GB to be assigne to this VM
:type memory_gb: int
:param cores: The number of virtual CPU cores per virtual CPU socket
:type cores: int
:param sockets: The number of virtual CPU sockets to distribute the defined vCPUs over (default=1)
:type sockets: int, optional
:param memory_gb: The amount of memory in GB to be assigne to this VM
:type memory_gb: int
:param vcpu_reservation_hz: A CPU reservation in hz for this VM. Only applicable on the ESXi hypervisor. (default=0)
:type vcpu_reservation_hz: int, optional
:param memory_reservation_gb: An amount of memory to lock to this VM. Only applicable on the ESXi hypervisor. (default=0)
Expand Down Expand Up @@ -4157,7 +4157,7 @@ def update_name(self, name:str, new_name:str=None, vcpus:int=None, memory_gb:int
vm_config = {
'uuid': vm.get('uuid'),
'new_name': new_name,
'vcpus': vcpus,
'cores': cores,
'memory_gb': memory_gb,
'sockets': sockets,
'vcpu_reservation_hz': vcpu_reservation_hz,
Expand All @@ -4178,7 +4178,7 @@ def update_name(self, name:str, new_name:str=None, vcpus:int=None, memory_gb:int
else:
raise ValueError()

def update_uuid(self, uuid:str, new_name:str=None, vcpus:int=None, memory_gb:int=None, sockets:int=None, vcpu_reservation_hz:int=None,
def update_uuid(self, uuid:str, new_name:str=None, cores:int=None, sockets:int=None, memory_gb:int=None, vcpu_reservation_hz:int=None,
memory_reservation_gb:int=None, description:str=None, disks:list=[], nics:list=[], gpus:list=[], serial_ports:list=[], timezone:str=None,
add_cdrom:bool=None, ha_priority:int=None, force:bool=False, wait:bool=True, clusteruuid:str=None):
"""Updates a specific virtual machine by the uuid provided
Expand All @@ -4187,10 +4187,10 @@ def update_uuid(self, uuid:str, new_name:str=None, vcpus:int=None, memory_gb:int
:type uuid: str
:param new_name: A new name for the virtual machine.
:type new_name: str, optional
:param vcpus: The number of vCPUs to be assigned to this VM
:type vcpus: int
:param memory_gb: The amount of memory in GB to be assigne to this VM
:type memory_gb: int
:param cores: The number of virtual CPU cores per virtual CPU socket
:type cores: int
:param sockets: The number of virtual CPU sockets to distribute the defined vCPUs over (default=1)
:type sockets: int, optional
:param vcpu_reservation_hz: A CPU reservation in hz for this VM. Only applicable on the ESXi hypervisor. (default=0)
Expand Down Expand Up @@ -4305,15 +4305,13 @@ def update_uuid(self, uuid:str, new_name:str=None, vcpus:int=None, memory_gb:int
bm_memory_mb = bm_memory_gb.to_MB()
payload['memory_mb'] = int(bm_memory_mb)

if sockets:
if cores:
required_power_state = 'off'
payload['sockets'] = sockets
else:
sockets = vm.get('sockets')
payload['num_vcpus'] = cores

if vcpus:
if sockets:
required_power_state = 'off'
payload['num_vcpus'] = (vcpus/sockets)
payload['sockets'] = sockets

if timezone:
payload['timezone'] = timezone
Expand Down
18 changes: 9 additions & 9 deletions ntnx_api/test/prism/test_prism_vms_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_vm_create_with_vdisks():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_vm_create_with_vdisk_nic():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_nic_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_vm_create_with_vdisk_nic_ipam():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_nic_ipam_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_return_v2_vm_create_with_vdisk_nic_ipam_ip():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_nic_ipam_ip_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_vm_create_from_image_nic_ipam():
result = False
vm_config = {
'name': 'api_test_v2_image_nic_ipam_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_vm_create_from_image_vg_nic_ipam():
result = False
vm_config = {
'name': 'api_test_v2_image_vg_nic_ipam_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_vm_create_failure():
result = False
vm_config = {
'name': 'api_test_v2_failure_{0}'.format(random_string),
'vcpus': 16,
'cores': 16,
'memory_gb': 128,
'add_cdrom': True,
'disks': [
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_vm_clone():
result = False
vm_config = {
'name': 'api_test_v2_clone_original_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -316,7 +316,7 @@ def test_vm_clone():
vm_clone_config_2 = {
'source_name': 'api_test_v2_clone_original_{0}'.format(random_string),
'name': 'api_test_v2_clone_2_{0}'.format(random_string),
'vcpus': 2,
'cores': 2,
'memory_gb': 128,
}
results.append(vms_obj.clone_name(clusteruuid=each_uuid, **vm_clone_config_2))
Expand Down
18 changes: 9 additions & 9 deletions ntnx_api/test/prism/test_prism_vms_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_vm_create_with_vdisks():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_vm_create_with_vdisk_nic():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_nic_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_vm_create_with_vdisk_nic_ipam():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_nic_ipam_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_return_v2_vm_create_with_vdisk_nic_ipam_ip():
result = False
vm_config = {
'name': 'api_test_v2_vdisk_nic_ipam_ip_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_vm_create_from_image_nic_ipam():
result = False
vm_config = {
'name': 'api_test_v2_image_nic_ipam_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_vm_create_from_image_vg_nic_ipam():
result = False
vm_config = {
'name': 'api_test_v2_image_vg_nic_ipam_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_vm_create_failure():
result = False
vm_config = {
'name': 'api_test_v2_failure_{0}'.format(random_string),
'vcpus': 16,
'cores': 16,
'memory_gb': 128,
'add_cdrom': True,
'disks': [
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_vm_clone():
result = False
vm_config = {
'name': 'api_test_v2_clone_original_{0}'.format(random_string),
'vcpus': 1,
'cores': 1,
'memory_gb': 0.1,
'add_cdrom': True,
'power_state': 'off',
Expand Down Expand Up @@ -316,7 +316,7 @@ def test_vm_clone():
vm_clone_config_2 = {
'source_name': 'api_test_v2_clone_original_{0}'.format(random_string),
'name': 'api_test_v2_clone_2_{0}'.format(random_string),
'vcpus': 2,
'cores': 2,
'memory_gb': 128,
}
results.append(vms_obj.clone_name(clusteruuid=each_uuid, **vm_clone_config_2))
Expand Down

0 comments on commit adb22a4

Please sign in to comment.