| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
from __future__ import (absolute_import, division, print_function) |
| 30 |
|
| 31 |
__metaclass__ = type |
| 32 |
|
| 33 |
VCENTER_INFO_URI = "/Consoles" |
| 34 |
CLUSTER_INFO_URI = "/Consoles/{uuid}/Clusters" |
| 35 |
GROUP_ID_CLUSTER_INFO_URI = "/Consoles/{uuid}/Groups/getGroupsForClusters" |
| 36 |
MANAGED_HOST_INFO_URI = "/Consoles/{uuid}/ManagedHosts" |
| 37 |
CLUSTER_MANAGED_HOST_INFO_URI = "/Consoles/{uuid}/Groups/{groupId}/ManagedHosts" |
| 38 |
HOST_FIRMWARE_DRIFT_INFO_URI = "/Consoles/{uuid}/Groups/{groupId}/ManagedHosts/{hostId}/FirmwareDriftReport" |
| 39 |
CLUSTER_FIRMWARE_DRIFT_INFO_URI = "/Consoles/{uuid}/Groups/{groupId}/FirmwareDriftReport" |
| 40 |
|
| 41 |
|
| 42 |
class OMEVVInfo: |
| 43 |
def __init__(self, omevv_obj): |
| 44 |
self.omevv_obj = omevv_obj |
| 45 |
|
| 46 |
def get_vcenter_info(self, vcenter_id=None): |
| 47 |
""" |
| 48 |
Retrieves the vCenter information. |
| 49 |
Parameters: |
| 50 |
vcenter_id (str, optional): The hostname of the vCenter. If provided, retrieves the information for the specified vCenter. |
| 51 |
Returns: |
| 52 |
list: A list of vCenter information when `vcenter_id` is not provided |
| 53 |
dict: A dict containing the information for the specified vCenter when `vcenter_id` is provided. If no match is found, the empty dict is returned. |
| 54 |
""" |
| 55 |
resp = self.omevv_obj.invoke_request('GET', VCENTER_INFO_URI) |
| 56 |
vcenter_info = [] |
| 57 |
if resp.success: |
| 58 |
vcenter_info = resp.json_data |
| 59 |
if vcenter_id and vcenter_info: |
| 60 |
for each_vcenter in vcenter_info: |
| 61 |
if each_vcenter.get('consoleAddress') == vcenter_id: |
| 62 |
return each_vcenter |
| 63 |
return {} |
| 64 |
return vcenter_info |
| 65 |
|
| 66 |
def get_cluster_info(self, uuid, cluster_name=""): |
| 67 |
uri = CLUSTER_INFO_URI.format(uuid=uuid) |
| 68 |
resp = self.omevv_obj.invoke_request('GET', uri) |
| 69 |
cluster_info = [] |
| 70 |
if resp.success: |
| 71 |
cluster_info = resp.json_data |
| 72 |
if cluster_name and cluster_info: |
| 73 |
for each_cluster in cluster_info: |
| 74 |
if each_cluster.get('name') == cluster_name: |
| 75 |
return each_cluster |
| 76 |
return {} |
| 77 |
return cluster_info |
| 78 |
|
| 79 |
def get_group_id_of_cluster(self, uuid, cluster_name): |
| 80 |
group_id = -1 |
| 81 |
uri = GROUP_ID_CLUSTER_INFO_URI.format(uuid=uuid) |
| 82 |
cluster_info = self.get_cluster_info(uuid, cluster_name) |
| 83 |
if cluster_info: |
| 84 |
entity_id = cluster_info.get('entityId') |
| 85 |
payload = {"clustIds": [entity_id]} |
| 86 |
resp = self.omevv_obj.invoke_request('POST', uri, data=payload) |
| 87 |
if resp.success: |
| 88 |
group_id = resp.json_data[0].get('groupId') |
| 89 |
return group_id |
| 90 |
|
| 91 |
def get_managed_host_details(self, uuid, servicetags=None, hostnames=None): |
| 92 |
servicetags = [] if servicetags is None else servicetags |
| 93 |
hostnames = [] if hostnames is None else hostnames |
| 94 |
uri = MANAGED_HOST_INFO_URI.format(uuid=uuid) |
| 95 |
resp = self.omevv_obj.invoke_request('GET', uri) |
| 96 |
managed_hosts = resp.json_data |
| 97 |
if not (servicetags or hostnames): |
| 98 |
return managed_hosts, {} |
| 99 |
|
| 100 |
if servicetags: |
| 101 |
managed_hosts = [ |
| 102 |
host for host in managed_hosts |
| 103 |
if host.get("serviceTag") in servicetags |
| 104 |
] |
| 105 |
|
| 106 |
if hostnames: |
| 107 |
managed_hosts = [ |
| 108 |
host for host in managed_hosts |
| 109 |
if host.get("hostName") in hostnames |
| 110 |
] |
| 111 |
|
| 112 |
invalid_result = { |
| 113 |
"servicetags": [ |
| 114 |
tag for tag in servicetags |
| 115 |
if not any(host.get("serviceTag") == tag for host in managed_hosts) |
| 116 |
], |
| 117 |
"hostnames": [ |
| 118 |
name for name in hostnames |
| 119 |
if not any(host.get("hostName") == name for host in managed_hosts) |
| 120 |
] |
| 121 |
} |
| 122 |
return managed_hosts, invalid_result |
| 123 |
|
| 124 |
def get_firmware_drift_info_for_single_host(self, uuid, groupid, hostid): |
| 125 |
result = [] |
| 126 |
uri = HOST_FIRMWARE_DRIFT_INFO_URI.format(uuid=uuid, |
| 127 |
groupId=str(groupid), |
| 128 |
hostId=str(hostid)) |
| 129 |
resp = self.omevv_obj.invoke_request('GET', uri) |
| 130 |
if resp.success: |
| 131 |
result = resp.json_data |
| 132 |
return result |
| 133 |
|
| 134 |
def get_firmware_drift_info_for_multiple_host(self, uuid, groupid, hostidlist): |
| 135 |
result = [] |
| 136 |
for each_host in hostidlist: |
| 137 |
output = self.get_firmware_drift_info_for_single_host(uuid, groupid, each_host) |
| 138 |
result.append(output) |
| 139 |
return result |
| 140 |
|
| 141 |
def get_firmware_drift_info_for_single_cluster(self, uuid, groupid): |
| 142 |
result = [] |
| 143 |
uri = CLUSTER_FIRMWARE_DRIFT_INFO_URI.format(uuid=uuid, |
| 144 |
groupId=str(groupid)) |
| 145 |
resp = self.omevv_obj.invoke_request('GET', uri) |
| 146 |
if resp.success: |
| 147 |
result = resp.json_data |
| 148 |
return result |
| 149 |
|
| 150 |
def get_firmware_drift_info_for_multiple_cluster(self, uuid, groupidlist): |
| 151 |
result = [] |
| 152 |
for each_group in groupidlist: |
| 153 |
output = self.get_firmware_drift_info_for_single_cluster(uuid=uuid, |
| 154 |
groupid=each_group) |
| 155 |
result.append(output) |
| 156 |
return result |
| 157 |
|
| 158 |
def get_cluster_name(self, uuid, host_id): |
| 159 |
uri = MANAGED_HOST_INFO_URI.format(uuid=uuid) |
| 160 |
resp = self.omevv_obj.invoke_request('GET', uri) |
| 161 |
managed_hosts = resp.json_data |
| 162 |
for host in managed_hosts: |
| 163 |
if host['id'] == host_id: |
| 164 |
return host['clusterName'] |
| 165 |
return "" |
| 166 |
|
| 167 |
def get_host_id_either_host_or_service_tag(self, uuid, hostname=None, servicetag=None): |
| 168 |
uri = MANAGED_HOST_INFO_URI.format(uuid=uuid) |
| 169 |
resp = self.omevv_obj.invoke_request('GET', uri) |
| 170 |
managed_hosts = resp.json_data |
| 171 |
for host in managed_hosts: |
| 172 |
if hostname and host['hostName'] == hostname: |
| 173 |
return host['id'], host['serviceTag'] |
| 174 |
if servicetag and host['serviceTag'] == servicetag: |
| 175 |
return host['id'], host['serviceTag'] |
| 176 |
return None, None |
| 177 |
|
| 178 |
def get_cluster_managed_host_details(self, uuid, cluster_group_id): |
| 179 |
uri = CLUSTER_MANAGED_HOST_INFO_URI.format(uuid=uuid, groupId=cluster_group_id) |
| 180 |
resp = self.omevv_obj.invoke_request('GET', uri) |
| 181 |
managed_hosts = resp.json_data |
| 182 |
|
| 183 |
host_ids = [] |
| 184 |
host_service_tags = [] |
| 185 |
|
| 186 |
for host in managed_hosts: |
| 187 |
host_ids.append(host.get('id')) |
| 188 |
host_service_tags.append(host.get('serviceTag')) |
| 189 |
|
| 190 |
return host_ids, host_service_tags |