Solved

Deleting the decommissioned VMs from commvault using the rest api

  • 11 March 2024
  • 5 replies
  • 73 views

Badge +5

I have to remove/Delete the VM from commvault using the Rest API

https://api.commvault.com/docs/api/cv/OpenAPI3/delete-virtual-machine

 

I have tried test running the api using python and I got the below mentioned error:

C:\Users\Ansible_user\Downloads>python vmdel.py WIN-C6TBRLJG6IM <commandcenter username> <commandcenter password

import requests
import urllib

#proxies={
#'http':'http://10.***.***.***:8080',
#'https':'http://10.***.***.***:8080'
#}
url = "https://win-c6tbrljg6im/commandcenter/api/V4/VirtualMachines/:<VM UUID>"

payload={}
headers = {
'Accept': 'application/json',
'Authtoken': '*******'
}

response = requests.request("GET", url, headers=headers, data=payload, proxies=urllib.request.getproxies())

print(response.text)

>
Traceback (most recent call last):
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\connectionpool.py", line 779, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\connectionpool.py", line 1048, in _prepare_proxy
    conn.connect()
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\connection.py", line 633, in connect
    self._tunnel()  # type: ignore[attr-defined]
    ^^^^^^^^^^^^^^
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\http\client.py", line 973, in _tunnel
    raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
OSError: Tunnel connection failed: 502 Bad Gateway

The above exception was the direct cause of the following exception:

urllib3.exceptions.ProxyError: ('Unable to connect to proxy', OSError('Tunnel connection failed: 502 Bad Gateway'))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\connectionpool.py", line 847, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\util\retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='win-c6tbrljg6im', port=443): Max retries exceeded with url: /commandcenter/api/V4/VirtualMachines/ (Caused by ProxyError('Unable to connect to proxy', OSError('Tunnel connection failed: 502 Bad Gateway')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Ansible_user\Downloads\vmdel.py", line 16, in <module>
    response = requests.request("GET", url, headers=headers, data=payload, proxies=urllib.request.getproxies())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ansible_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\adapters.py", line 513, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='win-c6tbrljg6im', port=443): Max retries exceeded with url: /commandcenter/api/V4/VirtualMachines/ (Caused by ProxyError('Unable to connect to proxy', OSError('Tunnel connection failed: 502 Bad Gateway')))

icon

Best answer by RandomCustomer 13 March 2024, 11:18

View original

5 replies

Userlevel 4
Badge +11

@RandomCustomer,

Looks like either the client win-c6tbrljg6im is not reachable from where you are running the command, or our webserver package is not installed on this client.

 

Regards,

Edward J Holowienka

Badge +5

Which webserver package could be missing ? The backup is running fine though(FYI)

Userlevel 4
Badge +11

@RandomCustomer,

Webserver package is not required for backups. To see if this is installed right click on the client in Commcell Console select view Software. The webserver package is by default installed on the commserve. So if you change the url to point to the commserve it should then work.

 

Reqards,

Edward J Holowienka

Badge +5

 

I tried to install the software. Commserve has internet connectivity so I downloaded the softwares. I received below error message:
Error Code: [68:182]
Description: Failed to install Base Package. Failed to access remote registry. For more information, visit [[https://documentation.commvault.com/commvault/v11/article?p=1971.htm]]
Source: win-c6tbrljg6im, Process: DistributeSoftware

 

Badge +5

This is fixed. The UUID I was taking directly from the VM server was incorrect.

I ran the GET method on VMs from commserv to get all the details and there was a different UUID which worked and api call finally happened.

Reply