Skip to content
This repository was archived by the owner on Sep 17, 2026. It is now read-only.
Open
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
43 changes: 25 additions & 18 deletions cli/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,32 @@ def populate_payload(config):
'''

def authenticate_hmc(config):
# Populate Authentication payload
payload = populate_payload(config)
url = "https://" + util.get_host_address(config) + URI
headers = {"Content-Type": CONTENT_TYPE, "Accept": ACCEPT}
response = requests.put(url, headers=headers, data=payload, verify=False)
if response.status_code != 200:
logger.error(f"failed to authenticate HMC, error: {response.text}")
raise AuthError(f"failed to authenticate HMC, error: {response.text}")

soup = BeautifulSoup(response.text, 'xml')
session_key = soup.find("X-API-Session")
try:
# Populate Authentication payload
payload = populate_payload(config)
url = "https://" + util.get_host_address(config) + URI
headers = {"Content-Type": CONTENT_TYPE, "Accept": ACCEPT}
response = requests.put(url, headers=headers, data=payload, verify=False)
response.raise_for_status()

soup = BeautifulSoup(response.text, 'xml')
session_key = soup.find("X-API-Session")
except requests.exceptions.RequestException as e:
raise AuthError(f"failed to authenticate HMC while making http request, error: {e}, response: {e.response.text}")
except Exception as e:
raise AuthError(f"failed to authenticate HMC, error: {e}")
return session_key.text, response.cookies

def delete_session(config, cookies):
url = "https://" + util.get_host_address(config) + URI
headers = {"x-api-key": util.get_session_key(config)}
response = requests.delete(url, cookies=cookies, headers=headers, verify=False)
if response.status_code != 204:
logger.error(f"failed to delete session on HMC, error: {response.text}")
raise AuthError(f"failed to delete session on HMC, error: {response.text}")
logger.debug("Logged off HMC session successfully")
try:
url = "https://" + util.get_host_address(config) + URI
headers = {"x-api-key": util.get_session_key(config)}
response = requests.delete(url, cookies=cookies, headers=headers, verify=False)
response.raise_for_status()

logger.debug("Logged off HMC session successfully")
except requests.exceptions.RequestException as e:
raise AuthError(f"failed to delete session on HMC while making http request, error: {e}, response: {e.response.text}")
except Exception as e:
raise AuthError(f"failed to delete session on HMC, error: {e}")
return
25 changes: 16 additions & 9 deletions cli/cmd/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,41 @@ def destroy(config_file_path):
# Invoking initialize_command to perform common actions like validation, authentication etc.
is_config_valid, cookies, sys_uuid, vios_uuid_list = command_util.initialize_command(config)
if is_config_valid:
_destroy(config, cookies, sys_uuid, vios_uuid_list)
logger.info("PIM partition successfully destroyed")
destroyed = _destroy(config, cookies, sys_uuid, vios_uuid_list)
if destroyed:
logger.info("PIM partition successfully destroyed")
except (Exception) as e:
logger.error(f"encountered an error: {e}")
finally:
if cookies:
command_util.cleanup(config, cookies)

def _destroy(config, cookies, sys_uuid, vios_uuid_list):
destroy_succeded = False
try:
exists, created_by_pim, partition_uuid = partition.check_partition_exists(
config, cookies, sys_uuid)
if exists:
logger.info("Shutting down the partition")
activation.shutdown_partition(config, cookies, partition_uuid)
logger.info("Partition shut down")
shutdown = activation.shutdown_partition(config, cookies, partition_uuid)
if shutdown:
logger.info("Partition shut down")

logger.info(
"Detaching installation medias and physical disk from the partition")
vios_operation.cleanup_vios(
vios_cleanup = vios_operation.cleanup_vios(
config, cookies, sys_uuid, partition_uuid, vios_uuid_list)
logger.info(
"Detached installation medias and physical disk from the partition")
if vios_cleanup:
logger.info(
"Detached installation medias and physical disk from the partition")

if created_by_pim and exists:
logger.info("Destroying the partition")
partition.remove_partition(config, cookies, partition_uuid)
destroyed = partition.remove_partition(config, cookies, partition_uuid)
logger.info("Partition destroyed")

# Decide destroy_succeded or not via all the operation's status
destroy_succeded = shutdown and vios_cleanup and destroyed
except Exception as e:
raise e
return
return destroy_succeded
14 changes: 4 additions & 10 deletions cli/cmd/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ def _launch(config, cookies, sys_uuid, vios_uuids):
active_vios_servers = vios_operation.get_active_vios(
config, cookies, sys_uuid, vios_uuids)
if len(active_vios_servers) == 0:
logger.error("failed to find active VIOS server")
raise VIOSError("failed to find active VIOS server")
raise VIOSError(f"no active VIOS server attached to the system '{util.get_host_address(config)}'")

@manju956 manju956 Oct 21, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

host address will be pointing to HMC IP. probably we can mention the system id or get corresponding system name and log.

logger.debug(
f"List of active VIOS '{list(active_vios_servers.keys())}'")

vios_media_uuid_list = vios_operation.get_vios_with_mediarepo_tag(active_vios_servers)
if len(vios_media_uuid_list) == 0:
logger.error("failed to find VIOS server for the partition")
raise StorageError("failed to find VIOS server for the partition")
raise StorageError(f"no VIOS server attached with media repository on the system '{util.get_host_address(config)}'")

logger.info("Setting up partition")
exists, created_by_pim, partition_uuid = partition.check_partition_exists(config, cookies, sys_uuid)
Expand Down Expand Up @@ -186,10 +184,7 @@ def setup_storage(config, cookies, active_vios, sys_uuid, lpar_id):
vios_storage_list = vios_operation.get_vios_with_physical_storage(
config, active_vios)
if len(vios_storage_list) == 0:
logger.error(
"failed to find physical volume for the partition")
raise StorageError(
"failed to find physical volume for the partition")
raise StorageError(f"no VIOS server attached with available physical disk on the system '{util.get_host_address(config)}' to attach to the PIM partition")
storage.attach_physical_storage(
config, cookies, sys_uuid, lpar_id, vios_storage_list)
except (StorageError, VIOSError, Exception) as e:
Expand All @@ -200,8 +195,7 @@ def handle_virtual_disk(config, cookies, active_vios, sys_uuid, lpar_id):
vios_storage_list = vios_operation.get_vios_with_physical_storage(
config, active_vios)
if len(vios_storage_list) == 0:
logger.error("failed to find physical volume for the partition")
raise StorageError("failed to find physical volume for the partition")
raise StorageError(f"no VIOS server attached with available physical disk on the system '{util.get_host_address(config)}' to attach to the PIM partition")
vios_storage_uuid = vios_storage_list[0][0]
updated_vios_payload = vios_operation.get_vios_details(config, cookies, sys_uuid, vios_storage_uuid)

Expand Down
1 change: 0 additions & 1 deletion cli/cmd/rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ def _rollback(config):
return False
return True
except Exception as e:
logger.error(f"failed to rollback PIM partition, error: {e}")
raise Exception(f"failed to rollback PIM partition, error: {e}")
4 changes: 2 additions & 2 deletions cli/cmd/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def _status(config, cookies, sys_uuid):
logger.debug("Checking partition exists")
exists, _, partition_uuid = partition.check_partition_exists(config, cookies, sys_uuid)
if not exists:
logger.error(f"Partition named '{util.get_partition_name(config)}' not found")
logger.error(f"partition named '{util.get_partition_name(config)}' not found")
return

lpar_state = activation.check_lpar_status(config, cookies, partition_uuid)
if lpar_state != "running":
logger.error(f"Partition '{util.get_partition_name(config)}' not in running state")
logger.error(f"partition '{util.get_partition_name(config)}' not in running state")
return
logger.info(f"PIM partition '{util.get_partition_name(config)}' is in running state")

Expand Down
1 change: 0 additions & 1 deletion cli/cmd/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _upgrade(config):
logger.info("Monitoring boot process, this will take a while")
monitor_util.monitor_pim(config)
except Exception as e:
logger.error(f"failed to upgrade PIM partition, error: {e}")
raise Exception(f"failed to upgrade PIM partition, error: {e}")

return upgraded
83 changes: 44 additions & 39 deletions cli/network/virtual_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,46 @@ def populate_payload(vlanid, vswitchid, vswitchname):
'''

def get_network_uuid(config, cookies, system_uuid):
uri = f"/rest/api/uom/ManagedSystem/{system_uuid}/VirtualNetwork/quick/All"
url = "https://" + util.get_host_address(config) + uri
headers = {"x-api-key": util.get_session_key(config), "Content-Type": "application/vnd.ibm.powervm.uom+xml, type=VirtualNetwork"}
response = requests.get(url, headers=headers, cookies=cookies, verify=False)
if response.status_code != 200:
logger.error(f"failed to list VLAN, error: {response.text}")
raise NetworkError(f"failed to list VLAN, error: {response.text}")
uuid = ""
network_name = util.get_vnetwork_name(config)
for nw in response.json():
if nw["NetworkName"] == network_name:
uuid = nw["UUID"]
break
try:
uri = f"/rest/api/uom/ManagedSystem/{system_uuid}/VirtualNetwork/quick/All"
url = "https://" + util.get_host_address(config) + uri
headers = {"x-api-key": util.get_session_key(config), "Content-Type": "application/vnd.ibm.powervm.uom+xml, type=VirtualNetwork"}
response = requests.get(url, headers=headers, cookies=cookies, verify=False)
response.raise_for_status()

uuid = ""
network_name = util.get_vnetwork_name(config)
for nw in response.json():
if nw["NetworkName"] == network_name:
uuid = nw["UUID"]
break

if "" == uuid:
logger.error(f"failed to find virtual network with name '{network_name}'")
raise NetworkError(f"failed to find virtual network with name '{network_name}'")
else:
logger.debug(f"Network UUID for the virtual network {network_name}: {uuid}")
if "" == uuid:
raise NetworkError(f"no virtual network available with name '{network_name}'")
else:
logger.debug(f"Network UUID for the virtual network {network_name}: {uuid}")
except requests.exceptions.RequestException as e:
raise NetworkError(f"failed to list VLAN while making http request, error: {e}, response: {e.response.text}")
except Exception as e:
raise NetworkError(f"failed to list VLAN, error: {e}")
return uuid

def get_vlan_details(config, cookies, system_uuid):
nw_uuid = get_network_uuid(config, cookies, system_uuid)
uri = f"/rest/api/uom/ManagedSystem/{system_uuid}/VirtualNetwork/{nw_uuid}"
url = "https://" + util.get_host_address(config) + uri
headers = {"x-api-key": util.get_session_key(config), "Content-Type": "application/vnd.ibm.powervm.uom+xml, type=VirtualNetwork"}
response = requests.get(url, headers=headers, cookies=cookies, verify=False)
if response.status_code != 200:
logger.error(f"failed to get VLAN details, error: {response.text}")
raise NetworkError(f"failed to get VLAN details, error: {response.text}")

soup = BeautifulSoup(response.text, 'xml')
vlan_id = soup.find("NetworkVLANID")
vswitch_id = soup.find("VswitchID")

try:
nw_uuid = get_network_uuid(config, cookies, system_uuid)
uri = f"/rest/api/uom/ManagedSystem/{system_uuid}/VirtualNetwork/{nw_uuid}"
url = "https://" + util.get_host_address(config) + uri
headers = {"x-api-key": util.get_session_key(config), "Content-Type": "application/vnd.ibm.powervm.uom+xml, type=VirtualNetwork"}
response = requests.get(url, headers=headers, cookies=cookies, verify=False)
response.raise_for_status()

soup = BeautifulSoup(response.text, 'xml')
vlan_id = soup.find("NetworkVLANID")
vswitch_id = soup.find("VswitchID")
except requests.exceptions.RequestException as e:
raise NetworkError(f"failed to get VLAN details while making http request, error: {e}, response: {e.response.text}")
except Exception as e:
raise NetworkError(f"failed to get VLAN details, error: {e}")
return vlan_id.text, vswitch_id.text

def check_network_adapter(config, cookies, partition_uuid, vlan_id, vswitch_id):
Expand All @@ -81,11 +86,11 @@ def check_network_adapter(config, cookies, partition_uuid, vlan_id, vswitch_id):
logger.debug(f"Found network with VLAN '{vlan_id}' and Switch '{vswitch_id}' attached to lpar.")
slot_num = soup.find("VirtualSlotNumber").text
return True, slot_num
else:
raise NetworkError(f"failed to check if virtual network is attached to the partition, error: {response.text}")
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise NetworkError(f"failed to check if virtual network is attached to the partition while making http request, error: {e}, response: {e.response.text}")
except Exception as e:
logger.error(f"failed to check if virtual network is attached to the partition, error: {e}")
raise e
raise NetworkError(f"failed to check if virtual network is attached to the partition, error: {e}")
return False, slot_num

def attach_network(config, cookies, system_uuid, partition_uuid):
Expand All @@ -105,10 +110,10 @@ def attach_network(config, cookies, system_uuid, partition_uuid):
url = "https://" + util.get_host_address(config) + uri
headers = {"x-api-key": util.get_session_key(config), "Content-Type": CONTENT_TYPE}
response = requests.put(url, headers=headers, cookies=cookies, data=payload, verify=False)
if response.status_code != 200:
logger.error(f"failed to attach virtual network to the partition, error: {response.text}")
raise NetworkError(f"failed to attach virtual network to the partition, error: {response.text}")
response.raise_for_status()
logger.debug(f"Network '{util.get_vnetwork_name(config)}' attached to lpar")
except requests.exceptions.RequestException as e:
raise NetworkError(f"failed to attach virtual network to the partition while making http request, error: {e}, response: {e.response.text}")
except Exception as e:
raise e
raise NetworkError(f"failed to attach virtual network to the partition, error: {e}")
return DEFAULT_NW_SLOT
Loading