예제 #1
0
def get_swift_storage_topology(model_name=None):
    """Get details of storage nodes and which region and zones they belong in.

    :param model_name: Model to point environment at
    :type model_name: str
    :returns: Dictionary of storage nodes and their region/zone information.
    :rtype: {
        'ip (str)': {
            'app_name': str,
            'unit': juju.Unit
            'region': int,
            'zone': int},
        ...}
    """
    topology = {}
    status = juju_utils.get_full_juju_status(model_name=model_name)
    for app_name, app_dep_config in status.applications.items():
        if 'swift-storage' in app_dep_config['charm']:
            app_config = zaza.model.get_application_config(
                app_name, model_name=model_name)
            region = app_config['storage-region']['value']
            zone = app_config['zone']['value']
            for unit in zaza.model.get_units(app_name, model_name=model_name):
                topology[zaza.model.get_unit_public_address(unit)] = {
                    'app_name': app_name,
                    'unit': unit,
                    'region': region,
                    'zone': zone
                }
    return topology
예제 #2
0
def get_juju_status(application=None, unit=None):
    if application:
        return juju_utils.get_application_status(application=application,
                                                 unit=unit)
    if unit:
        application = unit.split('/')[0]
        return juju_utils.get_application_status(application=application,
                                                 unit=unit)
    return json.loads(juju_utils.get_full_juju_status().to_json())
예제 #3
0
 def test_get_full_juju_status(self):
     self.assertEqual(juju_utils.get_full_juju_status(), self.juju_status)
     self.model.get_status.assert_called_once_with(model_name=None)
        allocation_pools = subnet['allocation_pools']
        self.cidr = subnet['cidr']
        self.highest_assigned = netaddr.IPAddress(allocation_pools[0]['end'])
        # XXX look away now, nothing to see here, move along.
        #     If there is less than 30 free ips in the network after the top
        #     dhcp ip then eat into the top of the dhcp range
        available_ips = []
        for element in list(netaddr.IPNetwork(self.cidr)):
            if element == netaddr.IPAddress(self.highest_assigned) or \
                    available_ips:
                available_ips.append(element)
        if len(available_ips) < 30:
            self.highest_assigned = self.highest_assigned - 30

    def get_next(self):
        next_ip = self.highest_assigned + 1
        if next_ip in list(netaddr.IPNetwork(self.cidr)):
            self.highest_assigned = self.highest_assigned + 1
            return next_ip
        else:
            raise Exception("vip pool exhausted")


cli_utils.setup_logging()
vp = VipPool()
juju_status = juju_utils.get_full_juju_status()
for application in juju_status.applications.keys():
    if 'vip' in model.get_application_config(application).keys():
        model.set_application_config(application, {'vip': vp.get_next()})
mojo_utils.juju_wait_finished()
예제 #5
0
def get_subordinate_applications():
    return [
        application for application in
        juju_utils.get_full_juju_status().applications.keys()
        if juju_utils.get_application_status(application)['subordinate-to']
    ]