예제 #1
0
def get_cyclades_stats(request):
    servers, networks, ip_pools, images = True, True, True, True,
    clusters = True
    backend = None

    backend_id = request.GET.get("backend")
    if backend_id is not None:
        try:
            try:
                backend_id = int(backend_id)
                backend = Backend.objects.get(id=backend_id)
            except (ValueError, TypeError):
                backend = Backend.objects.get(clustername=backend_id)
        except Backend.DoesNotExist:
            raise faults.BadRequest("Invalid backend '%s'" % backend_id)
        # This stats have no meaning per backend
        networks, ip_pools = False, False

    _stats = stats.get_cyclades_stats(backend=backend,
                                      clusters=clusters,
                                      servers=servers,
                                      networks=networks,
                                      ip_pools=ip_pools,
                                      images=images)
    data = json.dumps(_stats)
    return http.HttpResponse(data, status=200, content_type='application/json')
예제 #2
0
    def handle(self, *args, **options):
        if options["backend"] is not None:
            backend = get_backend(options["backend"])
        else:
            backend = None

        clusters = parse_bool(options["clusters"])
        servers = parse_bool(options["servers"])
        images = parse_bool(options["images"])
        if backend is None:
            ip_pools = parse_bool(options["ip_pools"])
            networks = parse_bool(options["networks"])
        else:
            ip_pools = False
            networks = False

        if options["json_file"] is None:
            stats = statistics.get_cyclades_stats(backend, clusters, servers,
                                                  ip_pools, networks, images)
        else:
            with open(options["json_file"]) as data_file:
                stats = json.load(data_file)

        output_format = options["output_format"]
        if output_format == "json":
            self.stdout.write(json.dumps(stats, indent=4) + "\n")
        elif output_format == "pretty":
            cluster_details = parse_bool(options["cluster_details"])
            pretty_print_stats(stats, self.stdout,
                               cluster_details=cluster_details)
        else:
            raise CommandError("Output format '%s' not supported." %
                               output_format)
예제 #3
0
파일: views.py 프로젝트: apyrgio/synnefo
def get_cyclades_stats(request):
    images = True
    backend = None
    if request.body:
        req = utils.get_request_dict(request)
        req_stats = utils.get_attribute(req, "stats", required=True,
                                        attr_type=dict)
        # Check backend
        backend_id = utils.get_attribute(req_stats, "backend", required=False,
                                         attr_type=(basestring, int))
        if backend_id is not None:
            try:
                try:
                    backend_id = int(backend_id)
                    backend = Backend.objects.get(id=backend_id)
                except (ValueError, TypeError):
                    backend = Backend.objects.get(clustername=backend_id)
            except Backend.DoesNotExist:
                raise faults.BadRequest("Invalid backend '%s'" % backend_id)
        include_images = utils.get_attribute(req_stats, "images",
                                             required=False,
                                             attr_type=bool)
        if include_images is not None:
            images = include_images

    _stats = stats.get_cyclades_stats(backend=backend, clusters=True,
                                      servers=True, resources=True,
                                      networks=True, images=images)
    data = json.dumps(_stats)
    return http.HttpResponse(data, status=200, content_type='application/json')
예제 #4
0
    def handle(self, *args, **options):
        if options["backend"] is not None:
            backend = get_resource("backend", options["backend"])
        else:
            backend = None

        clusters = parse_bool(options["clusters"])
        servers = parse_bool(options["servers"])
        images = parse_bool(options["images"])
        if backend is None:
            ip_pools = parse_bool(options["ip_pools"])
            networks = parse_bool(options["networks"])
        else:
            ip_pools = False
            networks = False

        if options["json_file"] is None:
            stats = statistics.get_cyclades_stats(backend, clusters, servers,
                                                  ip_pools, networks, images)
        else:
            with open(options["json_file"]) as data_file:
                stats = json.load(data_file)

        output_format = options["output_format"]
        if output_format == "json":
            self.stdout.write(json.dumps(stats, indent=4) + "\n")
        elif output_format == "pretty":
            cluster_details = parse_bool(options["cluster_details"])
            pretty_print_stats(stats,
                               self.stdout,
                               cluster_details=cluster_details)
        else:
            raise CommandError("Output format '%s' not supported." %
                               output_format)
예제 #5
0
def stats_component_details(request, component):
    """Mirror detailed stats view for cyclades/astakos.

    This stats view will import the get_astakos/cyclades_stats function and
    return its results to the caller.
    """
    admin_log(request, component=component)
    data = {}
    status = 200
    if component == 'astakos':
        data = astakos_stats.get_astakos_stats()
    elif component == 'cyclades':
        data = cyclades_stats.get_cyclades_stats()
    else:
        status = 404
    return HttpResponse(json.dumps(data, cls=DjangoJSONEncoder),
                        mimetype=JSON_MIMETYPE, status=status)
예제 #6
0
def stats_component_details(request, component):
    """Mirror detailed stats view for cyclades/astakos.

    This stats view will import the get_astakos/cyclades_stats function and
    return its results to the caller.
    """
    admin_log(request, component=component)
    data = {}
    status = 200
    if component == 'astakos':
        data = astakos_stats.get_astakos_stats()
    elif component == 'cyclades':
        data = cyclades_stats.get_cyclades_stats()
    else:
        status = 404
    return HttpResponse(json.dumps(data, cls=DjangoJSONEncoder),
                        mimetype=JSON_MIMETYPE, status=status)
예제 #7
0
def get_cyclades_stats(request):
    images = True
    backend = None
    if request.body:
        req = utils.get_request_dict(request)
        req_stats = utils.get_attribute(req,
                                        "stats",
                                        required=True,
                                        attr_type=dict)
        # Check backend
        backend_id = utils.get_attribute(req_stats,
                                         "backend",
                                         required=False,
                                         attr_type=(basestring, int))
        if backend_id is not None:
            try:
                try:
                    backend_id = int(backend_id)
                    backend = Backend.objects.get(id=backend_id)
                except (ValueError, TypeError):
                    backend = Backend.objects.get(clustername=backend_id)
            except Backend.DoesNotExist:
                raise faults.BadRequest("Invalid backend '%s'" % backend_id)
        include_images = utils.get_attribute(req_stats,
                                             "images",
                                             required=False,
                                             attr_type=bool)
        if include_images is not None:
            images = include_images

    _stats = stats.get_cyclades_stats(backend=backend,
                                      clusters=True,
                                      servers=True,
                                      resources=True,
                                      networks=True,
                                      images=images)
    data = json.dumps(_stats)
    return http.HttpResponse(data, status=200, content_type='application/json')
예제 #8
0
def get_cyclades_stats(request):
    servers, networks, ip_pools, images = True, True, True, True,
    clusters = True
    backend = None

    backend_id = request.GET.get("backend")
    if backend_id is not None:
        try:
            try:
                backend_id = int(backend_id)
                backend = Backend.objects.get(id=backend_id)
            except (ValueError, TypeError):
                backend = Backend.objects.get(clustername=backend_id)
        except Backend.DoesNotExist:
            raise faults.BadRequest("Invalid backend '%s'" % backend_id)
        # This stats have no meaning per backend
        networks, ip_pools = False, False

    _stats = stats.get_cyclades_stats(backend=backend, clusters=clusters,
                                      servers=servers, networks=networks,
                                      ip_pools=ip_pools, images=images)
    data = json.dumps(_stats)
    return http.HttpResponse(data, status=200, content_type='application/json')
예제 #9
0
    def handle(self, *args, **options):
        if options["backend"] is not None:
            backend = get_backend(options["backend"])
        else:
            backend = None

        clusters = parse_bool(options["clusters"])
        servers = parse_bool(options["servers"])
        resources = parse_bool(options["resources"])
        networks = parse_bool(options["networks"])
        images = parse_bool(options["images"])

        stats = statistics.get_cyclades_stats(backend, clusters, servers,
                                              resources, networks, images)

        output_format = options["output_format"]
        if output_format == "json":
            self.stdout.write(json.dumps(stats, indent=4) + "\n")
        elif output_format == "pretty":
            pretty_print_stats(stats, self.stdout)
        else:
            raise CommandError("Output format '%s' not supported." %
                               output_format)
예제 #10
0
        pprint_servers(servers, stdout)
        newline()

    networks = stats.get("networks")
    if networks is not None:
        pprint_networks(networks, stdout)
        newline()

    ip_pools = stats.get("ip_pools")
    if ip_pools is not None:
        pprint_ip_pools(ip_pools, stdout)
        newline()

    images = stats.get("images")
    if images is not None:
        pprint_table(stdout, sorted(images.items()), separator=" | ",
                     title="Statistics for Images")
        newline()

    clusters = stats.get("clusters")
    if clusters is not None:
        pprint_clusters(clusters, stdout, detail=cluster_details)


if __name__ == "__main__":
    stats = statistics.get_cyclades_stats(clusters=True, servers=True,
                                          ip_pools=True, networks=True,
                                          images=True)
    pretty_print_stats(stats, sys.stdout)
    sys.exit(0)
예제 #11
0
    if networks is not None:
        pprint_networks(networks, stdout)
        newline()

    ip_pools = stats.get("ip_pools")
    if ip_pools is not None:
        pprint_ip_pools(ip_pools, stdout)
        newline()

    images = stats.get("images")
    if images is not None:
        pprint_table(stdout,
                     sorted(images.items()),
                     separator=" | ",
                     title="Statistics for Images")
        newline()

    clusters = stats.get("clusters")
    if clusters is not None:
        pprint_clusters(clusters, stdout, detail=cluster_details)


if __name__ == "__main__":
    stats = statistics.get_cyclades_stats(clusters=True,
                                          servers=True,
                                          ip_pools=True,
                                          networks=True,
                                          images=True)
    pretty_print_stats(stats, sys.stdout)
    sys.exit(0)