Merge "Fix warnings in all snaps-related modules"
[functest-xtesting.git] / functest / opnfv_tests / openstack / snaps / snaps_utils.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # pylint: disable=missing-docstring
11
12 from functest.utils.constants import CONST
13
14 from snaps.openstack.utils import neutron_utils, nova_utils
15
16
17 def get_ext_net_name(os_creds):
18     """
19     Returns the configured external network name or
20     the first retrieved external network name
21     :param: os_creds: an instance of snaps OSCreds object
22     :return:
23     """
24     neutron = neutron_utils.neutron_client(os_creds)
25     ext_nets = neutron_utils.get_external_networks(neutron)
26     if hasattr(CONST, 'EXTERNAL_NETWORK'):
27         extnet_config = CONST.__getattribute__('EXTERNAL_NETWORK')
28         for ext_net in ext_nets:
29             if ext_net.name == extnet_config:
30                 return extnet_config
31     return ext_nets[0].name if ext_nets else ""
32
33
34 def get_active_compute_cnt(os_creds):
35     """
36     Returns the number of active compute servers
37     :param: os_creds: an instance of snaps OSCreds object
38     :return: the number of active compute servers
39     """
40     nova = nova_utils.nova_client(os_creds)
41     computes = nova_utils.get_availability_zone_hosts(nova, zone_name='nova')
42     return len(computes)