Пример #1
0
    def test_get_logger_one_handler(self):
        """
        We don't add a handler (causing spam multiple line outputs for a single msg)
        every time you call get_logger for the same logging object.
        """
        logger1 = get_logger('many_loggers')
        logger2 = get_logger('many_loggers')

        handlers = len(logger2.handlers)
        expected = 1

        self.assertEqual(handlers, expected)
Пример #2
0
 def __init__(self,
              user=const.DB_USER,
              password=const.DB_PASSWORD,
              database=const.DB_DATABASE_NAME,
              host=const.DB_HOST):
     self.logger = get_logger(__name__, loglevel=const.QUOTA_LOG_LEVEL)
     self._connection = psycopg2.connect(database=database,
                                         host=host,
                                         user=user,
                                         password=password)
     self._cursor = self._connection.cursor()
Пример #3
0
 def test_get_logger(self):
     """get_logger returns an instance of Pythons stdlib logging.Logger object"""
     logger = get_logger('single_logger')
     self.assertTrue(isinstance(logger, logging.Logger))
Пример #4
0
import time

import jwt
import ujson
import ldap3
from ldap3.core.exceptions import LDAPBindError, LDAPSocketOpenError, LDAPSASLPrepError
from redis import StrictRedis, RedisError
from flask import url_for
from flask_classy import request, Response
from vlab_api_common import BaseView, describe, get_logger
from jsonschema import validate, ValidationError

from vlab_auth_service.lib import const
from vlab_auth_service.lib.generate_token import generate_token, generate_v2_token

logger = get_logger(__name__, loglevel=const.AUTH_LOG_LEVEL)




class TokenView2(BaseView):
    """API end point for obtaining an version 2 schema auth token"""
    route_base = '/api/2/auth/token'
    version = 2
    POST_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#",
                    "type": "object",
                    "properties": {
                        "username": {
                            "type": "string",
                            "description": "The username to authenticate"
                        },
Пример #5
0
# -*- coding: UTF-8 -*-
"""
Defines the HTTP API for working with network gateways in vLab
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from jsonschema import validate, ValidationError
from vlab_inf_common.views import TaskView
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_gateway_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_GATEWAY_LOG_LEVEL)


class GatewayView(TaskView):
    """Defines the HTTP API for working with virtual local area networks"""
    route_base = '/api/2/inf/gateway'
    POST_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#",
                    "type": "object",
                    "properties": {
                        "wan": {
                            "description": "The name of the Wide Area Network to connect to",
                            "type": "string"
                        },
                        "lan": {
                            "description": "The name of the Local Area Network to connect to",
                            "type": "string"
                        }
                    },
Пример #6
0
# -*- coding: UTF-8 -*-
"""
Defines API for '/api/1/link' end point
"""
import hashlib
from collections import deque

import ujson
from flask import redirect, request, url_for
from flask_classy import route
from vlab_api_common import BaseView, describe, get_logger, validate_input
from vlab_api_common.http_auth import requires

from vlab_link_api.lib import const

logger = get_logger(__name__, loglevel=const.LINK_LOG_LEVEL)


class LinkView(BaseView):
    """End point for the Links URL shortner"""
    route_base = '/api/1/link'
    STORED_LINKS = deque(maxlen=const.LINK_MAX_COUNT)
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
            "url": {
                "type": "string",
                "description": "The URL you'd like a shorter version of"
            }
        },
Пример #7
0
# -*- coding: UTF-8 -*-
"""
Defines the RESTful API for working with snapshots in vLab
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import TaskView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input


from vlab_snapshot_api.lib import const


logger = get_logger(__name__, loglevel=const.VLAB_SNAPSHOT_LOG_LEVEL)


class SnapshotView(TaskView):
    """API end point for working with snapshots in vLab"""
    route_base = '/api/1/inf/snapshot'
    POST_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#",
                    "type": "object",
                    "description": "Create a snapshot; Maximum per VM is {}".format(const.VLAB_MAX_SNAPSHOTS),
                    "properties": {
                        "name": {
                            "description": "The virtual machine to take a snapshot of",
                            "type": "string"
                        },
                        "shift": {
                            "description": "When a VM has the maximum number of snaps, delete the oldest and take a new snapshot",
Пример #8
0
# -*- coding: UTF-8 -*-
"""
Defines the RESTful API for the ESRS deployment service
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input


from vlab_esrs_api.lib import const


logger = get_logger(__name__, loglevel=const.VLAB_ESRS_LOG_LEVEL)


class ESRSView(MachineView):
    """API end point for working with ESRS instances"""
    route_base = '/api/2/inf/esrs'
    RESOURCE = 'esrs'
    POST_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#",
                    "type": "object",
                    "description": "Create a ESRS instance",
                    "properties": {
                        "name": {
                            "description": "The name of your new ESRS instance",
                            "type": "string"
                        },
                        "image": {
Пример #9
0
# -*- coding: UTF-8 -*-
"""
Defines the RESTful API for managing instances of Microsoft Server
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_inf_common.input_validators import network_config_ok
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_winserver_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_WINSERVER_LOG_LEVEL)


class WinServerView(MachineView):
    """API end point for managing instances of Microsoft Server"""
    route_base = '/api/2/inf/winserver'
    RESOURCE = 'winserver'
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create a winserver",
        "properties": {
            "name": {
                "description": "The name to give your WinServer instance",
                "type": "string"
            },
            "image": {
Пример #10
0
# -*- coding: UTF-8 -*-
"""
Defines the RESTful API for the InsightIQ deployment service
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_insightiq_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_INSIGHTIQ_LOG_LEVEL)


class InsightIQView(MachineView):
    """API end point for InsightIQ instances"""
    route_base = '/api/2/inf/insightiq'
    RESOURCE = 'insightiq'
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create an InsightIQ instance",
        "properties": {
            "network": {
                "description": "The public network to connect InsightIQ to",
                "type": "string"
            },
            "name": {
                "description": "The name to give the new InsightIQ instance",
Пример #11
0
This module is for working with, and manipulating OVA files.
"""
import re
import os
import sys
import tarfile
import traceback
from threading import Timer
from urllib.request import urlopen, Request

from pyVmomi import vmodl
from vlab_api_common import get_logger

from vlab_inf_common.ssl_context import get_context

log = get_logger(__name__)


class Ova(object):
    """
    Represents an OVA file, and the contents within it.
    """
    def __init__(self, ovafile):
        """Performs necessary initialization, opening the OVA file,
        processing the files and reading the embedded ovf file.

        :param ovafile: **Required** The file path or URL of an OVA file
        :type ovafile: String
        """
        self._spec = None
        self._lease = None
Пример #12
0
# -*- coding: UTF-8 -*-
"""
This module defines the RESTful API for working with the jumpbox in your lab
"""
import ujson
from flask import current_app
from flask_classy import request, Response
from vlab_inf_common.views import TaskView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_jumpbox_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_JUMPBOX_LOG_LEVEL)


class JumpboxView(TaskView):
    """API end point for creating/deleting showing info about your jumpbox"""
    route_base = '/api/1/inf/jumpbox'
    DELETE_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "description": "Destroy your jumpbox"
    }
    GET_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "description": "Obtain information about your jump box"
    }
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create a new Jumpbox",
Пример #13
0
# -*- coding: UTF-8 -*-
"""
TODO
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_superna_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_SUPERNA_LOG_LEVEL)


class SupernaView(MachineView):
    """API end point TODO"""
    route_base = '/api/2/inf/superna'
    RESOURCE = 'superna'
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create a Superna server",
        "properties": {
            "name": {
                "description": "The name to give your Superna instance",
                "type": "string"
            },
            "image": {
                "description": "The image/version of Superna to create",
Пример #14
0
# -*- coding: UTF-8 -*-
"""Defines the API for checking if a user has exceeded their inventory quota"""
import ujson
from flask_classy import request, Response
from vlab_api_common import BaseView, get_logger, describe, requires

from vlab_quota.libs import const, Database

logger = get_logger(__name__, loglevel=const.QUOTA_LOG_LEVEL)


class QuotaView(BaseView):
    """API end point for checking on quota violations"""
    route_base = '/api/1/quota'
    GET_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "description": "Return quota information"
    }

    @requires(verify=const.VLAB_VERIFY_TOKEN, version=2)
    @describe(get=GET_SCHEMA)
    def get(self, *args, **kwargs):
        """Obtain quota information"""
        username = kwargs['token']['username']
        with Database() as db:
            exceeded_on, last_notified = db.user_info(username)
        resp_data = {
            'content': {
                'exceeded_on': exceeded_on,
                'last_notified': last_notified,
                'grace_period': const.QUOTA_GRACE_PERIOD,
Пример #15
0
# -*- coding: UTF-8 -*-
"""
Defines the RESTful API for deploying/managing a DataIQ instance
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_inf_common.input_validators import network_config_ok
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_dataiq_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_DATAIQ_LOG_LEVEL)


class DataIQView(MachineView):
    """API end point for DataIQ"""
    route_base = '/api/2/inf/dataiq'
    RESOURCE = 'dataiq'
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create a dataiq",
        "properties": {
            "name": {
                "description": "The name to give your DataIQ instance",
                "type": "string"
            },
            "image": {
Пример #16
0
# -*- coding: UTF-8 -*-
"""
This module defines the API for tracking your vLab inventory
"""
import ujson
from flask import current_app
from flask_classy import request, Response
from vlab_inf_common.views import TaskView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires


from vlab_inventory_api.lib import const


logger = get_logger(__name__, loglevel=const.VLAB_INVENTORY_LOG_LEVEL)


class InventoryView(TaskView):
    """API end point for working with user folders"""
    route_base = '/api/1/inf/inventory'
    GET_SCHEMA = {"$schema": "http://json-schema.org/draft-04/schema#",
                  "description": "Return all the virtual machines a user owns"
                 }
    DELETE_SCHEMA = {"$schema": "http://json-schema.org/draft-04/schema#",
                     "description": "Destroy the user's inventory record"
                    }
    POST_SCHEMA = {"$schema": "http://json-schema.org/draft-04/schema#",
                   "description": "Create a new record so a user can track their inventory of virtual machines"
                  }
Пример #17
0
# -*- coding: UTF-8 -*-
"""
Defines the API for common infrastructure API end points
"""
from abc import abstractmethod

import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_api_common import describe, BaseView, requires, get_logger, validate_input

from vlab_inf_common.constants import const

logger = get_logger(__name__, loglevel='INFO')


class TaskView(BaseView):
    """Defines the ``/<route_base>/task`` end point for async API actions"""
    TASK_ARGS = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
            "task-id": {
                "description":
                "The Task Id. Optionally index the URL with the task id",
                "type": "string"
            }
        },
        "required": ["task-id"]
    }
Пример #18
0
# -*- coding: UTF-8 -*-
"""
This module defines the API for working with auth tokens in vLab.
"""
import ujson
from flask import current_app
from flask_classy import request, Response
from vlab_inf_common.views import TaskView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_power_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_POWER_LOG_LEVEL)


class PowerView(TaskView):
    """API end point for turning on, off, or restarting virtual machines"""
    route_base = '/api/1/inf/power'
    GET_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "description": "Return all the virtual machines a user owns"
    }
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
            "power": {
                "oneOf": [{
                    "type": "string",
                    "pattern": "on"
Пример #19
0
# -*- coding: UTF-8 -*-
"""
Defines the RESTful API for deploying Windows desktop clients
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_windows_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_WINDOWS_LOG_LEVEL)


class WindowsView(MachineView):
    """API end point for working with Windows desktop VMs"""
    route_base = '/api/2/inf/windows'
    RESOURCE = 'windows'
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create a windows",
        "properties": {
            "name": {
                "description": "The name to give your Windows instance",
                "type": "string"
            },
            "image": {
                "description": "The image/version of Windows to create",
Пример #20
0
# -*- coding: UTF-8 -*-
"""
Defines the RESTful API for the ClarityNow service
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_claritynow_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_CLARITYNOW_LOG_LEVEL)


class ClarityNowView(MachineView):
    """API end point to manage ClarityNow instances"""
    route_base = '/api/2/inf/claritynow'
    RESOURCE = 'claritynow'
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create a claritynow",
        "properties": {
            "name": {
                "description": "The name to give your ClarityNow instance",
                "type": "string"
            },
            "image": {
                "description": "The image/version of ClarityNow to create",
Пример #21
0
# -*- coding: UTF-8 -*-
"""
Defines the HTTP API for working with deployments in vLab.
"""
import ujson
from flask import current_app
from flask_classy import request, route, Response
from vlab_inf_common.views import MachineView
from vlab_inf_common.vmware import vCenter, vim
from vlab_api_common import describe, get_logger, requires, validate_input

from vlab_deployment_api.lib import const

logger = get_logger(__name__, loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL)


class DeploymentView(MachineView):
    """API end points for vLab deployments"""
    route_base = '/api/2/inf/deployment'
    RESOURCE = 'deployment'
    POST_SCHEMA = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "description": "Create a deployment",
        "properties": {
            "template": {
                "description":
                "The name for a set of images that make up a deployment.",
                "type": "string"
            }
        },