Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
804 B
1
Indexable
Never
import requests
import vmc.vsphere.client as vsphere_client

# Replace these values with your own
url = "http://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-amd64.img"
username = "user@example.com"
password = "password"
vcenter_host = "vcenter.example.com"
library_name = "My Library"

# Download the cloud image from the URL
response = requests.get(url)
cloud_image_data = response.content

# Connect to vSphere and get the library object
vc = vsphere_client.create_vsphere_client(vcenter_host, username, password)
library = vc.library.get(library_name)

# Upload the cloud image to the library
library_item = library.upload(cloud_image_data, "ubuntu-20.04-server-cloudimg-amd64.img", "OVA")

print(f"Successfully uploaded cloud image to library item: {library_item.id}")