usage

package
Version: v1.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2019 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package usage provides information and interaction with the SimpleTenantUsage extension for the OpenStack Compute service.

Example to Retrieve Usage for a Single Tenant:

	start := time.Date(2017, 01, 21, 10, 4, 20, 0, time.UTC)
	end := time.Date(2017, 01, 21, 10, 4, 20, 0, time.UTC)

    singleTenantOpts := usage.SingleTenantOpts{
        Start: &start,
        End: &end,
    }

    page, err := usage.SingleTenant(computeClient, tenantID, singleTenantOpts).AllPages()
    if err != nil {
        panic(err)
    }

    tenantUsage, err := usage.ExtractSingleTenant(page)
    if err != nil {
        panic(err)
    }

    fmt.Printf("%+v\n", tenantUsage)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SingleTenant

func SingleTenant(client *gophercloud.ServiceClient, tenantID string, opts SingleTenantOptsBuilder) pagination.Pager

SingleTenant returns usage data about a single tenant.

Types

type ServerUsage

type ServerUsage struct {
	// EndedAt is the date and time when the server was deleted
	EndedAt time.Time `json:"-"`

	// Flavor is the display name of a flavor
	Flavor string `json:"flavor"`

	// Hours is the duration that the server exists in hours
	Hours float64 `json:"hours"`

	// InstanceID is the UUID of the instance
	InstanceID string `json:"instance_id"`

	// LocalGB is the sum of the root disk size of the server and the ephemeral disk size of it (in GiB)
	LocalGB int `json:"local_gb"`

	// MemoryMB is the memory size of the server (in MB)
	MemoryMB int `json:"memory_mb"`

	// Name is the name assigned to the server when it was created
	Name string `json:"name"`

	// StartedAt is the date and time when the server was started
	StartedAt time.Time `json:"-"`

	// State is the VM power state
	State string `json:"state"`

	// TenantID is the UUID of the tenant in a multi-tenancy cloud
	TenantID string `json:"tenant_id"`

	// Uptime is the uptime of the server in seconds
	Uptime int `json:"uptime"`

	// VCPUs is the number of virtual CPUs that the server uses
	VCPUs int `json:"vcpus"`
}

ServerUsage is a detailed set of information about a specific instance inside a tenant

func (*ServerUsage) UnmarshalJSON

func (u *ServerUsage) UnmarshalJSON(b []byte) error

UnmarshalJSON sets *u to a copy of data.

type SingleTenantOpts

type SingleTenantOpts struct {
	// The ending time to calculate usage statistics on compute and storage resources.
	End *time.Time `q:"end"`

	// The beginning time to calculate usage statistics on compute and storage resources.
	Start *time.Time `q:"start"`
}

SingleTenantOpts are options for fetching usage of a single tenant.

func (SingleTenantOpts) ToUsageSingleTenantQuery

func (opts SingleTenantOpts) ToUsageSingleTenantQuery() (string, error)

ToUsageSingleTenantQuery formats a SingleTenantOpts into a query string.

type SingleTenantOptsBuilder

type SingleTenantOptsBuilder interface {
	ToUsageSingleTenantQuery() (string, error)
}

SingleTenantOptsBuilder allows extensions to add additional parameters to the SingleTenant request.

type SingleTenantPage

type SingleTenantPage struct {
	pagination.SinglePageBase
}

SingleTenantPage stores a single, only page of TenantUsage results from a SingleTenant call.

func (SingleTenantPage) IsEmpty

func (page SingleTenantPage) IsEmpty() (bool, error)

IsEmpty determines whether or not a SingleTenantPage is empty.

type TenantUsage

type TenantUsage struct {
	// ServerUsages is an array of ServerUsage maps
	ServerUsages []ServerUsage `json:"server_usages"`

	// Start is the beginning time to calculate usage statistics on compute and storage resources
	Start time.Time `json:"-"`

	// Stop is the ending time to calculate usage statistics on compute and storage resources
	Stop time.Time `json:"-"`

	// TenantID is the ID of the tenant whose usage is being reported on
	TenantID string `json:"tenant_id"`

	// TotalHours is the total duration that servers exist (in hours)
	TotalHours float64 `json:"total_hours"`

	// TotalLocalGBUsage multiplies the server disk size (in GiB) by hours the server exists, and then adding that all together for each server
	TotalLocalGBUsage float64 `json:"total_local_gb_usage"`

	// TotalMemoryMBUsage multiplies the server memory size (in MB) by hours the server exists, and then adding that all together for each server
	TotalMemoryMBUsage float64 `json:"total_memory_mb_usage"`

	// TotalVCPUsUsage multiplies the number of virtual CPUs of the server by hours the server exists, and then adding that all together for each server
	TotalVCPUsUsage float64 `json:"total_vcpus_usage"`
}

TenantUsage is a set of usage information about a tenant over the sampling window

func ExtractSingleTenant

func ExtractSingleTenant(page pagination.Page) (*TenantUsage, error)

ExtractSingleTenant interprets a SingleTenantPage as a TenantUsage result.

func (*TenantUsage) UnmarshalJSON

func (u *TenantUsage) UnmarshalJSON(b []byte) error

UnmarshalJSON sets *u to a copy of data.

Directories

Path Synopsis
simple tenant usage unit tests
simple tenant usage unit tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL