Often there are situation where deployment will get stuck in progress or We lost control to manage the deployment using GUI. In those situation we can utilize the APIs and get the task done.
But for VRA8 taking the bearer token is bit tedious task as we need to obtain 2 different token then make it as bearer token. To make it easier I have created Python Module where you just need to provide the Admin credentials and perform the operation .
No need to worry about if you are not from python background or do not know code, Just follow the below instruction and we are goodย
To start the Process we need to meet the pre-requisites which are explain in below steps.
- Please follow the detailed instruction Here python installation and required module before we use this module –Do not skip this step.
- Download the file from Above and unzip and copy the file by name VRA8 and paste the file in directory where python is installed
general path in windows is : C:\Users\Administrator\AppData\Local\Programs\Python\Python39 - I am using Python 3.9 for example ,It will be different as per your version.
- Once the step 1-3 is completed , all we need to do is run the below commands.
from VRA8 import vraClass
as1 =vraClass(vrafqdn="vra82.vmwarecode.com", username="ankush", password="VMware123!",domain='vmwarecode.com')
as1.getDeployments()
as1.getDeployments() – We need to get the deployment ID from the list.

As we see , I have total 2 deployment in my environment and Now I will trigger the delete deployment request for deployment name Tag test 101 for that ID is -599f853d-4519-4c5f-b220-fd49bde3880e.
as1.deleteDeployment(id="599f853d-4519-4c5f-b220-fd49bde3880e")
Here response 202 means API has been triggered to delete . Now if we do getDeployment() again we only see 1 entry.

There are some additional function also which are part of this python module
Like getBlueprint() & releaseBlueprint()
Here is the quick look of both of them
as1.getBlueprint()
as1.releaseBlueprint(id="cf9641b4-0242-4555-abae-26d8b72f542d", version=11)

Happy Learning , Feel free to share your queries and feedback on this .
Update: 9th October : Added domain user support in class, previously it was just local users.
6 responses to “How to delete deployment in VRA 8 using Python(API)”
[…] I have written article where I showed how to remove the deployment from VRA if those are stuck here .Recently I have come across the situation where we do not have deployment but machines are stuck […]
LikeLike
I have implemented and it worked.
But on event of CREATE_FAILED of deployment how to use in Extensibility or VRO Workflow to use this Python script
LikeLike
Hi
Thanks for the useful log , when tryin the execute the script in my vra lab I got the following error :
Line 40, in getDeployments= ‘authorization’: self.vratoken()
line 29, in vratoken refreshtoken = apioutput.json()[‘refresh_token’]
do you have any idea about the root cause i dont no find any related any related information
LikeLike
It was due to domain user, Previous code only allows local user , With updated code now we can authenticate against domain user too
LikeLiked by 1 person
Thats what I did to make it working and find the root cause , thanks to Postman app it helped me ๐
LikeLike
Hi Ankush, New to python and getting below error:
(.venv) PS C:\Users\PAM-0038-SrvrAdm07\python-module> & c:/Users/PAM-0038-SrvrAdm07/python-module/.venv/Scripts/python.exe c:/Users/PAM-0038-SrvrAdm07/python-module/test.py
400
{‘timestamp’: 1695702430207, ‘type’: ‘CLIENT_ERROR’, ‘status’: ‘400 BAD_REQUEST’, ‘error’: ‘Bad Request’, ‘serverMessage’: ‘REST error received: {\n “error”: “invalid_grant”,\n “error_description”: “Invalid username or pass
word”\n}, status code: 400 BAD_REQUEST’}
Traceback (most recent call last):
File “C:\Users\PAM-0038-SrvrAdm07\python-module\.venv\lib\site-packages\requests\models.py”, line 910, in json
return complexjson.loads(self.text, **kwargs)
File “C:\ProgramData\python36\lib\json\__init__.py”, line 354, in loads
return _default_decoder.decode(s)
File “C:\ProgramData\python36\lib\json\decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\ProgramData\python36\lib\json\decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “c:/Users/PAM-0038-SrvrAdm07/python-module/test.py”, line 3, in
as1.getDeployments()
File “c:\Users\PAM-0038-SrvrAdm07\python-module\VRA8.py”, line 52, in getDeployments
api_output = requests.get(url, headers=headers, verify=False).json()[‘content’]
File “C:\Users\PAM-0038-SrvrAdm07\python-module\.venv\lib\site-packages\requests\models.py”, line 917, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
Running this from VScode using python extension
LikeLike