X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcollector%2Finfra_collectors%2Fvmware.py;h=8f39464366804c22cacd25f6208e2d8b05bb1437;hb=754a953c2ffe60c944e61a890906a13c7f5cc920;hp=65e739db1027321d7dd83d8b16dc844301aa551b;hpb=8e4179facf22c8096992f0a83caeec9f2f4996c7;p=osm%2FMON.git diff --git a/osm_mon/collector/infra_collectors/vmware.py b/osm_mon/collector/infra_collectors/vmware.py index 65e739d..8f39464 100644 --- a/osm_mon/collector/infra_collectors/vmware.py +++ b/osm_mon/collector/infra_collectors/vmware.py @@ -25,7 +25,7 @@ import logging from typing import List -from xml.etree import ElementTree as XmlElementTree +from lxml import etree as XmlElementTree import requests from pyvcloud.vcd.client import BasicLoginCredentials @@ -52,6 +52,7 @@ class VMwareInfraCollector(BaseVimInfraCollector): self.vim_uuid = vim_account["vim_uuid"] self.org_name = vim_account["orgname"] self.vim_project_id = vim_account["project_id"] + self.verify_ssl = vim_account.get("insecure", False) def connect_vim_as_admin(self): """Method connect as pvdc admin user to vCloud director. @@ -70,7 +71,7 @@ class VMwareInfraCollector(BaseVimInfraCollector): admin_user = self.admin_username admin_passwd = self.admin_password org = "System" - client = Client(host, verify_ssl_certs=False) + client = Client(host, verify_ssl_certs=self.verify_ssl) client.set_highest_supported_version() client.set_credentials(BasicLoginCredentials(admin_user, org, admin_passwd)) return client @@ -116,6 +117,7 @@ class VMwareInfraCollector(BaseVimInfraCollector): client = self.connect_vim_as_admin() if client._session: org_list = client.get_org_list() + org_uuid = "" for org in org_list.Org: if org.get("name") == self.org_name: org_uuid = org.get("href").split("/")[-1] @@ -129,7 +131,9 @@ class VMwareInfraCollector(BaseVimInfraCollector): ], } - response = requests.get(url=url, headers=headers, verify=False) + response = requests.get( + url=url, headers=headers, verify=self.verify_ssl + ) if ( response.status_code != requests.codes.ok @@ -168,7 +172,9 @@ class VMwareInfraCollector(BaseVimInfraCollector): ], } - response = requests.get(url=url, headers=headers, verify=False) + response = requests.get( + url=url, headers=headers, verify=self.verify_ssl + ) if ( response.status_code != requests.codes.ok @@ -194,35 +200,42 @@ class VMwareInfraCollector(BaseVimInfraCollector): vim_status_metric = Metric(vim_tags, "vim_status", vim_status) metrics.append(vim_status_metric) vnfrs = self.common_db.get_vnfrs(vim_account_id=vim_account_id) - for vnfr in vnfrs: - nsr_id = vnfr["nsr-id-ref"] - ns_name = self.common_db.get_nsr(nsr_id)["name"] - vnf_member_index = vnfr["member-vnf-index-ref"] - if vnfr["_admin"]["projects_read"]: - vnfr_project_id = vnfr["_admin"]["projects_read"][0] - else: - vnfr_project_id = "" - for vdur in vnfr["vdur"]: - resource_uuid = vdur["vim-id"] - tags = { - "vim_account_id": self.vim_account_id, - "resource_uuid": resource_uuid, - "nsr_id": nsr_id, - "ns_name": ns_name, - "vnf_member_index": vnf_member_index, - "vdur_name": vdur["name"], - "project_id": vnfr_project_id, - } - try: - vm_list = self.check_vm_status(resource_uuid) - for vm in vm_list: - if vm["status"] == "4" and vm["deployed"] == "true": - vm_status = 1 - else: - vm_status = 0 - vm_status_metric = Metric(tags, "vm_status", vm_status) - except Exception: - log.exception("VM status is not OK!") - vm_status_metric = Metric(tags, "vm_status", 0) - metrics.append(vm_status_metric) + if self.conf.get("collector", "vm_infra_metrics"): + vm_infra_metrics_enabled = str( + self.conf.get("collector", "vm_infra_metrics") + ).lower() in ("yes", "true", "1") + else: + vm_infra_metrics_enabled = True + if vm_infra_metrics_enabled: + for vnfr in vnfrs: + nsr_id = vnfr["nsr-id-ref"] + ns_name = self.common_db.get_nsr(nsr_id)["name"] + vnf_member_index = vnfr["member-vnf-index-ref"] + if vnfr["_admin"]["projects_read"]: + vnfr_project_id = vnfr["_admin"]["projects_read"][0] + else: + vnfr_project_id = "" + for vdur in vnfr["vdur"]: + resource_uuid = vdur["vim-id"] + tags = { + "vim_account_id": self.vim_account_id, + "resource_uuid": resource_uuid, + "nsr_id": nsr_id, + "ns_name": ns_name, + "vnf_member_index": vnf_member_index, + "vdur_name": vdur["name"], + "project_id": vnfr_project_id, + } + try: + vm_list = self.check_vm_status(resource_uuid) + for vm in vm_list: + if vm["status"] == "4" and vm["deployed"] == "true": + vm_status = 1 + else: + vm_status = 0 + vm_status_metric = Metric(tags, "vm_status", vm_status) + except Exception: + log.exception("VM status is not OK!") + vm_status_metric = Metric(tags, "vm_status", 0) + metrics.append(vm_status_metric) return metrics