예제 #1
0
    def token(self):
        """
        Returns the token
        """
        if self._token is None:
            self._token = openstack.get_token(self._directory)

        elif self._token.is_expired():
            self._token = openstack.get_token(self._directory)

        return self._token
예제 #2
0
    def platform_token(self):
        """
        Returns the platform token
        """
        if self._platform_token is None:
            self._platform_token = openstack.get_token(self._platform_directory)

        elif self._platform_token.is_expired():
            self._platform_token = openstack.get_token(self._platform_directory)

        return self._platform_token
예제 #3
0
def _get_token():
    """
    Returns a valid token
    """
    global _directory, _token

    if _directory is None:
        _directory = openstack.get_directory(config)

    if _token is None:
        _token = openstack.get_token(_directory)

    elif _token.is_expired():
        _token = openstack.get_token(_directory)

    return _token
예제 #4
0
def do_unit_tests(test_set=None, rest_api_debug=False, test_config=None):
    """
    NFVI Plugins Unit Tests
    """
    if rest_api_debug:
        # Enable debugging of request and response headers for rest-api calls
        import urllib2
        handler = urllib2.HTTPHandler(debuglevel=1)
        opener = urllib2.build_opener(handler)
        urllib2.install_opener(opener)

    directory = openstack.get_directory(config)
    token = openstack.get_token(directory)

    if test_set is None:
        test_set = [
            'keystone', 'ceilometer', 'sysinv', 'glance', 'cinder', 'neutron',
            'nova', 'heat', 'guest'
        ]

    print("-" * 80)
    if 'keystone' in test_set:
        keystone_unit_tests(token, test_config)
        print("-" * 80)

    if 'ceilometer' in test_set:
        ceilometer_unit_tests(token, test_config)
        print("-" * 80)

    if 'sysinv' in test_set:
        sysinv_unit_tests(token, test_config)
        print("-" * 80)

    if 'glance' in test_set:
        glance_unit_tests(token, test_config)
        print("-" * 80)

    if 'cinder' in test_set:
        cinder_unit_tests(token, test_config)
        print("-" * 80)

    if 'neutron' in test_set:
        neutron_unit_tests(token, test_config)
        print("-" * 80)

    if 'nova' in test_set:
        nova_unit_tests(token, test_config)
        print("-" * 80)

    if 'heat' in test_set:
        heat_unit_tests(token, test_config)
        print("-" * 80)

    if 'guest' in test_set:
        guest_unit_tests(token, test_config)
        print("-" * 80)

    if 'rest-api' in test_set:
        rest_api_unit_tests(token, test_config)
        print("-" * 80)
예제 #5
0
def _get_token():
    """
    Returns a valid token
    """
    global _directory, _token

    if _directory is None:
        _directory = openstack.get_directory(
            config, openstack.SERVICE_CATEGORY.PLATFORM)

    if _token is None:
        _token = openstack.get_token(_directory)

    elif _token.is_expired():
        _token = openstack.get_token(_directory)

    return _token
예제 #6
0
def process_do_setup(loads_dir, setup_data):
    """
    Test - Process Do Setup
    """
    from nfv_plugins.nfvi_plugins.openstack import cinder
    from nfv_plugins.nfvi_plugins.openstack import glance
    from nfv_plugins.nfvi_plugins.openstack import neutron
    from nfv_plugins.nfvi_plugins.openstack import nova
    from nfv_plugins.nfvi_plugins.openstack import openstack

    directory = openstack.get_directory(config,
                                        openstack.SERVICE_CATEGORY.OPENSTACK)
    token = openstack.get_token(directory)

    result = nova.get_flavors(token)
    flavors = result.result_data.get('flavors', list())

    result = glance.get_images(token)
    images = result.result_data.get('images', list())

    result = cinder.get_volumes(token)
    volumes = result.result_data.get('volumes', list())

    result = neutron.get_networks(token)
    networks = result.result_data.get('networks', list())

    result = neutron.get_subnets(token)
    subnets = result.result_data.get('subnets', list())

    result = nova.get_servers(token)
    servers = result.result_data.get('servers', list())

    for resource in setup_data['resources']:
        if 'flavor' == resource['type']:
            process_progress_marker_start("Create flavor %s " %
                                          resource['name'])
            flavor = next(
                (x for x in flavors if x['name'] == resource['name']), None)
            if flavor is None:
                nova.create_flavor(token,
                                   resource['id'],
                                   resource['name'],
                                   resource['vcpus'],
                                   resource['ram_mb'],
                                   resource['disk_gb'],
                                   ephemeral_gb=resource['ephemeral_gb'],
                                   swap_mb=resource['swap_mb'])

                if 'extra_specs' in resource:
                    for extra_spec in resource['extra_specs']:
                        nova.set_flavor_extra_specs(
                            token, resource['id'],
                            {extra_spec['key']: str(extra_spec['value'])})

            process_progress_marker_end("[OKAY]")

    result = nova.get_flavors(token)
    flavors = result.result_data.get('flavors', list())

    for resource in setup_data['resources']:
        if 'image' == resource['type']:
            process_progress_marker_start("Create image %s " %
                                          resource['name'])
            image = next((x for x in images if x['name'] == resource['name']),
                         None)
            if image is None:
                image_file = resource['file']
                if not os.path.isfile(image_file):
                    image_file = loads_dir + '/' + resource['file']
                    if not os.path.isfile(image_file):
                        process_progress_marker_end("[FAILED]")
                        print("Image file %s does not exist." %
                              resource['file'])
                        return False

                image_data = glance.create_image(
                    token, resource['name'], resource['description'],
                    resource['container_format'], resource['disk_format'],
                    resource['min_disk_size_gb'],
                    resource['min_memory_size_mb'], resource['visibility'],
                    resource['protected'], resource['properties']).result_data

                glance.upload_image_data_by_file(token, image_data['id'],
                                                 image_file)
            process_progress_marker_end("[OKAY]")

    result = glance.get_images(token)
    images = result.result_data.get('images', list())

    for resource in setup_data['resources']:
        if 'volume' == resource['type']:
            process_progress_marker_start("Create volume %s " %
                                          resource['name'])
            volume = next(
                (x for x in volumes if x['name'] == resource['name']), None)
            if volume is None:
                if resource['image_name'] is not None:
                    image = next((x for x in images
                                  if x['name'] == resource['image_name']),
                                 None)
                    if image is None:
                        process_progress_marker_end("[FAILED]")
                        print("Image %s for volume %s does not exist." %
                              (resource['image_name'], resource['name']))
                        return False

                    image_id = image['id']
                else:
                    image_id = None

                bootable = None
                if resource['bootable'] in ['YES', 'Yes', 'yes']:
                    bootable = True

                cinder.create_volume(token,
                                     resource['name'],
                                     resource['description'],
                                     resource['size_gb'],
                                     image_id,
                                     bootable=bootable)

                for _ in range(10):
                    time.sleep(5)
                    volumes = cinder.get_volumes(token).result_data
                    if volumes is not None:
                        volumes = volumes.get('volumes', list())
                        volume = next((x for x in volumes
                                       if x['name'] == resource['name']), None)
                        volume = cinder.get_volume(token,
                                                   volume['id']).result_data
                        if 'available' == volume['volume']['status']:
                            break
                else:
                    process_progress_marker_end("[FAILED]")
                    print("Volume %s not create properly." % resource['name'])
                    return False
            process_progress_marker_end("[OKAY]")

    result = cinder.get_volumes(token)
    volumes = result.result_data.get('volumes', list())

    for resource in setup_data['resources']:
        if 'network' == resource['type']:
            process_progress_marker_start("Create network %s " %
                                          resource['name'])
            network = next(
                (x for x in networks if x['name'] == resource['name']), None)
            if network is None:
                neutron.create_network(token, resource['name'],
                                       resource['network_type'],
                                       resource['segmentation_id'],
                                       resource['physical_network'],
                                       resource['shared'])
            process_progress_marker_end("[OKAY]")

    result = neutron.get_networks(token)
    networks = result.result_data.get('networks', list())

    for resource in setup_data['resources']:
        if 'subnet' == resource['type']:
            process_progress_marker_start("Create subnet %s " %
                                          resource['name'])
            subnet = next(
                (x for x in subnets if x['name'] == resource['name']), None)
            if subnet is None:
                network = next((x for x in networks
                                if x['name'] == resource['network_name']),
                               None)
                if network is None:
                    process_progress_marker_end("[FAILED]")
                    print("Network %s for subnet %s does not exist." %
                          (resource['network_name'], resource['name']))
                    return False

                neutron.create_subnet(token, network['id'], resource['name'],
                                      resource['ip_version'], resource['cidr'],
                                      resource['gateway_ip'],
                                      resource['dhcp_enabled'])
            process_progress_marker_end("[OKAY]")

    result = neutron.get_subnets(token)
    subnets = result.result_data.get('subnets', list())

    instance_created = False
    for resource in setup_data['resources']:
        if 'instance' == resource['type']:
            process_progress_marker_start("Create instance %s " %
                                          resource['name'])
            server = next(
                (x for x in servers if x['name'] == resource['name']), None)
            if server is None:
                flavor = next(
                    (x for x in flavors if x['name'] == resource['flavor']),
                    None)
                if flavor is None:
                    process_progress_marker_end("[FAILED]")
                    print("Can't find flavor %s for instance %s" %
                          (resource['flavor'], resource['name']))
                    return False

                if resource['image'] is not None:
                    image = next(
                        (x for x in images if x['name'] == resource['image']),
                        None)
                    if image is None:
                        process_progress_marker_end("[FAILED]")
                        print("Can't find image %s for instance %s" %
                              (resource['image'], resource['name']))
                        return False

                    image_id = image['id']
                else:
                    image_id = None

                block_devices = list()
                for block_device in resource['block_devices']:
                    if 'volume' == block_device['type']:
                        volume = next(
                            (x for x in volumes
                             if x['name'] == block_device['volume_name']),
                            None)
                        if volume is None:
                            process_progress_marker_end("[FAILED]")
                            print("Can't find volume %s for instance %s" %
                                  (block_device['volume_name'],
                                   resource['name']))
                            return False

                        block_devices.append({
                            'uuid':
                            volume['id'],
                            'device_name':
                            block_device['device_name'],
                            'source_type':
                            block_device['source_type'],
                            'destination_type':
                            block_device['destination_type'],
                            'boot_index':
                            block_device['boot_index']
                        })

                if 0 == len(block_devices):
                    block_devices = None

                network_ids = list()
                for network_name in resource['networks']:
                    network = next(
                        (x for x in networks if x['name'] == network_name),
                        None)
                    if network is None:
                        process_progress_marker_end("[FAILED]")
                        print("Can't find network %s for instance %s" %
                              (network_name, resource['name']))
                        return False

                    network_ids.append({'uuid': network['id']})

                if 0 == len(network_ids):
                    network_ids = None

                nova.create_server(token, resource['name'], flavor['id'],
                                   image_id, block_devices, network_ids)

                for _ in range(10):
                    time.sleep(5)
                    result = nova.get_servers(token)
                    servers = result.result_data.get('servers', list())
                    if servers:
                        server = next((x for x in servers
                                       if x['name'] == resource['name']), None)
                        server = nova.get_server(token,
                                                 server['id']).result_data
                        if 'ACTIVE' == server['server']['status']:
                            server_id = server['server']['id']
                            break
                else:
                    process_progress_marker_end("[FAILED]")
                    print("Server %s not created properly." % resource['name'])
                    return False

                for attached_volume in resource['attached_volumes']:
                    volume = next(
                        (x for x in volumes
                         if x['name'] == attached_volume['volume_name']), None)
                    if volume is None:
                        process_progress_marker_end("[FAILED]")
                        print(
                            "Can't find volume %s for instance %s" %
                            (attached_volume['volume_name'], resource['name']))
                        return False

                    nova.attach_volume(token, server_id, volume['id'],
                                       attached_volume['device_name'])

                instance_created = True

            process_progress_marker_end("[OKAY]")

    if instance_created:
        # Allow time for instances to boot and guest client to start up
        # inside the each instance (in case it is being used). Timeout is long
        # because we are usually testing in Virtual Box.
        time.sleep(90)

    return True
예제 #7
0
def process_do_teardown(setup_data):
    """
    Test - Process Do Teardown
    """
    from nfv_plugins.nfvi_plugins.openstack import cinder
    from nfv_plugins.nfvi_plugins.openstack import glance
    from nfv_plugins.nfvi_plugins.openstack import neutron
    from nfv_plugins.nfvi_plugins.openstack import nova
    from nfv_plugins.nfvi_plugins.openstack import openstack

    directory = openstack.get_directory(config,
                                        openstack.SERVICE_CATEGORY.OPENSTACK)
    token = openstack.get_token(directory)

    result = nova.get_flavors(token)
    flavors = result.result_data.get('flavors', list())

    result = glance.get_images(token)
    images = result.result_data.get('images', list())

    result = cinder.get_volumes(token)
    volumes = result.result_data.get('volumes', list())

    result = neutron.get_networks(token)
    networks = result.result_data.get('networks', list())

    result = neutron.get_subnets(token)
    subnets = result.result_data.get('subnets', list())

    result = nova.get_servers(token)
    servers = result.result_data.get('servers', list())

    for resource in setup_data['resources']:
        if 'instance' == resource['type']:
            process_progress_marker_start("Delete instance %s " %
                                          resource['name'])
            server = next(
                (x for x in servers if x['name'] == resource['name']), None)
            if server is not None:
                nova.delete_server(token, server['id'])

                for _ in range(10):
                    time.sleep(5)
                    servers = nova.get_servers(token).result_data
                    if servers is not None:
                        servers = servers.get('servers', list())
                        server = next((x for x in servers
                                       if x['name'] == resource['name']), None)
                        if server is None:
                            break
                else:
                    process_progress_marker_end("[FAILED]")
                    print("Server %s not deleted." % resource['name'])
                    return False
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'subnet' == resource['type']:
            process_progress_marker_start("Delete subnet %s " %
                                          resource['name'])
            subnet = next(
                (x for x in subnets if x['name'] == resource['name']), None)
            if subnet is not None:
                neutron.delete_subnet(token, subnet['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'network' == resource['type']:
            process_progress_marker_start("Delete network %s " %
                                          resource['name'])
            network = next(
                (x for x in networks if x['name'] == resource['name']), None)
            if network is not None:
                neutron.delete_network(token, network['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'volume' == resource['type']:
            process_progress_marker_start("Delete volume %s " %
                                          resource['name'])
            volume = next(
                (x for x in volumes if x['name'] == resource['name']), None)
            if volume is not None:
                cinder.delete_volume(token, volume['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'image' == resource['type']:
            process_progress_marker_start("Delete image %s " %
                                          resource['name'])
            image = next((x for x in images if x['name'] == resource['name']),
                         None)
            if image is not None:
                glance.delete_image(token, image['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'flavor' == resource['type']:
            process_progress_marker_start("Delete flavor %s " %
                                          resource['name'])
            flavor = next(
                (x for x in flavors if x['name'] == resource['name']), None)
            if flavor is not None:
                nova.delete_flavor(token, flavor['id'])
            process_progress_marker_end("[OKAY]")

    return True
예제 #8
0
def do_unit_tests(test_set=None, rest_api_debug=False, test_config=None):
    """
    NFVI Plugins Unit Tests
    """
    if rest_api_debug:
        # Enable debugging of request and response headers for rest-api calls
        from six.moves import urllib
        handler = urllib.request.HTTPHandler(debuglevel=1)
        opener = urllib.request.build_opener(handler)
        urllib.request.install_opener(opener)

    platform_directory = openstack.get_directory(
        config, openstack.SERVICE_CATEGORY.PLATFORM)
    openstack_directory = openstack.get_directory(
        config, openstack.SERVICE_CATEGORY.OPENSTACK)
    platform_token = openstack.get_token(platform_directory)
    openstack_token = openstack.get_token(openstack_directory)

    if test_set is None:
        test_set = ['keystone', 'ceilometer', 'sysinv', 'glance', 'cinder',
                    'neutron', 'nova', 'heat', 'guest']

    print("-" * 80)
    if 'keystone' in test_set:
        keystone_unit_tests(openstack_token, test_config)
        print("-" * 80)

    if 'ceilometer' in test_set:
        ceilometer_unit_tests(openstack_token, test_config)
        print("-" * 80)

    if 'sysinv' in test_set:
        sysinv_unit_tests(platform_token, test_config)
        print("-" * 80)

    if 'glance' in test_set:
        glance_unit_tests(openstack_token, test_config)
        print("-" * 80)

    if 'cinder' in test_set:
        cinder_unit_tests(openstack_token, test_config)
        print("-" * 80)

    if 'neutron' in test_set:
        neutron_unit_tests(openstack_token, test_config)
        print("-" * 80)

    if 'nova' in test_set:
        nova_unit_tests(openstack_token, test_config)
        print("-" * 80)

    if 'heat' in test_set:
        heat_unit_tests(openstack_token, test_config)
        print("-" * 80)

    if 'guest' in test_set:
        guest_unit_tests(platform_token, test_config)
        print("-" * 80)

    if 'rest-api' in test_set:
        rest_api_unit_tests(platform_token, test_config)
        print("-" * 80)
예제 #9
0
    def do_GET(self):
        global _lock, _token

        if self.path == '/':
            with open(_webserver_src_dir + '/html/index.html', 'r') as f:
                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'text/html')
                self.end_headers()
                self.wfile.write(f.read())

        elif self.path == '/windriver-favicon.ico':
            with open(_webserver_src_dir + '/images' + self.path, 'r') as f:
                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'image/x-icon')
                self.end_headers()
                self.wfile.write(f.read())

        elif re.search('/vim/overview', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                locked_hosts = 0
                unlocked_hosts = 0
                locking_hosts = 0
                unlocking_hosts = 0
                enabled_hosts = 0
                disabled_hosts = 0
                offline_hosts = 0
                failed_hosts = 0
                nfvi_enabled_hosts = 0

                hosts = database.database_host_get_list()
                for host in hosts:
                    if host.is_enabled():
                        enabled_hosts += 1

                    elif host.is_disabled():
                        disabled_hosts += 1

                    if host.nfvi_host_is_enabled():
                        nfvi_enabled_hosts += 1

                    if host.is_locked():
                        locked_hosts += 1
                    else:
                        unlocked_hosts += 1

                    if host.is_locking():
                        locking_hosts += 1

                    elif host.is_unlocking():
                        unlocking_hosts += 1

                    if host.is_offline():
                        offline_hosts += 1

                    if host.is_failed():
                        failed_hosts += 1

                total_hosts = len(hosts)

                locked_instances = 0
                unlocked_instances = 0
                enabled_instances = 0
                disabled_instances = 0
                failed_instances = 0
                powering_off_instances = 0
                pausing_instances = 0
                paused_instances = 0
                suspended_instances = 0
                suspending_instances = 0
                resizing_instances = 0
                rebooting_instances = 0
                rebuilding_instances = 0
                migrating_instances = 0
                deleting_instances = 0
                deleted_instances = 0

                instances = database.database_instance_get_list()
                for instance in instances:
                    if instance.is_locked():
                        locked_instances += 1
                    else:
                        unlocked_instances += 1

                    if instance.is_enabled():
                        enabled_instances += 1

                    if instance.is_disabled():
                        disabled_instances += 1

                    if instance.is_failed():
                        failed_instances += 1

                    if instance.is_powering_off():
                        powering_off_instances += 1

                    if instance.is_pausing():
                        pausing_instances += 1

                    if instance.is_paused():
                        paused_instances += 1

                    if instance.is_suspending():
                        suspending_instances += 1

                    if instance.is_suspended():
                        suspended_instances += 1

                    if instance.is_resizing():
                        resizing_instances += 1

                    if instance.is_rebooting():
                        rebooting_instances += 1

                    if instance.is_rebuilding():
                        rebuilding_instances += 1

                    if instance.is_migrating():
                        migrating_instances += 1

                    if instance.is_deleting():
                        deleting_instances += 1

                    if instance.is_deleted():
                        deleted_instances += 1

                total_instances = len(instances)

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({
                        'locked_hosts': locked_hosts,
                        'unlocked_hosts': unlocked_hosts,
                        'locking_hosts': locking_hosts,
                        'unlocking_hosts': unlocking_hosts,
                        'enabled_hosts': enabled_hosts,
                        'disabled_hosts': disabled_hosts,
                        'offline_hosts': offline_hosts,
                        'failed_hosts': failed_hosts,
                        'nfvi_enabled_hosts': nfvi_enabled_hosts,
                        'total_hosts': total_hosts,
                        'locked_instances': locked_instances,
                        'unlocked_instances': unlocked_instances,
                        'enabled_instances': enabled_instances,
                        'disabled_instances': disabled_instances,
                        'failed_instances': failed_instances,
                        'powering_off_instances': powering_off_instances,
                        'pausing_instances': pausing_instances,
                        'paused_instances': paused_instances,
                        'suspended_instances': suspended_instances,
                        'suspending_instances': suspending_instances,
                        'resizing_instances': resizing_instances,
                        'rebooting_instances': rebooting_instances,
                        'rebuilding_instances': rebuilding_instances,
                        'migrating_instances': migrating_instances,
                        'deleting_instances': deleting_instances,
                        'deleted_instances': deleted_instances,
                        'total_instances': total_instances,
                        'datetime': str(datetime.datetime.now())[:-3]
                    }) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/alarms', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                critical_alarms = 0
                major_alarms = 0
                minor_alarms = 0
                warning_alarms = 0
                indeterminate_alarms = 0

                _lock.acquire()
                if _token is None or _token.is_expired():
                    _token = openstack.get_token(_directory)
                _lock.release()

                result = fm.get_alarms(_token)
                if result.result_data:
                    for alarm in result.result_data['alarms']:
                        if 'critical' == alarm['severity']:
                            critical_alarms += 1
                        elif 'major' == alarm['severity']:
                            major_alarms += 1
                        elif 'minor' == alarm['severity']:
                            minor_alarms += 1
                        elif 'warning' == alarm['severity']:
                            warning_alarms += 1
                        else:
                            indeterminate_alarms += 1

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({
                        'critical_alarms': critical_alarms,
                        'major_alarms': major_alarms,
                        'minor_alarms': minor_alarms,
                        'warning_alarms': warning_alarms,
                        'indeterminate_alarms': indeterminate_alarms,
                        'datetime': str(datetime.datetime.now())[:-3]
                    }) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/systems', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                system_list = list()
                systems = database.database_system_get_list()
                for system in systems:
                    system_list.append(system.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'systems': system_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/hosts', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                host_list = list()
                hosts = database.database_host_get_list()
                for host in hosts:
                    host_list.append(host.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'hosts': host_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/host_groups', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                host_group_list = list()
                host_groups = database.database_host_group_get_list()
                for host_group in host_groups:
                    host_group_list.append(host_group.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'host_groups': host_group_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/host_aggregates', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                host_aggregate_list = list()
                host_aggregates = database.database_host_aggregate_get_list()
                for host_aggregate in host_aggregates:
                    host_aggregate_list.append(host_aggregate.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'host_aggregates': host_aggregate_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/hypervisors', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                hypervisor_list = list()
                hypervisors = database.database_hypervisor_get_list()
                for hypervisor in hypervisors:
                    hypervisor_list.append(hypervisor.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'hypervisors': hypervisor_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/instances', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                instance_list = list()
                instances = database.database_instance_get_list()
                for instance in instances:
                    instance_list.append(instance.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'instances': instance_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/instance_types', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                instance_type_list = list()
                instance_types = database.database_instance_type_get_list()
                for instance_type in instance_types:
                    instance_type_list.append(instance_type.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'instance_types': instance_type_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/instance_groups', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                instance_group_list = list()
                instance_groups = database.database_instance_group_get_list()
                for instance_group in instance_groups:
                    instance_group_list.append(instance_group.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'instance_groups': instance_group_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/images', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                image_list = list()
                images = database.database_image_get_list()
                for image in images:
                    image_list.append(image.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'images': image_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/volumes', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                volume_list = list()
                volumes = database.database_volume_get_list()
                for volume in volumes:
                    volume_list.append(volume.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'volumes': volume_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/volume_snapshots', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                volume_snapshot_list = list()
                volume_snapshots = database.database_volume_snapshot_get_list()
                for volume_snapshot in volume_snapshots:
                    volume_snapshot_list.append(volume_snapshot.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'volume_snapshots': volume_snapshot_list}) +
                    ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/subnets', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                subnet_list = list()
                subnets = database.database_subnet_get_list()
                for subnet in subnets:
                    subnet_list.append(subnet.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'subnets': subnet_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/vim/networks', self.path) is not None:
            query_obj = re.match(".*?callback=(.*)&.*", self.path)
            if query_obj is not None:
                network_list = list()
                networks = database.database_network_get_list()
                for network in networks:
                    network_list.append(network.as_dict())

                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    query_obj.group(1) + "(" +
                    json.dumps({'networks': network_list}) + ")")
            else:
                self.send_response(httplib.BAD_REQUEST,
                                   'Bad Request: does not exist')
                self.send_header('Content-Type', 'application/json')
                self.end_headers()

        elif re.search('/fonts', self.path) is not None:
            with open(_webserver_src_dir + self.path, 'r') as f:
                self.send_response(httplib.OK)
                self.send_header('Content-Type', 'application/font-woff')
                self.end_headers()
                self.wfile.write(f.read())

        else:
            mime_type = 'unsupported'
            send_reply = False
            if self.path.endswith(".html"):
                mime_type = 'text/html'
                send_reply = True
            elif self.path.endswith(".svg"):
                mime_type = 'image/svg+xml'
                send_reply = True
            elif self.path.endswith(".jpg"):
                mime_type = 'image/jpg'
                send_reply = True
            elif self.path.endswith(".gif"):
                mime_type = 'image/gif'
                send_reply = True
            elif self.path.endswith(".png"):
                mime_type = 'image/png'
                send_reply = True
            elif self.path.endswith(".ico"):
                mime_type = 'image/x-icon'
                send_reply = True
            elif self.path.endswith(".js"):
                mime_type = 'application/javascript'
                send_reply = True
            elif self.path.endswith(".css"):
                mime_type = 'text/css'
                send_reply = True
            elif self.path.endswith(".handlebars"):
                mime_type = 'text/x-handlebars-template'
                send_reply = True

            if send_reply:
                with open(_webserver_src_dir + self.path, 'r') as f:
                    self.send_response(httplib.OK)
                    self.send_header('Content-Type', mime_type)
                    self.end_headers()
                    self.wfile.write(f.read())