1 # -*- coding: utf-8 -*-
4 # Copyright 2016-2017 VMware Inc.
5 # This file is part of ETSI OSM
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact: osslegalrouting@vmware.com
26 from osm_mon
.collector
.vnf_collectors
.base_vim
import BaseVimCollector
27 from osm_mon
.collector
.vnf_collectors
.vrops
.vrops_helper
import vROPS_Helper
28 from osm_mon
.core
.common_db
import CommonDbClient
29 from osm_mon
.core
.config
import Config
31 log
= logging
.getLogger(__name__
)
34 class VIOCollector(BaseVimCollector
):
35 def __init__(self
, config
: Config
, vim_account_id
: str, vim_session
: object):
36 super().__init
__(config
, vim_account_id
)
37 self
.common_db
= CommonDbClient(config
)
38 cfg
= self
.get_vim_account(vim_account_id
)
39 self
.vrops
= vROPS_Helper(
40 vrops_site
=cfg
["vrops_site"],
41 vrops_user
=cfg
["vrops_user"],
42 vrops_password
=cfg
["vrops_password"],
45 def get_vim_account(self
, vim_account_id
: str):
46 vim_account_info
= self
.common_db
.get_vim_account(vim_account_id
)
47 return vim_account_info
["config"]
49 def collect(self
, vnfr
: dict):
50 vnfd
= self
.common_db
.get_vnfd(vnfr
["vnfd-id"])
53 # Populate extra tags for metrics
54 nsr_id
= vnfr
["nsr-id-ref"]
56 tags
["ns_name"] = self
.common_db
.get_nsr(nsr_id
)["name"]
57 if vnfr
["_admin"]["projects_read"]:
58 tags
["project_id"] = vnfr
["_admin"]["projects_read"][0]
60 tags
["project_id"] = ""
62 # Fetch the list of all known resources from vROPS.
63 resource_list
= self
.vrops
.get_vm_resource_list_from_vrops()
65 for vdur
in vnfr
["vdur"]:
66 # This avoids errors when vdur records have not been completely filled
67 if "name" not in vdur
:
70 vdu
= next(filter(lambda vdu
: vdu
["id"] == vdur
["vdu-id-ref"], vnfd
["vdu"]))
71 if "monitoring-parameter" not in vdu
:
74 vim_id
= vdur
["vim-id"]
75 vdu_mappings
[vim_id
] = {"name": vdur
["name"]}
77 # Map the vROPS instance id to the vim-id so we can look it up.
78 for resource
in resource_list
:
79 for resourceIdentifier
in resource
["resourceKey"][
83 resourceIdentifier
["identifierType"]["name"]
84 == "VMEntityInstanceUUID"
86 if resourceIdentifier
["value"] != vim_id
:
88 vdu_mappings
[vim_id
]["vrops_id"] = resource
["identifier"]
90 if len(vdu_mappings
) != 0:
91 return self
.vrops
.get_metrics(
92 vdu_mappings
=vdu_mappings
,
93 monitoring_params
=vdu
["monitoring-parameter"],