# Path: blazar/context.py
# CONF = cfg.CONF
#     FROM_DICT_EXTRA_KEYS = ['service_catalog']
# class BlazarContext(context.RequestContext):
#     def __init__(self, service_catalog=None, **kwargs):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def current(cls):
#     def to_dict(self):
#     def admin(cls):
# def current():
# def admin():
# 
# Path: blazar/utils/openstack/base.py
# CONF = cfg.CONF
# def get_os_auth_host(conf):
# def url_for(service_catalog, service_type, admin=False,
#             endpoint_interface=None,
#             os_region_name=None):


import uuid as uuidgen
from keystoneauth1 import session
from keystoneauth1 import token_endpoint
from novaclient import client as nova_client
from novaclient import exceptions as nova_exception
from novaclient.v2 import servers
from oslo_config import cfg
from oslo_log import log as logging
from blazar import context
from blazar.manager import exceptions as manager_exceptions
from blazar.plugins import oshosts
from blazar.utils.openstack import base
            # FIXME(scroiset): can't get an aggregate by name
            # so iter over all aggregate and check for the good one
            all_aggregates = self.nova.aggregates.list()
            for agg in all_aggregates:
                if aggregate_obj == agg.name:
                    aggregate = agg
        if aggregate:
            return aggregate
        else:
            raise manager_exceptions.AggregateNotFound(pool=aggregate_obj)

    @staticmethod
    def _generate_aggregate_name():
        return str(uuidgen.uuid4())

    def create(self, name=None, az=None, metadata=None):
        """Create a Pool (an Aggregate) with or without Availability Zone.

        By default expose to user the aggregate with an Availability Zone.
        Return an aggregate or raise a nova exception.

        """

        name = name or self._generate_aggregate_name()

        LOG.debug('Creating pool aggregate: %(name)s with Availability Zone '
                  '%(az)s', {'name': name, 'az': az})
        agg = self.nova.aggregates.create(name, az)

        try:

# Path: blazar/context.py
# CONF = cfg.CONF
#     FROM_DICT_EXTRA_KEYS = ['service_catalog']
# class BlazarContext(context.RequestContext):
#     def __init__(self, service_catalog=None, **kwargs):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def current(cls):
#     def to_dict(self):
#     def admin(cls):
# def current():
# def admin():
# 
# Path: blazar/utils/openstack/base.py
# CONF = cfg.CONF
# def get_os_auth_host(conf):
# def url_for(service_catalog, service_type, admin=False,
#             endpoint_interface=None,
#             os_region_name=None):


# Path: blazar/utils/openstack/nova.py
import uuid as uuidgen
from keystoneauth1 import session
from keystoneauth1 import token_endpoint
from novaclient import client as nova_client
from novaclient import exceptions as nova_exception
from novaclient.v2 import servers
from oslo_config import cfg
from oslo_log import log as logging
from blazar import context
from blazar.manager import exceptions as manager_exceptions
from blazar.plugins import oshosts
from blazar.utils.openstack import base

            # FIXME(scroiset): can't get an aggregate by name
            # so iter over all aggregate and check for the good one
            all_aggregates = self.nova.aggregates.list()
            for agg in all_aggregates:
                if aggregate_obj == agg.name:
                    aggregate = agg
        if aggregate:
            return aggregate
        else:
            raise manager_exceptions.AggregateNotFound(pool=aggregate_obj)

    @staticmethod
    def _generate_aggregate_name():
        return str(uuidgen.uuid4())

    def create(self, name=None, az=None, metadata=None):
        """Create a Pool (an Aggregate) with or without Availability Zone.

        By default expose to user the aggregate with an Availability Zone.
        Return an aggregate or raise a nova exception.

        """

        name = name or self._generate_aggregate_name()

        LOG.debug('Creating pool aggregate: %(name)s with Availability Zone '
                  '%(az)s', {'name': name, 'az': az})
        agg = self.nova.aggregates.create(name, az)

        try:

            ctx = context.current()