import logging
from typing import List
-from keystoneauth1 import session
-from keystoneauth1.identity import v3
from keystoneclient.v3 import client as keystone_client
from novaclient import client as nova_client
from novaclient import v2 as nova_client_v2
from osm_mon.collector.infra_collectors.base_vim import BaseVimInfraCollector
from osm_mon.collector.metric import Metric
-from osm_mon.collector.utils import CollectorUtils
+from osm_mon.collector.utils.openstack import OpenstackUtils
from osm_mon.core.common_db import CommonDbClient
from osm_mon.core.config import Config
return False
def _build_keystone_client(self, vim_account_id) -> keystone_client.Client:
- sess = self._get_session(vim_account_id)
+ sess = OpenstackUtils.get_session(vim_account_id)
return keystone_client.Client(session=sess)
def _build_nova_client(self, vim_account_id) -> nova_client_v2.Client:
- sess = self._get_session(vim_account_id)
+ sess = OpenstackUtils.get_session(vim_account_id)
return nova_client.Client("2", session=sess)
-
- def _get_session(self, vim_account_id: str):
- creds = CollectorUtils.get_credentials(vim_account_id)
- verify_ssl = CollectorUtils.is_verify_ssl(creds)
- auth = v3.Password(auth_url=creds.url,
- username=creds.user,
- password=creds.password,
- project_name=creds.tenant_name,
- project_domain_id='default',
- user_domain_id='default')
- return session.Session(auth=auth, verify=verify_ssl)
# contact: osslegalrouting@vmware.com
##
+import json
import logging
from typing import List
-
from xml.etree import ElementTree as XmlElementTree
+
+import requests
from pyvcloud.vcd.client import BasicLoginCredentials
from pyvcloud.vcd.client import Client
-from osm_mon.collector.utils import CollectorUtils
from osm_mon.collector.infra_collectors.base_vim import BaseVimInfraCollector
from osm_mon.collector.metric import Metric
+from osm_mon.collector.utils.collector import CollectorUtils
from osm_mon.core.common_db import CommonDbClient
from osm_mon.core.config import Config
-import requests
-import json
log = logging.getLogger(__name__)
API_VERSION = '27.0'
from osm_mon.collector.infra_collectors.vmware import VMwareInfraCollector
from osm_mon.collector.infra_collectors.vio import VIOInfraCollector
from osm_mon.collector.metric import Metric
-from osm_mon.collector.utils import CollectorUtils
+from osm_mon.collector.utils.collector import CollectorUtils
from osm_mon.collector.vnf_collectors.juju import VCACollector
from osm_mon.collector.vnf_collectors.openstack import OpenstackCollector
from osm_mon.collector.vnf_collectors.vio import VIOCollector
+++ /dev/null
-# Copyright 2018 Whitestack, LLC
-# *************************************************************
-
-# This file is part of OSM Monitoring module
-# All Rights Reserved to Whitestack, LLC
-
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-
-# http://www.apache.org/licenses/LICENSE-2.0
-
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-# For those usages not covered by the Apache License, Version 2.0 please
-# contact: bdiaz@whitestack.com or glavado@whitestack.com
-##
-import json
-
-from osm_mon.collector.metric import Metric
-from osm_mon.core import database
-from osm_mon.core.database import VimCredentials, VimCredentialsRepository
-
-
-class CollectorUtils(Metric):
-
- @staticmethod
- def get_vim_type(vim_account_id) -> str:
- credentials = CollectorUtils.get_credentials(vim_account_id)
- config = json.loads(credentials.config)
- if 'vim_type' in config:
- vim_type = config['vim_type']
- return str(vim_type.lower())
- else:
- return str(credentials.type)
-
- @staticmethod
- def get_credentials(vim_account_id) -> VimCredentials:
- database.db.connect()
- try:
- with database.db.atomic():
- return VimCredentialsRepository.get(VimCredentials.uuid == vim_account_id)
- finally:
- database.db.close()
-
- @staticmethod
- def is_verify_ssl(vim_credentials: VimCredentials):
- vim_config = json.loads(vim_credentials.config)
- return 'insecure' not in vim_config or vim_config['insecure'] is False
--- /dev/null
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: bdiaz@whitestack.com or glavado@whitestack.com
+##
--- /dev/null
+# Copyright 2018 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: bdiaz@whitestack.com or glavado@whitestack.com
+##
+import json
+
+from osm_mon.collector.metric import Metric
+from osm_mon.core import database
+from osm_mon.core.database import VimCredentials, VimCredentialsRepository
+
+
+class CollectorUtils(Metric):
+
+ @staticmethod
+ def get_vim_type(vim_account_id) -> str:
+ credentials = CollectorUtils.get_credentials(vim_account_id)
+ config = json.loads(credentials.config)
+ if 'vim_type' in config:
+ vim_type = config['vim_type']
+ return str(vim_type.lower())
+ else:
+ return str(credentials.type)
+
+ @staticmethod
+ def get_credentials(vim_account_id) -> VimCredentials:
+ database.db.connect()
+ try:
+ with database.db.atomic():
+ return VimCredentialsRepository.get(VimCredentials.uuid == vim_account_id)
+ finally:
+ database.db.close()
+
+ @staticmethod
+ def is_verify_ssl(vim_credentials: VimCredentials):
+ vim_config = json.loads(vim_credentials.config)
+ return 'insecure' not in vim_config or vim_config['insecure'] is False
--- /dev/null
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: bdiaz@whitestack.com or glavado@whitestack.com
+##
+import json
+
+from keystoneauth1 import session
+from keystoneauth1.identity import v3
+
+from osm_mon.collector.utils.collector import CollectorUtils
+
+
+class OpenstackUtils:
+
+ @staticmethod
+ def get_session(vim_account_id: str):
+ creds = CollectorUtils.get_credentials(vim_account_id)
+ verify_ssl = CollectorUtils.is_verify_ssl(creds)
+ vim_config = json.loads(creds.config)
+ project_domain_name = 'Default'
+ user_domain_name = 'Default'
+ if 'project_domain_name' in vim_config:
+ project_domain_name = vim_config['project_domain_name']
+ if 'user_domain_name' in vim_config:
+ user_domain_name = vim_config['user_domain_name']
+ auth = v3.Password(auth_url=creds.url,
+ username=creds.user,
+ password=creds.password,
+ project_name=creds.tenant_name,
+ project_domain_name=project_domain_name,
+ user_domain_name=user_domain_name)
+ return session.Session(auth=auth, verify=verify_ssl)
import gnocchiclient.exceptions
from ceilometerclient.v2 import client as ceilometer_client
from gnocchiclient.v1 import client as gnocchi_client
-from keystoneauth1 import session
from keystoneauth1.exceptions.catalog import EndpointNotFound
-from keystoneauth1.identity import v3
from keystoneclient.v3 import client as keystone_client
from neutronclient.v2_0 import client as neutron_client
from osm_mon.collector.metric import Metric
-from osm_mon.collector.utils import CollectorUtils
+from osm_mon.collector.utils.openstack import OpenstackUtils
from osm_mon.collector.vnf_collectors.base_vim import BaseVimCollector
from osm_mon.collector.vnf_metric import VnfMetric
from osm_mon.core.common_db import CommonDbClient
self.backend = self._get_backend(vim_account_id)
def _build_keystone_client(self, vim_account_id: str) -> keystone_client.Client:
- sess = OpenstackBackend.get_session(vim_account_id)
+ sess = OpenstackUtils.get_session(vim_account_id)
return keystone_client.Client(session=sess)
def _get_resource_uuid(self, nsr_id: str, vnf_member_index: str, vdur_name: str) -> str:
def collect_metric(self, metric_type: MetricType, metric_name: str, resource_id: str, interface_name: str):
pass
- @staticmethod
- def get_session(vim_account_id: str):
- creds = CollectorUtils.get_credentials(vim_account_id)
- verify_ssl = CollectorUtils.is_verify_ssl(creds)
- auth = v3.Password(auth_url=creds.url,
- username=creds.user,
- password=creds.password,
- project_name=creds.tenant_name,
- project_domain_id='default',
- user_domain_id='default')
- return session.Session(auth=auth, verify=verify_ssl)
-
class GnocchiBackend(OpenstackBackend):
self.neutron = self._build_neutron_client(vim_account_id)
def _build_gnocchi_client(self, vim_account_id: str) -> gnocchi_client.Client:
- sess = OpenstackBackend.get_session(vim_account_id)
+ sess = OpenstackUtils.get_session(vim_account_id)
return gnocchi_client.Client(session=sess)
def _build_neutron_client(self, vim_account_id: str) -> neutron_client.Client:
- sess = OpenstackBackend.get_session(vim_account_id)
+ sess = OpenstackUtils.get_session(vim_account_id)
return neutron_client.Client(session=sess)
def collect_metric(self, metric_type: MetricType, metric_name: str, resource_id: str, interface_name: str):
self.client = self._build_ceilometer_client(vim_account_id)
def _build_ceilometer_client(self, vim_account_id: str) -> ceilometer_client.Client:
- sess = OpenstackBackend.get_session(vim_account_id)
+ sess = OpenstackUtils.get_session(vim_account_id)
return ceilometer_client.Client(session=sess)
def collect_metric(self, metric_type: MetricType, metric_name: str, resource_id: str, interface_name: str):
from keystoneauth1.identity import v3
from novaclient import client as nClient
-from osm_mon.collector.utils import CollectorUtils
+from osm_mon.collector.utils.collector import CollectorUtils
from osm_mon.collector.vnf_collectors.base_vim import BaseVimCollector
from osm_mon.collector.vnf_metric import VnfMetric
from osm_mon.core.common_db import CommonDbClient
from pyvcloud.vcd.client import BasicLoginCredentials
from pyvcloud.vcd.client import Client
-from osm_mon.collector.utils import CollectorUtils
+from osm_mon.collector.utils.collector import CollectorUtils
from osm_mon.collector.vnf_collectors.base_vim import BaseVimCollector
from osm_mon.collector.vnf_metric import VnfMetric
from osm_mon.core.common_db import CommonDbClient
from unittest import TestCase, mock
from osm_mon.collector.service import CollectorService
-from osm_mon.collector.utils import CollectorUtils
+from osm_mon.collector.utils.collector import CollectorUtils
from osm_mon.collector.vnf_collectors.openstack import OpenstackCollector
from osm_mon.core.common_db import CommonDbClient
from osm_mon.core.config import Config
##
from unittest import TestCase, mock
-from osm_mon.collector.utils import CollectorUtils
+from osm_mon.collector.utils.collector import CollectorUtils
from osm_mon.core.config import Config
from osm_mon.core.database import VimCredentialsRepository, VimCredentials