On branch main
Initial commit Changes to be committed: new file: README.md new file: abx/apply_nsx_tags_for_tiers/README.md new file: abx/apply_nsx_tags_for_tiers/action.py new file: abx/list_vcenter_vms/README.md new file: abx/list_vcenter_vms/action.py new file: abx/send_email/README.md new file: abx/send_email/action.py new file: blueprints/forms/vdefend-form.json new file: blueprints/vdefend-form-driven.yaml
This commit is contained in:
11
abx/list_vcenter_vms/README.md
Normal file
11
abx/list_vcenter_vms/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# ABX: list_vcenter_vms (Python 3)
|
||||
|
||||
Returns an array of VM names from vCenter for use in the Custom Form.
|
||||
|
||||
## Constants (recommended)
|
||||
- VCENTER_SERVER (e.g., https://vcsa.lab.legionitgroup.com)
|
||||
- VCENTER_USERNAME
|
||||
- VCENTER_PASSWORD
|
||||
|
||||
## Output format
|
||||
Return a JSON array of strings (VM names) or objects `{ "text": "vm-name", "value": "vm-name" }`.
|
||||
33
abx/list_vcenter_vms/action.py
Normal file
33
abx/list_vcenter_vms/action.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import os, requests
|
||||
|
||||
def _login(session, base):
|
||||
# Try modern API session (vSphere 8/9)
|
||||
r = session.post(f"{base}/api/session")
|
||||
if r.status_code in (200, 204):
|
||||
return
|
||||
# Fallback to legacy vAPI
|
||||
r = session.post(f"{base}/rest/com/vmware/cis/session")
|
||||
if r.status_code not in (200, 201):
|
||||
raise Exception(f"vCenter login failed: {r.status_code} {r.text}")
|
||||
|
||||
def handler(context, inputs):
|
||||
base = os.getenv("VCENTER_SERVER") or inputs.get("vcenter_server")
|
||||
user = os.getenv("VCENTER_USERNAME") or inputs.get("vcenter_username")
|
||||
pwd = os.getenv("VCENTER_PASSWORD") or inputs.get("vcenter_password")
|
||||
if not (base and user and pwd):
|
||||
raise Exception("Missing vCenter credentials/server. Set VCENTER_* constants or pass in inputs.")
|
||||
s = requests.Session()
|
||||
s.verify = False
|
||||
s.auth = (user, pwd)
|
||||
_login(s, base)
|
||||
# Try modern inventory endpoint
|
||||
r = s.get(f"{base}/api/vcenter/vm")
|
||||
if r.status_code == 200:
|
||||
vms = [vm.get("name") for vm in r.json() if vm.get("name")]
|
||||
else:
|
||||
# Fallback legacy
|
||||
r = s.get(f"{base}/rest/vcenter/vm")
|
||||
r.raise_for_status()
|
||||
vms = [vm.get("name") for vm in r.json().get("value", []) if vm.get("name")]
|
||||
# Return array for multi-select
|
||||
return vms
|
||||
Reference in New Issue
Block a user