Example #1
0
def set_neutron_quota_set(project: keystone.ProjectType = None,
                          client: _client.NeutronClientType = None,
                          **quota):
    client = _client.neutron_client(client)
    project = keystone.get_project_id(project=project,
                                      session=client.httpclient.session)
    return client.update_quota(project, body={'quota': quota})['quota']
Example #2
0
def get_neutron_quota_set(project: keystone.ProjectType = None,
                          client: _client.NeutronClientType = None,
                          detail=False,
                          **params):
    client = _client.neutron_client(client)
    project = keystone.get_project_id(project=project,
                                      session=client.httpclient.session)
    if detail:
        return client.show_quota_details(project, **params)['quota']
    else:
        return client.show_quota(project, **params)['quota']
Example #3
0
def ensure_neutron_quota_limits(project: keystone.ProjectType = None,
                                client: _client.NeutronClientType = None,
                                retry_timeout: tobiko.Seconds = None,
                                retry_interval: tobiko.Seconds = None,
                                **required_quotas: int) -> None:
    if not required_quotas:
        return
    client = _client.neutron_client(client)
    project = keystone.get_project_id(project=project,
                                      session=client.httpclient.session)
    for attempt in tobiko.retry(timeout=retry_timeout,
                                interval=retry_interval,
                                default_timeout=60.,
                                default_interval=3.):
        actual_limits, expected_limits = get_neutron_quota_limits_increase(
            project=project, client=client, extra_increase=10//attempt.number,
            **required_quotas)
        if expected_limits:
            if attempt.is_last:
                raise EnsureNeutronQuotaLimitsError(
                    project=project,
                    actual_limits=actual_limits,
                    expected_limits=expected_limits)
            LOG.info(f"Increase Neutron quota limit(s) (project={project}): "
                     f"{actual_limits} -> {expected_limits}...")
            try:
                set_neutron_quota_set(project=project, client=client,
                                      **expected_limits)
            except Exception as ex:
                if attempt.is_last:
                    raise
                LOG.exception("Unable to ensure Neutron quota set limits: "
                              f"{expected_limits}: {ex}")
        else:
            LOG.debug(f"Required quota limits are OK: {required_quotas}")
            break
    else:
        raise RuntimeError("Broken retry loop")
Example #4
0
 def setup_client(self):
     self.client = _client.neutron_client(self.client)
Example #5
0
def create_network(client=None, **params) -> NeutronNetworkType:
    return _client.neutron_client(client).create_network(
        body={'network': params})['network']
Example #6
0
def delete_network(network, client=None):
    return _client.neutron_client(client).delete_network(network=network)
Example #7
0
def list_networks(client=None, **params) -> \
        tobiko.Selection[NeutronNetworkType]:
    networks = _client.neutron_client(client).list_networks(
        **params)['networks']
    return tobiko.select(networks)
Example #8
0
def get_network(network, client=None, **params) -> NeutronNetworkType:
    try:
        return _client.neutron_client(
            client).show_network(network, **params)['network']
    except _client.neutronclient.exceptions.NotFound as ex:
        raise NoSuchNetwork(id=network) from ex
Example #9
0
def list_dhcp_agent_hosting_network(network, client=None, **params):
    agents = _client.neutron_client(client).list_dhcp_agent_hosting_networks(
        network, **params)
    if isinstance(agents, abc.Mapping):
        agents = agents['agents']
    return tobiko.select(agents)
Example #10
0
def list_l3_agent_hosting_routers(router, client=None, **params):
    agents = _client.neutron_client(client).list_l3_agent_hosting_routers(
        router, **params)
    if isinstance(agents, abc.Mapping):
        agents = agents['agents']
    return tobiko.select(agents)
Example #11
0
def list_agents(client=None, **params) \
        -> tobiko.Selection[NeutronAgentType]:
    agents = _client.neutron_client(client).list_agents(**params)
    if isinstance(agents, abc.Mapping):
        agents = agents['agents']
    return tobiko.Selection[NeutronAgentType](agents)