Esempio n. 1
0
LOG = logging.getLogger(__name__)


# API static values
VOLUME_STATE_AVAILABLE = "available"
DEFAULT_QUOTA_NAME = 'default'

# Available consumer choices associated with QOS Specs
CONSUMER_CHOICES = (
    ('back-end', _('back-end')),
    ('front-end', _('front-end')),
    ('both', pgettext_lazy('Both of front-end and back-end', u'both')),
)

VERSIONS = base.APIVersionManager("volume", preferred_version=2)

try:
    from cinderclient.v2 import client as cinder_client_v2
    VERSIONS.load_supported_version(2, {"client": cinder_client_v2,
                                        "version": 2})
except ImportError:
    pass


class BaseCinderAPIResourceWrapper(base.APIResourceWrapper):

    @property
    def name(self):
        # If a volume doesn't have a name, use its id.
        return (getattr(self._apiresource, 'name', None) or
Esempio n. 2
0
from horizon import exceptions
from horizon import exceptions as horizon_exceptions
from horizon.utils import functions as utils
from horizon.utils.memoized import memoized
from horizon.utils.memoized import memoized_with_request

from openstack_auth import utils as auth_utils
from openstack_dashboard.api import base
from openstack_dashboard.api import microversions
from openstack_dashboard.contrib.developer.profiler import api as profiler

LOG = logging.getLogger(__name__)

# Supported compute versions
VERSIONS = base.APIVersionManager("compute", preferred_version='2.53')
VERSIONS.load_supported_version(1.1, {"client": nova_client, "version": 1.1})
VERSIONS.load_supported_version(2, {"client": nova_client, "version": 2})

# API static values
INSTANCE_ACTIVE_STATE = 'ACTIVE'
VOLUME_STATE_AVAILABLE = "available"
DEFAULT_QUOTA_NAME = 'default'
INSECURE = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
CACERT = getattr(settings, 'OPENSTACK_SSL_CACERT', None)


@memoized
def get_microversion(request, feature):
    client = novaclient(request)
    min_ver, max_ver = api_versions._get_server_version_range(client)
Esempio n. 3
0
#    License for the specific language governing permissions and limitations
#    under the License.

from django.conf import settings
from horizon.utils import functions as utils
from horizon.utils.memoized import memoized  # noqa
from keystoneauth1 import session
from keystoneclient.auth import token_endpoint
from novaclient import client as nova_client
from openstack_auth import utils as auth_utils
from openstack_dashboard.api import base
from oslo_log import log as logging
from troveclient.v1 import client

# Supported compute versions
NOVA_VERSIONS = base.APIVersionManager("compute", preferred_version=2)
NOVA_VERSIONS.load_supported_version(1.1, {
    "client": nova_client,
    "version": 1.1
})
NOVA_VERSIONS.load_supported_version(2, {"client": nova_client, "version": 2})
NOVA_VERSION = NOVA_VERSIONS.get_active_version()['version']

LOG = logging.getLogger(__name__)


@memoized
def troveclient(request):
    insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
    cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
    endpoint_type = getattr(settings, 'OPENSTACK_ENDPOINT_TYPE', 'publicURL')
Esempio n. 4
0
from horizon import exceptions
from horizon.utils import functions
from horizon.utils.memoized import memoized  # noqa
from openstack_dashboard.api import base

from sahara_dashboard import utils as u

# "type" of Sahara service registered in keystone
SAHARA_SERVICE = 'data-processing'
# Sahara service_type registered in Juno
SAHARA_SERVICE_FALLBACK = 'data_processing'

SAHARA_AUTO_IP_ALLOCATION_ENABLED = getattr(
    settings, 'SAHARA_AUTO_IP_ALLOCATION_ENABLED', False)
VERSIONS = base.APIVersionManager(SAHARA_SERVICE,
                                  preferred_version=getattr(
                                      settings, 'OPENSTACK_API_VERSIONS',
                                      {}).get(SAHARA_SERVICE, 1.1))
VERSIONS.load_supported_version(1.1, {"client": api_client, "version": 1.1})

SAHARA_PAGE_SIZE = 15


def get_page_size(request=None):
    if request:
        return functions.get_page_size(request)
    else:
        return SAHARA_PAGE_SIZE


def _get_marker(request):
    return request.GET["marker"] if 'marker' in request.GET else None
from rfc6238 import totp

# keystone client
from keystoneauth1.identity import v3 as v3_plugin
from keystoneclient.v3 import client as v3_client
from keystoneauth1 import session as keystone_session

# openstack dashboard api import
from openstack_dashboard.api import base as api_base
from openstack_dashboard.api import keystone

from openstack_dashboard import settings
from openstack_dashboard.auth.exception import IllegalArgument, InvalidToken, TOTPRuntimeError

LOG = logging.getLogger(__name__)
KS_VERSION = api_base.APIVersionManager('identity', preferred_version=3)

# custom keystone property to read from the database
TOTP_KEY_ATTRIBUTE = "totp_key"
EMAIL_ATTRIBUTE = "email"
KEYSTONE_URL = getattr(settings, "OPENSTACK_KEYSTONE_URL", None)
TOTP_TTL = getattr(settings, "TOTP_VALIDITY_PERIOD", 30)


# TOTP Token Oracle
# This class does all verification work.
class TOTPOracle(object):
    def __init__(self,
                 auth_url=None,
                 user_data=None,
                 username=None,
Esempio n. 6
0
from keystoneauth1.identity import v3 as v3_plugin
from keystoneauth1 import session as keystone_session
from django.conf import settings

# import base api library from openstack dashboard codebase
from openstack_dashboard.api import base as api_base
from openstack_dashboard.api import keystone
from horizon.utils import functions as utils
from horizon.utils.memoized import memoized

# import designate SDK libraries
from designateclient.v2 import client as designate_client

LOG = logging.getLogger(__name__)

KS_VERSION = api_base.APIVersionManager("identity", preferred_version=3)
VERSION = api_base.APIVersionManager("dns", preferred_version=2)
try:
    VERSION.load_supported_version(2, {
        "client": designate_client,
        "version": 2
    })
except ImportError:
    LOG.error("VERSION.load_supported_versions FAILED.")

DEBUGLOG = True


def logwrap_info(message):
    if DEBUGLOG:
        LOG.info("DESIGNATE API WRAPPER: %s" % message)
Esempio n. 7
0
import logging

from django.conf import settings

from horizon import exceptions
from horizon.utils.memoized import memoized  # noqa
from sdsclient.v1 import client as sds_client
from sdsclient.v1.contrib import list_extensions as sds_list_extensions

from openstack_dashboard.api import base

LOG = logging.getLogger(__name__)

#NOTE(fengqian): SDS only have API v1
VERSIONS = base.APIVersionManager("sds", preferred_version=1)
VERSIONS.load_supported_version(1, {"client": sds_client, "version": 1})


@memoized
def sdsclient(request):
    api_version = VERSIONS.get_active_version()
    insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
    cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)

    try:
        sds_url = base.url_for(request, "storage_controller_v1")
    except exceptions.ServiceCatalogException:
        LOG.error("No sds service")
        raise
Esempio n. 8
0
from django.conf import settings
import datetime
import time
import logging

import requests

from openstack_dashboard.api import base

from horizon.utils.memoized import memoized
# from horizon.utils.memoized import memoized_with_request
from horizon import exceptions

LOG = logging.getLogger(__name__)

VERSIONS = base.APIVersionManager("vmexpire",
                                  preferred_version=base.Version(1))


def get_auth_params_from_request(request):
    auth_url = base.url_for(request, 'identity')
    vmexpire_urls = []
    for service_name in ('vmexpire', ):
        try:
            vmexpire_url = base.url_for(request, service_name)
            vmexpire_urls.append((service_name, vmexpire_url))
        except exceptions.ServiceCatalogException:
            pass
    if not vmexpire_urls:
        raise exceptions.ServiceCatalogException(
            "no vmexpire service configured")
    vmexpire_urls = tuple(vmexpire_urls)  # need to make it cacheable
Esempio n. 9
0
from openstack_dashboard.api import base

from monascaclient import client as mon_client
from monitoring.config import local_settings as settings

LOG = logging.getLogger(__name__)

INSECURE = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
CACERT = getattr(settings, 'OPENSTACK_SSL_CACERT', None)

KEYSTONE_SERVICE = 'identity'
MONITORING_SERVICE = getattr(settings, 'MONITORING_SERVICE_TYPE', 'monitoring')

VERSIONS = base.APIVersionManager(MONITORING_SERVICE,
                                  preferred_version=getattr(
                                      settings, 'OPENSTACK_API_VERSIONS',
                                      {}).get(MONITORING_SERVICE, 2.0))
VERSIONS.load_supported_version(2.0, {'client': mon_client, 'version': '2_0'})


def _get_endpoint(request):
    try:
        endpoint = base.url_for(
            request,
            service_type=settings.MONITORING_SERVICE_TYPE,
            endpoint_type=settings.MONITORING_ENDPOINT_TYPE)
    except exceptions.ServiceCatalogException:
        endpoint = 'http://127.0.0.1:8070/v2.0'
        LOG.warning('Monasca API location could not be found in Service '
                    'Catalog, using default: {0}'.format(endpoint))
    return endpoint