Beispiel #1
0
def bills(clients: Clients, facility_id: int, start: datetime, end: datetime,
          fields: List[str], sort: str) -> None:
    """Get utility bills"""
    items = clients.sis.get_statements(facility_id=facility_id,
                                       start=start,
                                       end=end)
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #2
0
def get(clients: Clients, feed_key: str, fields: List[str], sort: str) -> None:
    """Get fields"""
    feed = clients.iot.get_feed_with_key(key=feed_key)
    if not feed:
        raise click.ClickException(f"Feed with key {feed_key} does not exist.")

    items = clients.iot.get_fields_for_feed(feed.id)
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #3
0
def get(clients: Clients, id: str, fields: List[str], sort: str) -> None:
    """Get service(s)"""
    items = (
        [clients.contxt_deployments.get(f"{clients.org_id}/services/{id}")]
        if id
        else clients.contxt_deployments.get(f"{clients.org_id}/services")
    )
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #4
0
def get(clients: Clients, slug: Optional[str], fields: List[str], sort: str) -> None:
    """Get project(s)"""
    items = (
        [clients.contxt_deployments.get(f"{clients.org_id}/projects/{slug}")]
        if slug
        else clients.contxt_deployments.get(f"{clients.org_id}/projects")
    )
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #5
0
def get(clients: Clients, service_id: Optional[str], fields: List[str],
        sort: str) -> None:
    """Get service instance(s)"""
    items = (
        clients.contxt_deployments.get(
            f"{clients.org_id}/services/{service_id}/service_instances")
        if service_id else
        clients.contxt_deployments.get(f"{clients.org_id}/service_instances"))
    print_table(items, keys=fields, sort_by=sort)
Beispiel #6
0
def get(clients: Clients, fields: List[str], sort: str,
        cluster_slug: Optional[str]) -> None:
    """Get clusters"""
    (items, fields) = ((
        [clients.contxt_deployments.get_cluster(clients.org_id, cluster_slug)],
        None)  # type: ignore
                       if cluster_slug else
                       (clients.contxt_deployments.get_clusters(
                           clients.org_id), fields))
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #7
0
def unprovisioned(clients: Clients, feed_key: str,
                  output: Optional[IO[str]]) -> None:
    """Get unprovisioned fields"""
    items = clients.iot.get_unprovisioned_fields_for_feed_key(feed_key)
    if not output:
        print_table(items=items or [], keys=["field_descriptor"])
    else:
        writer = DictWriter(output, fieldnames=NEW_FIELD_ATTRS)
        writer.writeheader()
        writer.writerows([{
            "field_descriptor": f.field_descriptor
        } for f in items])
Beispiel #8
0
def get(clients: Clients, project_slug: str, fields: List[str],
        sort: str) -> None:
    """Get project environment(s)"""
    result = clients.contxt_deployments.get(
        f"{clients.org_id}/projects/{project_slug}/environments")

    if "cluster_slug" in fields:
        clusters = clients.contxt_deployments.get_clusters(clients.org_id)
        for r in result:
            r["cluster_slug"] = next(c.slug for c in clusters
                                     if c.id == r["cluster_id"])

    print_table(result, keys=fields, sort_by=sort)
Beispiel #9
0
def spend(
    clients: Clients,
    facility_id: int,
    resource_type: ResourceType,
    start: datetime,
    end: datetime,
    interval: str,
) -> None:
    """Get utility spend"""
    items = clients.ems.get_monthly_utility_spend(facility_id=facility_id,
                                                  resource_type=resource_type,
                                                  start_date=start,
                                                  end_date=end)
    print_table(items=items)
Beispiel #10
0
def usage(
    clients: Clients,
    facility_id: int,
    resource_type: ResourceType,
    start: datetime,
    end: datetime,
    interval: str,
) -> None:
    """Get utility usage"""
    usage = clients.ems.get_usage(facility_id=facility_id,
                                  resource_type=resource_type,
                                  start=start,
                                  end=end,
                                  interval=interval)
    print_table(items=usage.values)
Beispiel #11
0
def main_data(clients: Clients, facility_id: int, resource_type: ResourceType,
              start: datetime, end: datetime) -> None:
    """Get main service data"""
    data: Dict[datetime, Dict[str, Any]] = defaultdict(dict)
    services = clients.ems.get_main_services(facility_id=facility_id,
                                             resource_type=resource_type)
    with click.progressbar(
            services,
            label="Downloading main service data",
            item_show_func=lambda s: f"Service {s.name}" if s else "",
    ) as services_:
        for service in services_:
            for (t, v) in clients.iot.get_time_series_for_field(
                    field=service.usage_field,
                    start_time=start,
                    end_time=end,
                    window=Window.MINUTELY,
                    per_page=5000,
            ):
                data[t][service.usage_field.field_human_name] = v

    # Dump
    print_table(items=data)
Beispiel #12
0
def groupings_get(clients: Clients, facility_id: int, fields: List[str],
                  sort: str) -> None:
    """Get field groupings"""
    items = clients.iot.get_field_groupings_for_facility(facility_id)
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #13
0
def feeds(clients: Clients, fields: List[str], sort: str,
          facility_id: Optional[int]) -> None:
    """Get feeds"""
    items = clients.iot.get_feeds(facility_id=facility_id)
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #14
0
def mains(clients: Clients, facility_id: int, resource_type: ResourceType,
          fields: List[str], sort: str) -> None:
    """Get main services"""
    items = clients.ems.get_main_services(facility_id=facility_id,
                                          resource_type=resource_type)
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #15
0
def get(clients: Clients, org_id: str, project_id: int, fields: List[str],
        sort: str) -> None:
    """Get edge nodes for a project"""
    items = clients.contxt.get_edge_nodes(organization_id=org_id,
                                          project_id=project_id)
    print_table(items=items, keys=fields, sort_by=sort)
Beispiel #16
0
def get(clients: Clients, fields: List[str], sort: str) -> None:
    """Get organizations"""
    items = clients.contxt.get_organizations()
    print_table(items=items, keys=fields, sort_by=sort)