Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/v4api_sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build/
dist/
*.egg-info/
eslint.config.mjs
ntnx_opsmgmt_py_client/
80 changes: 40 additions & 40 deletions python/v4api_sdk/create_image_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def main():
parser.add_argument("pc_ip", help="Prism Central IP address or FQDN")
parser.add_argument("username", help="Prism Central username")
parser.add_argument(
"-p", "--poll", help="Time between task polling, in seconds", default=1
)
"-p", "--poll", help="Time between task polling, in seconds", default=1
)
args = parser.parse_args()

# get the cluster password
cluster_password = getpass.getpass(
prompt="Please enter your Prism Central \
password: ",
stream=None,
)
prompt="Please enter your Prism Central \
password: ",
stream=None,
)

pc_ip = args.pc_ip
username = args.username
Expand All @@ -59,12 +59,12 @@ def main():
if not cluster_password:
while not cluster_password:
print(
"Password cannot be empty. \
Please enter a password or Ctrl-C/Ctrl-D to exit."
)
"Password cannot be empty. \
Please enter a password or Ctrl-C/Ctrl-D to exit."
)
cluster_password = getpass.getpass(
prompt="Please enter your Prism Central password: ", stream=None
)
prompt="Please enter your Prism Central password: ", stream=None
)

try:
# create utils instance for re-use later
Expand Down Expand Up @@ -93,26 +93,26 @@ def main():
if not cluster.name == "Unnamed":
found_clusters.append({"name": cluster.name, "ext_id": cluster.ext_id})
print(
f"The following clusters ({len(cluster_list.data)-1}) were found, not including Prism Central."
)
f"The following clusters ({len(cluster_list.data)-1}) were found, not including Prism Central."
)
print(
"Note: By default Prism Central clusters appear as 'Unnamed'. Clusters matching this name have \
not been included in this list."
)
"Note: By default Prism Central clusters appear as 'Unnamed'. Clusters matching this name have \
not been included in this list."
)
pprint(found_clusters)
expected_cluster_name = input(
"\nPlease enter the name of the destination cluster: "
).lower()
"\nPlease enter the name of the destination cluster: "
).lower()

matches = [
x
for x in found_clusters
if x["name"].lower() == expected_cluster_name.lower()
]
x
for x in found_clusters
if x["name"].lower() == expected_cluster_name.lower()
]
if not matches:
print(
f"No cluster found matching the name {expected_cluster_name}. Exiting."
)
f"No cluster found matching the name {expected_cluster_name}. Exiting."
)
sys.exit()

# get the cluster ext_id
Expand All @@ -129,20 +129,20 @@ def main():
vmm_config.verify_ssl = False
api_client = VMMClient(configuration=vmm_config)
api_client.add_default_header(
header_name="Accept-Encoding", header_value="gzip, deflate, br"
)
header_name="Accept-Encoding", header_value="gzip, deflate, br"
)
api_instance = ntnx_vmm_py_client.api.ImagesApi(api_client=api_client)

# generate unique ID to ensure image names are always different
unique_id = uuid.uuid1()

# setup new image properties
new_image = ntnx_vmm_py_client.models.vmm.v4.content.Image.Image()
new_image.name = f"centos7_2211_generic_cloud_{unique_id}"
new_image.desc = "CentOS 7 Generic Cloud 2211"
new_image.name = f"rocky_linux_9_cloud_{unique_id}"
new_image.desc = "Rocky Linux 9 Cloud Image"
new_image.type = "DISK_IMAGE"
image_source = ntnx_vmm_py_client.models.vmm.v4.content.UrlSource.UrlSource()
image_source.url = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2211.qcow2"
image_source.url = "https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2"
image_source.allow_insecure = False
new_image.source = image_source
image_cluster = ntnx_vmm_py_client.models.vmm.v4.ahv.config.ClusterReference.ClusterReference()
Expand All @@ -160,24 +160,24 @@ def main():
# monitor_task function
create_ext_id = image_create.data.ext_id
utils.monitor_task(
task_ext_id=create_ext_id,
task_name="Create image",
pc_ip=pc_ip,
username=username,
password=cluster_password,
poll_timeout=poll_timeout,
)
task_ext_id=create_ext_id,
task_name="Create image",
pc_ip=pc_ip,
username=username,
password=cluster_password,
poll_timeout=poll_timeout,
)
task = utils.get_task(create_ext_id)
print(f"Image created with ext_id {task.data.entities_affected[0].ext_id}")
else:
print("Image creation cancelled.")

except VMMException as vmm_exception:
print(
f"Unable to authenticate using the supplied credentials. \
Please check your username and/or password, then try again. \
Exception details: {vmm_exception}"
)
f"Unable to authenticate using the supplied credentials. \
Please check your username and/or password, then try again. \
Exception details: {vmm_exception}"
)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions python/v4api_sdk/subnet_config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "UVM-Full-Test",
"name": "UVM",
"description": "User VMS only, no CVMs or Nutanix Products",
"subnet_type": "VLAN",
"network_id": 409,
"network_id": 406,
"virtual_switch_reference": "ef6defb7-bfb2-4c08-9ac7-e2cf195077ec",
"is_external": false,
"is_advanced_networking": true,
Expand Down