Esempio n. 1
0
def create(self, username, wan, lan, txn_id):
    """Deploy a new default gateway

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new default gateway
    :type username: String

    :param network: The name of the network that the jumpbox connects to.
    :type network: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_GATEWAY_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    try:
        logger.info('Task starting')
        resp['content'] = vmware.create_gateway(username, wan, lan, logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 2
0
def delete(self, username, machine_name, txn_id):
    """Destroy an instance of InsightIQ

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new default gateway
    :type username: String

    :param machine_name: The name of the instance of insightiq
    :type machine_name: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_INSIGHTIQ_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        vmware.delete_insightiq(username, machine_name, logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    else:
        logger.info('Task complete')
    return resp
Esempio n. 3
0
def create(self, username, machine_name, image, network, txn_id):
    """Deploy a new shinny instance of InsightIQ

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new default gateway
    :type username: String

    :param machine_name: The name to give your new IIQ instance
    :type machine_name: String

    :param image: The version/image of IIQ to create
    :type image: String

    :param network: The network to connect IIQ to
    :type network: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_INSIGHTIQ_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        resp['content'] = vmware.create_insightiq(username, machine_name,
                                                  image, network, logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 4
0
def show(self, username, txn_id):
    """Obtain basic information about the deployment in a user's lab.

    :Returns: Dictionary

    :param username: The name of the user who wants info about their default gateway
    :type username: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        info = vmware.show_deployment(username)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    else:
        logger.info('Task complete')
        resp['content'] = info
    return resp
Esempio n. 5
0
def create(self, username, machine_name, image, network, txn_id):
    """Deploy a new instance of Kemp

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new Kemp
    :type username: String

    :param machine_name: The name of the new instance of Kemp
    :type machine_name: String

    :param image: The image/version of Kemp to create
    :type image: String

    :param network: The name of the network to connect the new Kemp instance up to
    :type network: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_KEMP_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        resp['content'] = vmware.create_kemp(username, machine_name, image,
                                             network, logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 6
0
def show(self, username, txn_id):
    """Obtain information about all virtual machines a user owns

    :Returns: Dictionary

    :param username: The owner of the virtual machines
    :type username: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_INVENTORY_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task Starting')
    try:
        info = vmware.show_inventory(username)
    except (FileNotFoundError, ValueError):
        status = 404
        resp[
            'error'] = 'User {} has no inventory. HINT: Has the lab been initialized yet?'.format(
                username)
    else:
        resp['content'] = info
    logger.info('Task Complete')
    return resp
Esempio n. 7
0
def delete_template(self, username, template, txn_id):
    """Destroy a deployment template that a user owns.

    :Returns: Dictionary

    :param username: The name of a user trying to delete a deployment template.
    :type username: String

    :param template: The name of the deployment template to destroy.
    :type template: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        templates.delete(username, template)
    except ValueError as doh:
        logger.error("Task failed")
        resp['error'] = '{}'.format(doh)
    else:
        logger.info("Task complete")
    return resp
Esempio n. 8
0
def modify_template(self, username, template, summary, owner, txn_id):
    """Make minor changes to a deployment template.

    :Returns: Dictionary

    :param username: The name of the user that currently owns the template.
    :type username: String

    :param template: The name of the deployment template.
    :type template: String

    :param summary: A short description of the template.
    :type summary: String

    :param owner: The username of the new template owner.
    :type owner: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        templates.modify(username, template, summary, owner)
    except ValueError as doh:
        logger.error("Task failed")
        resp['error'] = '{}'.format(doh)
    else:
        logger.info("Task complete")
    return resp
Esempio n. 9
0
def show(self, username, txn_id):
    """Obtain all the snapshots on the machines a user owns

    :Returns: Dictionary

    :param username: The name of the user who wants info about snapshots in their lab
    :type username: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_SNAPSHOT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        info = vmware.show_snapshot(username)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    else:
        logger.info('Task complete')
        resp['content'] = info
    return resp
Esempio n. 10
0
def create(self, username, machine_name, shift, txn_id):
    """Create a new snapshot on a user's virtual machine

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new Snapshot
    :type username: String

    :param machine_name: The name of the virtual machine to snapshot
    :type machine_name: String

    :param shift: When a VM already has the maximum number of snapshots, automatically
                  delete the oldest snapshot and take a new snapshot.
    :type shift: Boolean

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_SNAPSHOT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        resp['content'] = vmware.create_snapshot(username, machine_name, shift,
                                                 logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 11
0
def delete(self, username, vlan_name, txn_id):
    """Delete a vLAN owned by the user.

    :Returns: Dictionary

    :param username: The name of the user who wants to destroy a vLAN.
    :type username: String

    :param vlan_name: The kind of vLAN to make, like FrontEnd or BackEnd
    :type vlan_name: String
    """
    logger = get_task_logger(txn_id=txn_id, task_id=self.request.id, loglevel=const.VLAB_VLAN_LOG_LEVEL.upper())
    resp = {'error' : None, 'content': {}, 'params': {'vlan_name': vlan_name}}
    logger.info('Task Starting')
    owns = database.get_vlan(username).get(vlan_name, None)
    if not owns:
        error = "Unable to delete vLAN you do not own"
        resp['error'] = error
        return resp
    try:
        delete_network(vlan_name)
    except ValueError as doh:
        logger.exception(doh)
        resp['error'] = '{}'.format(doh)
        return resp
    try:
        database.delete_vlan(username=username, vlan_name=vlan_name)
    except (RuntimeError, ValueError) as doh:
        resp['error'] = '{}'.format(doh)
    logger.info('Task Completed')
    return resp
Esempio n. 12
0
def delete(self, username, snap_id, machine_name, txn_id):
    """Destroy a Snapshot

    :Returns: Dictionary

    :param username: The name of the user who wants to delete an instance of Snapshot
    :type username: String

    :param snap_id: The snapshot to destroy
    :type snap_id: Integer

    :param machine_name: The name of the virtual machine which owns the snapshot
    :type machine_name: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_SNAPSHOT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        vmware.delete_snapshot(username, snap_id, machine_name, logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    else:
        logger.info('Task complete')
    return resp
Esempio n. 13
0
    def test_get_task_logger_contains(self):
        """``get_task_logger`` contains the txn_id and task_id"""
        log = get_task_logger(txn_id='myId', task_id='aabbcc')

        format = log.logger.handlers[0].formatter._fmt
        expected_format = '%(asctime)s [%(txn_id)s] [%(task_id)s]: %(message)s'
        expected_extra = {'txn_id': 'myId', 'task_id': 'aabbcc'}

        self.assertEqual(format, expected_format)
        self.assertEqual(log.extra, expected_extra)
Esempio n. 14
0
def modify_network(self, username, machine_name, new_network, txn_id):
    """Change the network an ESRS instance is connected to"""
    logger = get_task_logger(txn_id=txn_id, task_id=self.request.id, loglevel=const.VLAB_ESRS_LOG_LEVEL.upper())
    resp = {'content' : {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        vmware.update_network(username, machine_name, new_network)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 15
0
def image(self, txn_id):
    """Obtain a list of available images/versions of CentOS that can be created

    :Returns: Dictionary

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id, task_id=self.request.id, loglevel=const.VLAB_CENTOS_LOG_LEVEL.upper())
    resp = {'content' : {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    resp['content'] = {'image': vmware.list_images()}
    logger.info('Task complete')
    return resp
Esempio n. 16
0
def create(self, username, machine_name, image, network, static_ip,
           default_gateway, netmask, dns, txn_id):
    """Deploy a new instance of Dns

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new Dns
    :type username: String

    :param machine_name: The name of the new instance of Dns
    :type machine_name: String

    :param image: The image/version of Dns to create
    :type image: String

    :param network: The name of the network to connect the new Dns instance up to
    :type network: String

    :param static_ip: The IPv4 address to assign to the VM
    :type static_ip: String

    :param default_gateway: The IPv4 address of the network gateway
    :type default_gateway: String

    :param netmask: The subnet mask of the network, i.e. 255.255.255.0
    :type netmask: String

    :param dns: A list of DNS servers to use.
    :type dns: List

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DNS_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        resp['content'] = vmware.create_dns(username, machine_name, image,
                                            network, static_ip,
                                            default_gateway, netmask, dns,
                                            logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 17
0
def image(self, txn_id):
    """Obtain a list of the available images/versions of ESRS that can be deployed

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new default gateway
    :type username: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id, task_id=self.request.id, loglevel=const.VLAB_ESRS_LOG_LEVEL.upper())
    resp = {'content' : {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    resp['content'] = {'image': vmware.list_images()}
    logger.info('Task complete')
    return resp
Esempio n. 18
0
def create(self, username, machine_name, image, network, desktop, ram, cpu_count, txn_id):
    """Deploy a new instance of CentOS

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new CentOS
    :type username: String

    :param machine_name: The name of the new instance of CentOS
    :type machine_name: String

    :param image: The image/version of CentOS to create
    :type image: String

    :param network: The name of the network to connect the new CentOS instance up to
    :type network: String

    :param desktop: Deploy the VM with a GUI
    :type desktop: Boolean

    :param ram: The number of GB of RAM to allocate for the VM
    :type ram: Integer

    :param cpu_count: The number of CPU cores to allocate for the VM
    :type cpu_count: Integer

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id, task_id=self.request.id, loglevel=const.VLAB_CENTOS_LOG_LEVEL.upper())
    resp = {'content' : {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        resp['content'] = vmware.create_centos(username,
                                               machine_name,
                                               image,
                                               network,
                                               desktop,
                                               ram,
                                               cpu_count,
                                               logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 19
0
def create(self, username, machine_name, image, front_end, back_end, ram,
           cpu_count, txn_id):
    """Deploy a new OneFS node

    :Returns: Dictionary

    :param username: The name of the user who wants to create a new default gateway
    :type username: String

    :param machine_name: The name of the new OneFS node
    :type machine_name: String

    :param image: The image version of OneFS to create
    :type image: String

    :param front_end: The network to hook up the external network to
    :type front_end: String

    :param back_end: The network to hook the internal network to
    :type back_end: String

    :param ram: The number of GB of memory to provision the node with
    :type ram: Integer

    :param cpu_count: The number of CPU cores to allocate to the vOneFS node
    :type cpu_count: Integer

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_ONEFS_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        resp['content'] = vmware.create_onefs(username, machine_name, image,
                                              front_end, back_end, ram,
                                              cpu_count, logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    logger.info('Task complete')
    return resp
Esempio n. 20
0
def images(self, verbose, txn_id):
    """Obtain a list of available deployments that can be created/deployed.

    :Returns: Dictionary

    :param verbose: Include extra details about available images/deployment templates.
    :type verbose: Boolean

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    resp['content'] = {'image': vmware.list_images(verbose=verbose)}
    logger.info('Task complete')
    return resp
Esempio n. 21
0
def create(self, username, txn_id):
    """Make a folder for tacking a user's VM inventory

    :Returns: Dictionary

    :param username: The name of the user to create a folder for
    :type username: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_INVENTORY_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task Starting')
    vmware.create_inventory(username)
    logger.info('Task Complete')
    return resp
Esempio n. 22
0
def show_template(self, username, txn_id):
    """Obtain a list of all the templates a user owns.

    :Returns: Dictionary

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        resp['content'] = templates.show(username, logger)
    except ValueError as doh:
        logger.error("Task failed")
        resp['error'] = '{}'.format(doh)
    else:
        logger.info("Task complete")
    return resp
Esempio n. 23
0
def delete(self, username, txn_id):
    """Destroy a user's inventory

    :Returns: Dictionary

    :param username: The owner of the inventory to delete
    :type username: String

    :param everything: Optionally destroy all the VMs associated with the user
    :type everything: Boolean

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_INVENTORY_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task Starting')
    resp['error'] = vmware.delete_inventory(username, logger)
    logger.info('Task Complete')
    return resp
Esempio n. 24
0
def list(self, username, txn_id):
    """List all vLANs owned by the user

    :Returns: Dictionary

    :param username: The name of the user who wants a list of their vLANs.
    :type username: String

    :param txn_id: A client-supplied transaction id - makes debugging easier
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id, task_id=self.request.id, loglevel=const.VLAB_VLAN_LOG_LEVEL.upper())
    resp = {'content' : {}, 'error' : None, 'params' : {}}
    logger.info('Task Starting')
    USER_TAG = '{}_'.format(username)
    vlans = database.get_vlan(username)
    answer = {}
    for name, tag in vlans.items():
        answer[name.replace(USER_TAG, '')] = tag
    resp['content'] = answer
    logger.info('Task Completed')
    return resp
Esempio n. 25
0
def create_template(self, username, template, machines, portmaps, summary,
                    txn_id):
    """Make a new deployment template.

    :Returns: Dictionary

    :param username: The name of the account creating a deployment template.
    :type username: String

    :param template: What to name the new deployment template.
    :type template: String

    :param machines: The machines to include in the deployment template.
    :type machines: List

    :param portmaps: A mapping of machine IP to TCP port.
    :type portmaps: Dictionary

    :param summary:
    :type summary: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        templates.create(username, template, machines, portmaps, summary,
                         logger)
    except ValueError as doh:
        logger.error("Task failed")
        resp['error'] = '{}'.format(doh)
    else:
        logger.info("Task complete")
    return resp
Esempio n. 26
0
def delete(self, username, user_token, template, client_ip, txn_id):
    """Destroy a deployment.

    :Returns: Dictionary

    :param username: The name of the user who wants to delete an instance of Deployment
    :type username: String

    :param user_token: The JWT of a user destorying a deployment.
    :type user_token: String

    :param template: The name of the deployment.
    :type template: String

    :param client_ip: The IP address that sent the request.
    :type client_ip: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        vmware.delete_deployment(username, template, logger)
        delete_port_maps(username, template, user_token, client_ip, logger)
    except ValueError as doh:
        logger.error('Task failed: {}'.format(doh))
        resp['error'] = '{}'.format(doh)
    except RuntimeError as doh:
        logger.error("Not all portmap rules deleted. Error: %s", doh)
        resp['error'] = 'Not all portmap rules deleted. Error: {}'.format(doh)
    else:
        logger.info('Task complete')
    return resp
Esempio n. 27
0
def modify(self, username, power_state, machine, txn_id):
    """Celery task for changing the power state of Virtual Machine(s)

    :Returns: Dictionary

    :param username: The name of the user who owns the supplied VM(s)
    :type username: String

    :param power_state: The desired power state for the supplied VM(s)
    :type power_state: String

    :param machine: The name of the VM(s) to power on/off/restart
    :type machine: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_POWER_LOG_LEVEL.upper())
    resp = {
        'content': {},
        'error': None,
        'params': {
            'power': power_state,
            'machine': machine
        }
    }
    logger.info('Task Starting')
    try:
        modify_power(username, power_state, machine, logger)
    except ValueError as doh:
        err = '{}'.format(doh)
        logger.info('Task Failure: {}'.format(err))
        resp['error'] = '{}'.format(err)
    logger.info('Task Completed')
    return resp
Esempio n. 28
0
def create(self, username, vlan_name, switch_name, txn_id):
    """Create a vLAN for the user.

    :Returns: Dictionary

    :param username: The name of the user who wants to create a vLAN
    :type username: String

    :param vlan_name: The kind of vLAN to make, like FrontEnd or BackEnd
    :type vlan_name: String
    """
    logger = get_task_logger(txn_id=txn_id, task_id=self.request.id, loglevel=const.VLAB_VLAN_LOG_LEVEL.upper())
    resp = {'error' : None, 'content': {},
            'params': {'vlan_name': vlan_name, 'switch_name': switch_name}}
    logger.info('Task Starting')
    try:
        vlan_tag_id = database.register_vlan(username=username, vlan_name=vlan_name, logger=logger)
    except ValueError as doh:
        resp['error'] = '{}'.format(doh)
        return resp

    try:
        error = create_network(vlan_name, vlan_tag_id, switch_name)
    except Exception as doh:
        resp['error'] = '{}'.format(doh)
    else:
        resp['error'] = error
    if resp['error']:
        try:
            # Delete the record in the DB to keep VMware & the DB records in sync
            # otherwise, we'll leak vLAN tag ids
            database.delete_vlan(username=username, vlan_name=vlan_name)
        except Exception as doh:
            logger.traceback(doh)
    logger.info('Task Completed')
    return resp
Esempio n. 29
0
def config(self, cluster_name, name, username, version, int_netmask,
           int_ip_low, int_ip_high, ext_netmask, ext_ip_low, ext_ip_high,
           gateway, dns_servers, encoding, sc_zonename, smartconnect_ip,
           join_cluster, compliance, txn_id):
    """Turn a blank OneFS node into a usable device

    :Returns: Dictionary

    :param cluster_name: The name of the OneFS cluster
    :type cluster_name: String

    :param name: The name of the OneFS node
    :type name: String

    :param int_netmask: The subnet mask for the internal OneFS network
    :type int_netmask: String

    :param int_ip_low: The smallest IP to assign to an internal NIC
    :type int_ip_low: String (IPv4 address)

    :param int_ip_high: The largest IP to assign to an internal NIC
    :type int_ip_high: String (IPv4 address)

    :param ext_ip_low: The smallest IP to assign to an external/public NIC
    :type ext_ip_low: String (IPv4 address)

    :param ext_ip_high: The largest IP to assign to an external/public NIC
    :type ext_ip_high: String (IPv4 address)

    :param gateway: The IP address for the default gateway
    :type gateway: String (IPv4 address)

    :param dns_servers: A common separated list of IPs of the DNS servers to use
    :type dns_servers: String

    :param encoding: The filesystem encoding to use.
    :type encoding: String

    :param sc_zonename: The SmartConnect Zone name to use. Skipped if None.
    :type sc_zonename: String

    :param smartconnect_ip: The IPv4 address to use as the SIP
    :type smartconnect_ip: String (IPv4 address)

    :param join_cluster: Add the node to an existing cluster
    :type join_cluster: Boolean

    :param compliance: Set to True when creating a Compliance mode cluster
    :type compliance: Boolean

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_ONEFS_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    nodes = vmware.show_onefs(username)
    node = nodes.get(name, None)
    if not node:
        error = "No node named {} found".format(name)
        resp['error'] = error
        logger.error(error)
        return resp
    elif node['meta']['configured']:
        error = "Cannot configure a node that's already configured"
        resp['error'] = error
        logger.error(error)
    else:
        # Lets set it up!
        logger.info('Found node')
        console_url = node['console']
        if join_cluster:
            logger.info('Joining node to cluster {}'.format(cluster_name))
            setup_onefs.join_existing_cluster(console_url, cluster_name,
                                              compliance, logger)
        else:
            logger.info('Setting up new cluster named {}'.format(cluster_name))
            setup_onefs.configure_new_cluster(version=version,
                                              console_url=console_url,
                                              cluster_name=cluster_name,
                                              int_netmask=int_netmask,
                                              int_ip_low=int_ip_low,
                                              int_ip_high=int_ip_high,
                                              ext_netmask=ext_netmask,
                                              ext_ip_low=ext_ip_low,
                                              ext_ip_high=ext_ip_high,
                                              gateway=gateway,
                                              dns_servers=dns_servers,
                                              encoding=encoding,
                                              sc_zonename=sc_zonename,
                                              smartconnect_ip=smartconnect_ip,
                                              compliance=compliance,
                                              logger=logger)
    node['meta']['configured'] = True
    vmware.update_meta(username, name, node['meta'])
    logger.info('Task complete')
    return resp
Esempio n. 30
0
 def test_get_task_logger(self):
     """``get_task_logger`` returns an instance of logging.LoggerAdapter"""
     log = get_task_logger(txn_id='myId', task_id='aabbcc')
     self.assertTrue(isinstance(log, logging.LoggerAdapter))