Back to

Package util

Latest Go to latest

The highest tagged major version is .

Published: Sep 19, 2020 | License: BSD-3-Clause | Module:



const (
	ColonSeparator string = ":"
	Lab            string = "lab"
	ATL            string = "atl"
	ACS            string = "acs"
	Browser        string = "browser"
	CrOS           string = "cros"
	OperationPageSize int = 500

message for filtering

const (
	// MachineCollection refers to the prefix of the corresponding resource.
	MachineCollection string = "machines"
	// RackCollection refers to the prefix of the corresponding resource.
	RackCollection string = "racks"
	// VMCollection refers to the prefix of the corresponding resource.
	VMCollection string = "vms"
	// ChromePlatformCollection refers to the prefix of the corresponding resource.
	ChromePlatformCollection string = "chromeplatforms"
	// MachineLSECollection refers to the prefix of the corresponding resource.
	MachineLSECollection string = "machineLSEs"
	// HostCollection refers to the prefix of the corresponding resource.
	HostCollection string = "hosts"
	// RackLSECollection refers to the prefix of the corresponding resource.
	RackLSECollection string = "rackLSEs"
	// NicCollection refers to the prefix of the corresponding resource.
	NicCollection string = "nics"
	// KVMCollection refers to the prefix of the corresponding resource.
	KVMCollection string = "kvms"
	// RPMCollection refers to the prefix of the corresponding resource.
	RPMCollection string = "rpms"
	// DracCollection refers to the prefix of the corresponding resource.
	DracCollection string = "dracs"
	// SwitchCollection refers to the prefix of the corresponding resource.
	SwitchCollection string = "switches"
	// VlanCollection refers to the prefix of the corresponding resource.
	VlanCollection string = "vlans"
	// MachineLSEPrototypeCollection refers to the prefix of the corresponding resource.
	MachineLSEPrototypeCollection string = "machineLSEPrototypes"
	// RackLSEPrototypeCollection refers to the prefix of the corresponding resource.
	RackLSEPrototypeCollection string = "rackLSEPrototypes"
	// DHCPCollection refers to the prefix of the dhcp config id in change history
	DHCPCollection string = "dhcps"
	// IPCollection refers to the prefix of the ip id in change history
	IPCollection string = "ips"
	// StateCollection refers to the prefix of the states id in change history
	StateCollection string = "states"

	// DefaultImporter refers to the user of the cron job importer
	DefaultImporter string = "crimson-importer"

	// MaxPageSize maximum page size for list operations
	MaxPageSize int32 = 1000
const AcsLabAdminRealm = "chromium:ufs/acs-admin"

AcsLabAdminRealm is the admin realm for acs lab.

const AtlLabAdminRealm = "chromium:ufs/atl-admin"

AtlLabAdminRealm is the admin realm for atl lab.

const BrowserLabAdminRealm = "chromium:ufs/browser-admin"

BrowserLabAdminRealm is the admin realm for browser lab.


var (
	ZoneFilterName              string = "zone"
	RackFilterName              string = "rack"
	MachineFilterName           string = "machine"
	HostFilterName              string = "host"
	NicFilterName               string = "nic"
	DracFilterName              string = "drac"
	KVMFilterName               string = "kvm"
	MacAddressFilterName        string = "mac"
	RPMFilterName               string = "rpm"
	SwitchFilterName            string = "switch"
	SwitchPortFilterName        string = "switchport"
	ServoFilterName             string = "servo"
	TagFilterName               string = "tag"
	ChromePlatformFilterName    string = "platform"
	MachinePrototypeFilterName  string = "machineprototype"
	RackPrototypeFilterName     string = "rackprototype"
	VlanFilterName              string = "vlan"
	StateFilterName             string = "state"
	IPV4FilterName              string = "ipv4"
	IPV4StringFilterName        string = "ipv4str"
	OccupiedFilterName          string = "occupied"
	ManufacturerFilterName      string = "man"
	FreeVMFilterName            string = "free"
	ResourceTypeFilterName      string = "resourcetype"
	OSVersionFilterName         string = "osversion"
	OSFilterName                string = "os"
	VirtualDatacenterFilterName string = "vdc"

Filter names for indexed properties in datastore for different entities

var StateToDescription = map[string]string{
	"registered":           "Needs deploy",
	"deployed_pre_serving": "Deployed but not placed in prod",
	"deployed_testing":     "Deployed to the prod, but for testing",
	"serving":              "Deployed to the prod, serving",
	"needs_reset":          "Deployed to the prod, but required cleanup and verify",
	"needs_repair":         "Deployed to the prod, needs repair",
	"repair_failed":        "Deployed to the prod, failed to be repaired in previous step and requires new repair attempt",
	"disabled":             "Deployed to the prod, but disabled",
	"reserved":             "Deployed to the prod, but reserved (e.g. locked)",
	"decommissioned":       "Decommissioned from the prod, but still lives in UFS record",
	"deploying":            "Deploying the resource with required configs just before it is READY",
	"ready":                "Resource is ready for use or free to use",

StateToDescription refers a map between a State to its description.

var StrToUFSState = map[string]string{
	"registered":           "STATE_REGISTERED",
	"deployed_pre_serving": "STATE_DEPLOYED_PRE_SERVING",
	"deployed_testing":     "STATE_DEPLOYED_TESTING",
	"serving":              "STATE_SERVING",
	"needs_reset":          "STATE_NEEDS_RESET",
	"needs_repair":         "STATE_NEEDS_REPAIR",
	"repair_failed":        "STATE_REPAIR_FAILED",
	"disabled":             "STATE_DISABLED",
	"reserved":             "STATE_RESERVED",
	"decommissioned":       "STATE_DECOMMISSIONED",
	"deploying":            "STATE_DEPLOYING",
	"ready":                "STATE_READY",

StrToUFSState refers a map between a string to a UFS defined state map.

var StrToUFSZone = map[string]string{
	"atlanta":           "ZONE_ATLANTA",
	"chromeos1":         "ZONE_CHROMEOS1",
	"chromeos4":         "ZONE_CHROMEOS4",
	"chromeos6":         "ZONE_CHROMEOS6",
	"chromeos2":         "ZONE_CHROMEOS2",
	"chromeos3":         "ZONE_CHROMEOS3",
	"chromeos5":         "ZONE_CHROMEOS5",
	"chromeos7":         "ZONE_CHROMEOS7",
	"chromeos15":        "ZONE_CHROMEOS15",
	"atl97":             "ZONE_ATL97",
	"iad97":             "ZONE_IAD97",
	"mtv96":             "ZONE_MTV96",
	"mtv97":             "ZONE_MTV97",
	"fuchsia":           "ZONE_FUCHSIA",
	"unspecified":       "ZONE_UNSPECIFIED",
	"cros_googler_desk": "ZONE_CROS_GOOGLER_DESK",

StrToUFSZone refers a map between a string to a UFS defined map.

func AddPrefix

func AddPrefix(collection, entity string) string

AddPrefix adds the prefix for a given resource name

func CurrentUser

func CurrentUser(ctx context.Context) string

CurrentUser returns the current user


func DUTToLSE(dut *lab.DeviceUnderTest, deviceID string, updatedTime *timestamp.Timestamp) *ufspb.MachineLSE

DUTToLSE converts a DUT spec to a UFS machine LSE

func FormatDHCPHostname

func FormatDHCPHostname(old string) string

FormatDHCPHostname formats a name which will be a dhcp host

func FormatDHCPHostnames

func FormatDHCPHostnames(names []string) []string

FormatDHCPHostnames formats a given array of resource names which could be used as dhcp hostnames

func FormatIP

func FormatIP(vlanName, ipAddress string, occupied bool) *ufspb.IP

FormatIP initialize an IP object

func FormatInputNames

func FormatInputNames(names []string) []string

FormatInputNames formats a given array of resource names

func FormatResourceName

func FormatResourceName(old string) string

FormatResourceName formats the resource name

func GetATLLabName

func GetATLLabName(raw string) string

GetATLLabName returns a resource name with atl prefix and a given user-specified raw name.

func GetBrowserLabName

func GetBrowserLabName(raw string) string

GetBrowserLabName return a resource name with browser prefix and a given user-specified raw name.

func GetCapacity

func GetCapacity(cidr string) float64

GetCapacity returns the capacity of a vlan cidr block

func GetCrOSLabName

func GetCrOSLabName(raw string) string

GetCrOSLabName returns a resource name with ChromeOS prefix and a given user-specified raw name.

func GetIPName

func GetIPName(vlanName, ipv4Str string) string

GetIPName returns a formatted IP name

func GetNicName

func GetNicName(nicName, machineName string) string

GetNicName formats a nic name with its attached machine

func GetOSMachineLSEPrototypes

func GetOSMachineLSEPrototypes() []*ufspb.MachineLSEPrototype

GetOSMachineLSEPrototypes returns the pre-defined machine lse prototypes for ChromeOS machines.

func GetPageSize

func GetPageSize(pageSize int32) int32

GetPageSize gets the correct page size for List pagination

func GetPrefix

func GetPrefix(resourceName string) string

GetPrefix returns the prefix for a resource name

func GetRackHostname

func GetRackHostname(rackName string) string

GetRackHostname returns a rack host name.

func GetStateDescription

func GetStateDescription(state string) string

GetStateDescription returns the description for the state

func GetSuffixAfterSeparator

func GetSuffixAfterSeparator(name, seprator string) string

GetSuffixAfterSeparator extracts the string appearing after the separator

returns the suffix after the first found separator

func IPv4IntToStr

func IPv4IntToStr(ipAddress uint32) string

IPv4IntToStr returns a string ip address

func IPv4StrToInt

func IPv4StrToInt(ipAddress string) (uint32, error)

IPv4StrToInt returns an uint32 address from the given ip address string.

func Int32ToStr

func Int32ToStr(v int32) string

Int32ToStr converts the int32 to string

func Int64ToStr

func Int64ToStr(v int64) string

Int64ToStr converts the int64 to string

func IsInBrowserZone

func IsInBrowserZone(name string) bool

IsInBrowserZone check if a given name(resource or zone name) indicates it's in browser zone.

func IsInternalError

func IsInternalError(err error) bool

IsInternalError checks if an error has code INTERNAL

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error has code NOT_FOUND

func IsUFSState

func IsUFSState(state string) bool

IsUFSState checks if a string refers to a valid UFS state.

func IsUFSZone

func IsUFSZone(zone string) bool

IsUFSZone checks if a string refers to a valid UFS zone.

func LabstationToLSE

func LabstationToLSE(l *lab.Labstation, deviceID string, updatedTime *timestamp.Timestamp) *ufspb.MachineLSE

LabstationToLSE converts a DUT spec to a UFS machine LSE

func Min

func Min(a, b int) int

Min returns the smaller integer of the two inputs.

func ParseATLTopology

func ParseATLTopology(data *sheets.Spreadsheet) (map[string]*ufspb.Vlan, []*ufspb.Vlan)

ParseATLTopology parse the topology of ATL lab based on a Google sheet

func ParseMac

func ParseMac(userMac string) (string, error)

ParseMac returns a valid mac address after parsing user input.

func ParseVlan

func ParseVlan(vlanName, cidr string) ([]*ufspb.IP, int, error)

ParseVlan parses vlan to a list of IPs

vlanName here is a full vlan name, e.g. browser:123 The first 10 and last 1 ip of this cidr block will be reserved and not returned to users for further operations

func ProcessDatacenters

func ProcessDatacenters(dc *crimsonconfig.Datacenter) ([]*ufspb.Rack, []*ufspb.KVM, []*ufspb.Switch, []*ufspb.DHCPConfig)

ProcessDatacenters converts datacenters to several UFS objects

func ProcessNetworkInterfaces

func ProcessNetworkInterfaces(nics []*crimson.NIC, dracs []*crimson.DRAC, machines []*crimson.Machine) ([]*ufspb.Nic, []*ufspb.Drac, []*ufspb.DHCPConfig, map[string][]string, map[string]string)

ProcessNetworkInterfaces converts nics and dracs to several UFS formats for further importing

func RemovePrefix

func RemovePrefix(name string) string

RemovePrefix extracts string appearing after a "/"

func RemoveStatePrefix

func RemoveStatePrefix(state string) string

RemoveStatePrefix removes the "state_" prefix from the string

func RemoveStringEntry

func RemoveStringEntry(slice []string, entry string) []string

RemoveStringEntry removes string entry from the string slice

func RemoveZonePrefix

func RemoveZonePrefix(zone string) string

RemoveZonePrefix removes the "zone_" prefix from the string

func ToChromeMachines

func ToChromeMachines(old []*crimson.Machine, machineToNics map[string][]string, machineToDracs map[string]string) []*ufspb.Machine

ToChromeMachines converts crimson machines to UFS format.

func ToChromePlatforms

func ToChromePlatforms(oldP *crimsonconfig.Platforms) []*ufspb.ChromePlatform

ToChromePlatforms converts platforms in static file to UFS format.

func ToLab

func ToLab(datacenter string) ufspb.Lab

ToLab converts the crimson lab string to UFS lab.

func ToMachineLSEs

func ToMachineLSEs(hosts []*crimson.PhysicalHost, vms []*crimson.VM, machines []*crimson.Machine, platforms []*crimson.Platform) ([]*ufspb.MachineLSE, []*ufspb.VM, []*ufspb.IP, []*ufspb.DHCPConfig)

ToMachineLSEs converts crimson data to UFS LSEs.

func ToOSMachineLSEs

func ToOSMachineLSEs(labConfigs []*invV2Api.ListCrosDevicesLabConfigResponse_LabConfig) []*ufspb.MachineLSE

ToOSMachineLSEs converts cros inventory data to UFS LSEs for ChromeOS machines.

func ToOses

func ToOses(old []*crimson.OS) []*ufspb.OSVersion

ToOses converts the os versions to UFS format.

func ToState

func ToState(state crimsoncommon.State) ufspb.State

ToState converts crimson state to UFS state.

func ToUFSDept

func ToUFSDept(zone string) string

ToUFSDept returns the dept name based on zone string.

func ToUFSRealm

func ToUFSRealm(zone string) string

ToUFSRealm returns the realm name based on zone string.

func ToUFSState

func ToUFSState(state string) ufspb.State

ToUFSState converts state string to a UFS state enum.

func ToUFSZone

func ToUFSZone(zone string) ufspb.Zone

ToUFSZone converts zone string to a UFS zone enum.

func ToZone

func ToZone(datacenter string) ufspb.Zone

ToZone converts the crimson lab string to UFS zone.

func ValidStateStr

func ValidStateStr() []string

ValidStateStr returns a valid str list for state strings.

func ValidZoneStr

func ValidZoneStr() []string

ValidZoneStr returns a valid str list for zone strings.

type DHCPConf

type DHCPConf struct {
	ValidVlans       []*ufspb.Vlan
	ValidIPs         []*ufspb.IP
	ValidDHCPs       []*ufspb.DHCPConfig
	DHCPsWithoutVlan []*ufspb.DHCPConfig
	MismatchedVlans  []*ufspb.Vlan
	DuplicatedVlans  []*ufspb.Vlan
	DuplicatedIPs    []*ufspb.IP

DHCPConf defines the format of response after parsing a ChromeOS dhcp conf file

func ParseOSDhcpdConf

func ParseOSDhcpdConf(conf string, topology map[string]*ufspb.Vlan) (*DHCPConf, error)

ParseOSDhcpdConf parses dhcpd.conf

type Key

type Key string

Key is a type for use in adding values to context. It is not recommended to use plain string as key.

type PSRequest

type PSRequest struct {
	Msg struct {
		Data      string `json:"data"`
		MessageID string `json:"messageId"`
	} `json:"message"`
	Sub string `json:"subscription"`

PSRequest helps to unmarshall json data sent from pubsub

The format of the data sent by PubSub is described in

func NewPSRequest

func NewPSRequest(r *http.Request) (*PSRequest, error)

NewPSRequest returns a PSRequest object constructed from http request

func (*PSRequest) DecodeMessage

func (p *PSRequest) DecodeMessage() ([]byte, error)

DecodeMessage decodes []byte pertaining to the request

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier