vsphere-automation-sdk-python icon indicating copy to clipboard operation
vsphere-automation-sdk-python copied to clipboard

Update existing vm cpu, memory, power state

Open littleccguy opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I love this python SDK. I am able to teardown and recreate vms using clone_task, and it makes my life so much easier. However, that is only part of what I need. I need to modify the new vms after they are created.

Describe the solution you'd like

  • Get the power state of the vm
  • Power off if necessary
  • Update CPU count
  • Update cores_per_socket
  • Update memory either in MB or GB
  • Power on

Describe alternatives you've considered

No response

Additional context

No response

littleccguy avatar Jan 08 '22 10:01 littleccguy

I believe I was able to solve my issue. Here is what I did in case someone else needs this as well.

usrPass = "{}:{}".format(args.username, args.password.value) base64String = base64.b64encode(bytes(usrPass, 'ascii')).decode('ascii') print(base64String) api_response = session.post(url="https://{}/api/session".format(args.server), headers={"Authorization": "Basic {}".format(base64String), "Connection": "keep-alive", "Accept": "*/*", "Accept-Encoding": "gzip, deflate, br"}) api_key = api_response.text.strip("\"")

vsphere_client = create_vsphere_client(server=args.server, username=args.username, password=args.password.value, session=session)

vsphere_client.session.headers.update({"vmware-api-session-id": api_key})

At this poini, I can do things like get, and patch vsphere_client.session.get(url="https://{}/api/vcenter/vm/{}/hardware/cpu".format(args.server, vm_id) )

littleccguy avatar Jan 11 '22 19:01 littleccguy