util

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColonSeparator string = ":"
	Lab            string = "lab"
	ATL            string = "atl"
	ACS            string = "acs"
	Browser        string = "browser"
	CrOS           string = "cros"
	// https://cloud.google.com/datastore/docs/concepts/limits
	OperationPageSize int = 500

	// Version Key format of inventory
	TimestampBasedVersionKeyFormat string = "2006-01-02 15:04:05.000 UTC"
)

message for filtering

View Source
const (
	// AssetCollection refers to the prefix of the corresponding resource.
	AssetCollection string = "assets"
	// 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"
	// MachineLSEDeploymentCollection refers to the prefix of the corresponding resource.
	MachineLSEDeploymentCollection string = "machineLSEDeployments"
	// 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"
	// CachingServiceCollection refers to the prefix of the CachingService.
	CachingServiceCollection string = "cachingservices"
	// DutStateCollection refers to the prefix of the DutStates id in change history
	DutStateCollection string = "dutstates"
	// SchedulingUnitCollection refers to the prefix of the SchedulingUnit.
	SchedulingUnitCollection string = "schedulingunits"

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

	// MaxPageSize maximum page size for list operations
	MaxPageSize int32 = 1000

	// NoHostPrefix is the prefix string for generating a fake non-existing hostname
	NoHostPrefix string = "no-host-yet-"
)
View Source
const AcsLabAdminRealm = "@internal:ufs/os-acs"

AcsLabAdminRealm is the admin realm for acs lab.

View Source
const AtlLabAdminRealm = "@internal:ufs/os-atl"

AtlLabAdminRealm is the admin realm for atl lab.

View Source
const BrowserLabAdminRealm = "@internal:ufs/browser"

BrowserLabAdminRealm is the admin realm for browser lab.

View Source
const OldBrowserLabAdminRealm = "chromium:ufs/browser-admin"

OldBrowserLabAdminRealm is the Old realm for browser lab

If a client sends this realm, replace it with BrowserLabAdminRealm

Variables

View Source
var (
	ZoneFilterName                 string = "zone"
	RackFilterName                 string = "rack"
	MachineFilterName              string = "machine"
	HostFilterName                 string = "host"
	NicFilterName                  string = "nic"
	DracFilterName                 string = "drac"
	KVMFilterName                  string = "kvm"
	KVMPortFilterName              string = "kvmport"
	MacAddressFilterName           string = "mac"
	RPMFilterName                  string = "rpm"
	RPMPortFilterName              string = "rpmport"
	SwitchFilterName               string = "switch"
	SwitchPortFilterName           string = "switchport"
	ServoFilterName                string = "servo"
	ServoTypeFilterName            string = "servotype"
	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"
	ModelFilterName                string = "model"
	BuildTargetFilterName          string = "target"
	BoardFilterName                string = "board"
	DeviceTypeFilterName           string = "devicetype"
	PhaseFilterName                string = "phase"
	AssetTypeFilterName            string = "assettype"
	SubnetsFilterName              string = "subnets"
	PoolsFilterName                string = "pools"
	DeploymentIdentifierFilterName string = "deploymentidentifier"
	DeploymentEnvFilterName        string = "deploymentenv"
	MachineLSEsFilterName          string = "duts"
	TypeFilterName                 string = "type"
	SerialNumberFilterName         string = "serialnumber"
)

Filter names for indexed properties in datastore for different entities

View Source
var (
	// OSNamespace os namespace to be set in client context metadata. OS data is stored in os namespace in the datastore.
	OSNamespace = "os"
	// BrowserNamespace browser namespace to be set in client context metadata. Browser data is stored in default namespace in the datastore.
	BrowserNamespace = "browser"
	//Namespace key in the incoming context metadata
	Namespace = "namespace"
)

Namespace namespace to be set by clients in context metadata This will be used to set the actual datastore namespace in the context

View Source
var (
	// ConfigurationsGet allows to get configuration resources.
	ConfigurationsGet = realms.RegisterPermission("ufs.configurations.get")
	// ConfigurationsList allows to list configuration resources.
	ConfigurationsList = realms.RegisterPermission("ufs.configurations.list")
	// ConfigurationsCreate allows to create configuration resources.
	ConfigurationsCreate = realms.RegisterPermission("ufs.configurations.create")
	// ConfigurationUpdate allows to update configuration resources.
	ConfigurationsUpdate = realms.RegisterPermission("ufs.configurations.update")
	// ConfigurationsDelete allows to delete configuration resources.
	ConfigurationsDelete = realms.RegisterPermission("ufs.configurations.delete")

	// RegistrationsGet allows to get registration resources.
	RegistrationsGet = realms.RegisterPermission("ufs.registrations.get")
	// RegistrationsList allows to list registration resources.
	RegistrationsList = realms.RegisterPermission("ufs.registrations.list")
	// RegistrationsCreate allows to create registration resources.
	RegistrationsCreate = realms.RegisterPermission("ufs.registrations.create")
	// RegistrationsUpdate allows to update registration resources.
	RegistrationsUpdate = realms.RegisterPermission("ufs.registrations.update")
	// RegistrationsDelete allows to delete registration resources.
	RegistrationsDelete = realms.RegisterPermission("ufs.registrations.delete")

	// InventoriesGet allows to get inventory resources.
	InventoriesGet = realms.RegisterPermission("ufs.inventories.get")
	// InventoriesList allows to list inventory resources.
	InventoriesList = realms.RegisterPermission("ufs.inventories.list")
	// InventoriesCreate allows to create inventory resources.
	InventoriesCreate = realms.RegisterPermission("ufs.inventories.create")
	// InventoriesUpdate allows to update inventory resources.
	InventoriesUpdate = realms.RegisterPermission("ufs.inventories.update")
	// InventoriesDelete allows to delete inventory resources.
	InventoriesDelete = realms.RegisterPermission("ufs.inventories.delete")

	// NetworksGet allows to get network resources.
	NetworksGet = realms.RegisterPermission("ufs.networks.get")
	// NetworksList allows to list network resources.
	NetworksList = realms.RegisterPermission("ufs.networks.list")
	// NetworksCreate allows to create network resources.
	NetworksCreate = realms.RegisterPermission("ufs.networks.create")
	// NetworksUpdate allows to update network resources.
	NetworksUpdate = realms.RegisterPermission("ufs.networks.update")
	// NetworksDelete allows to delete network resources.
	NetworksDelete = realms.RegisterPermission("ufs.networks.delete")

	// ResourcesImport allows to import resource resources.
	ResourcesImport = realms.RegisterPermission("ufs.resources.import")
)

UFS registered permissions in process registry

View Source
var ClientToDatastoreNamespace = map[string]string{
	BrowserNamespace: "",
	OSNamespace:      OSNamespace,
}

ClientToDatastoreNamespace refers a map between client namespace(set in context metadata) to actual datastore namespace

View Source
var ServoV3HostnameRegex = regexp.MustCompile(`.*-servo`)

ServoV3HostnameRegex is used to identify servo V3 hosts.

View Source
var SkipRealmsCheck = false

SkipRealmsCheck flag to skip realms check

View Source
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.

View Source
var StrToAntennaConnection = map[string]string{
	"unknown":    "CONN_UNKNOWN",
	"conductive": "CONN_CONDUCTIVE",
	"ota":        "CONN_OTA",
}

StrToAntennaConnection refers a map between a string to a AntennaConnection map.

View Source
var StrToCableType = map[string]string{
	"invalid":     "CABLE_INVALID",
	"audiojack":   "CABLE_AUDIOJACK",
	"usbaudio":    "CABLE_USBAUDIO",
	"usbprinting": "CABLE_USBPRINTING",
	"hdmiaudio":   "CABLE_HDMIAUDIO",
}

StrToCableType refers a map between a string to a CableType map.

View Source
var StrToCameraType = map[string]string{
	"invalid": "CAMERA_INVALID",
	"huddly":  "CAMERA_HUDDLY",
	"ptzpro2": "CAMERA_PTZPRO2",
}

StrToCameraType refers a map between a string to a CameraType map.

View Source
var StrToChameleonType = map[string]string{
	"invalid": "CHAMELEON_TYPE_INVALID",
	"dp":      "CHAMELEON_TYPE_DP",
	"dphdmi":  "CHAMELEON_TYPE_DP_HDMI",
	"vga":     "CHAMELEON_TYPE_VGA",
	"hdmi":    "CHAMELEON_TYPE_HDMI",
}

StrToChameleonType refers a map between a string to a ChameleonType map.

View Source
var StrToFacing = map[string]string{
	"unknown": "FACING_UNKNOWN",
	"back":    "FACING_BACK",
	"front":   "FACING_FRONT",
}

StrToFacing refers a map between a string to a Facing map.

View Source
var StrToLicenseType = map[string]string{
	"invalid":      "LICENSE_TYPE_UNSPECIFIED",
	"windows10pro": "LICENSE_TYPE_WINDOWS_10_PRO",
	"msofficestd":  "LICENSE_TYPE_MS_OFFICE_STANDARD",
}

StrToLicenseType refers a map between a string to a LicenseType map.

View Source
var StrToLight = map[string]string{
	"unknown": "LIGHT_UNKNOWN",
	"led":     "LIGHT_LED",
	"noled":   "LIGHT_NOLED",
}

StrToLight refers a map between a string to a Light map.

View Source
var StrToRouter = map[string]string{
	"unspecified": "ROUTER_UNSPECIFIED",
	"80211ax":     "ROUTER_802_11AX",
}

StrToRouter refers a map between a string to a Router map.

View Source
var StrToSchedulingUnitType = map[string]string{
	"invalid":    "SCHEDULING_UNIT_TYPE_INVALID",
	"all":        "SCHEDULING_UNIT_TYPE_ALL",
	"individual": "SCHEDULING_UNIT_TYPE_INDIVIDUAL",
}

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

View Source
var StrToUFSDeviceType = map[string]string{
	"chromebook":  "DEVICE_CHROMEBOOK",
	"labstation":  "DEVICE_LABSTATION",
	"servo":       "DEVICE_SERVO",
	"unspecified": "CHROME_OS_DEVICE_TYPE_UNSPECIFIED",
}

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

View Source
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.

View Source
var StrToUFSZone = genStrToUFSZone()

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

Functions

func AddPrefix

func AddPrefix(collection, entity string) string

AddPrefix adds the prefix for a given resource name

func AppendUniqueStrings

func AppendUniqueStrings(des []string, src ...string) []string

AppendUniqueStrings returns a slice with unique elements such that all the des elements are appended to src.

func CheckPermission

func CheckPermission(ctx context.Context, perm realms.Permission, realm string) error

CheckPermission checks if the user has permission in the realm

return error if user doesnt have permission or unable to check permission in realm else returns nil

func ContainsAnyStrings

func ContainsAnyStrings(list []string, inputs ...string) bool

ContainsAnyStrings returns true if at least one of the inputs is in list.

func CurrentUser

func CurrentUser(ctx context.Context) string

CurrentUser returns the current user

func DUTToLSE

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

DUTToLSE converts a DUT spec to a UFS machine LSE

func DeviceToAssetMeta

func DeviceToAssetMeta(d *lab.ChromeOSDevice) (*ufspb.AssetInfo, string, ufspb.AssetType)

DeviceToAssetMeta creates an asset for the device

func ExecuteRequest

func ExecuteRequest(ctx context.Context, hc *http.Client, req *http.Request, value proto.Message) error

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 FormatDeploymentRecord

func FormatDeploymentRecord(hostname, serialNumber string) *ufspb.MachineLSEDeployment

FormatDeploymentRecord initialize a MachineLSE deployment record object by hostname and given serial number.

func FormatIP

func FormatIP(vlanName, ipAddress string, reserve, 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 GetCrOSLabName

func GetCrOSLabName(raw string) string

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

func GetHiveForDut

func GetHiveForDut(hostname string) string

GetHiveForDut returns the hive value for a DUT.

hive value is derived from the DUT hostname.

func GetHostnameWithNoHostPrefix

func GetHostnameWithNoHostPrefix(suffix string) string

GetHostnameWithNoHostPrefix generates a hostname with NoHostPrefix.

func GetIPName

func GetIPName(vlanName, ipv4Str string) string

GetIPName returns a formatted IP name

func GetNewNicNameForRenameMachine

func GetNewNicNameForRenameMachine(oldNicName, oldMachineName, newMachineName string) string

GetNewNicNameForRenameMachine returns new nic name for new machine 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 GetResourcePrefix

func GetResourcePrefix(message proto.Message) (string, error)

GetResourcePrefix gets the resource prefix given to the proto message.

Returns the resource prefix for a given proto message. See also: https://blog.golang.org/protobuf-apiv2

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 GetValidRealmName

func GetValidRealmName(realm string) string

GetValidRealmName replaces the older Browser realm with newer realm

func HostnameToLocation

func HostnameToLocation(hostname string) *ufspb.Location

HostnameToLocation convert hostname to location

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 IsAntennaConnection

func IsAntennaConnection(antennaConnection string) bool

IsAntennaConnection checks if a string refers to a valid AntennaConnection.

func IsAssetType

func IsAssetType(assetType string) bool

IsAssetType checks if a strings is a valid asset type

func IsCableType

func IsCableType(cableType string) bool

IsCableType checks if a string refers to a valid CableType.

func IsCameraType

func IsCameraType(cameraType string) bool

IsCameraType checks if a string refers to a valid CameraType.

func IsChameleonType

func IsChameleonType(chameleonType string) bool

IsChameleonType checks if a string refers to a valid ChameleonType.

func IsClientNamespace

func IsClientNamespace(namespace string) bool

IsClientNamespace checks if a string refers to a valid client namespace.

func IsFacing

func IsFacing(facing string) bool

IsFacing checks if a string refers to a valid Facing.

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 IsLicenseType

func IsLicenseType(licenseType string) bool

IsLicenseType checks if a string refers to a valid LicenseType.

func IsLight

func IsLight(light string) bool

IsLight checks if a string refers to a valid Light.

func IsMacFormatValid

func IsMacFormatValid(userMac string) error

IsMacFormatValid check if the given mac address is in valid format

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error has code NOT_FOUND

func IsRouter

func IsRouter(router string) bool

IsRouter checks if a string refers to a valid Router.

func IsSchedulingUnitType

func IsSchedulingUnitType(schedulingUnitType string) bool

IsSchedulingUnitType checks if a string refers to a valid SchedulingUnitType.

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 LabToZone

func LabToZone(lab string) ufspb.Zone

LabToZone converts deprecated Lab type to 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, freeStartIP, freeEndIP string) ([]*ufspb.IP, int, string, string, 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 ProtoEqual

func ProtoEqual(i, j proto.Message) bool

ProtoEqual compares the given protos i, j and returns true if Type(i) == Type(j) and one of the following holds 1. i == j == nil 2. For each exported field(proto message field) x in Type(i), i.Equal(j) or i.x == j.y. returns false otherwise.

func PublishHaRTAssetInfoRequest

func PublishHaRTAssetInfoRequest(ctx context.Context, assets []string) (err error)

PublishHaRTAssetInfoRequest sends a request for asset info update for given assets

func RemoveGivenPrefix

func RemoveGivenPrefix(msg, prefix string) string

RemoveGivenPrefix removes the prefix from the string

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 SetupDatastoreNamespace

func SetupDatastoreNamespace(ctx context.Context, namespace string) (context.Context, error)

SetupDatastoreNamespace sets the datastore namespace in the context to access the correct namespace in the datastore

func ToAntennaConnection

func ToAntennaConnection(antennaConnection string) chromeosLab.Wifi_AntennaConnection

ToAntennaConnection converts antennaConnection string to a Wifi_AntennaConnection enum.

func ToAssetType

func ToAssetType(assetType string) ufspb.AssetType

ToAssetType returns an AssetType object corresponding to string

func ToCableType

func ToCableType(cableType string) chromeosLab.CableType

ToCableType converts cableType string to a Cable type enum.

func ToCameraType

func ToCameraType(cameraType string) chromeosLab.CameraType

ToCameraType converts cameraType string to a Camera type enum.

func ToChameleonType

func ToChameleonType(chameleonType string) chromeosLab.ChameleonType

ToChameleonType converts devicetype string to a Chameleon type enum.

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 ToFacing

func ToFacing(facing string) chromeosLab.Camerabox_Facing

ToFacing converts facing string to a Camerabox_Facing enum.

func ToLab

func ToLab(datacenter string) ufspb.Lab

ToLab converts the crimson lab string to UFS lab.

func ToLicenseType

func ToLicenseType(licenseType string) chromeosLab.LicenseType

ToLicenseType converts licenseType string to a License type enum.

func ToLight

func ToLight(light string) chromeosLab.Camerabox_Light

ToLight converts light string to a Camerabox_Light enum.

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 ToOSAssets

func ToOSAssets(labConfigs []*invV2Api.ListCrosDevicesLabConfigResponse_LabConfig, existingAssetMap map[string]*ufspb.Asset) []*ufspb.Asset

ToOSAssets converts cros inventory data to UFS ChromeOS assets.

func ToOSDutStates

ToOSDutStates converts cros inventory data to UFS dut states for ChromeOS machines.

func ToOSMachineLSEs

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 ToRouter

func ToRouter(router string) chromeosLab.Wifi_Router

ToRouter converts router string to a Wifi_Router enum.

func ToSchedulingUnitType

func ToSchedulingUnitType(schedulingUnitType string) ufspb.SchedulingUnitType

ToSchedulingUnitType converts SchedulingUnitType string to a UFS SchedulingUnitType enum.

func ToState

func ToState(state crimsoncommon.State) ufspb.State

ToState converts crimson state to UFS state.

func ToUFSDeploymentEnv

func ToUFSDeploymentEnv(env string) ufspb.DeploymentEnv

ToUFSDeploymentEnv converts string to a UFS DeploymentEnv enum.

func ToUFSDept

func ToUFSDept(zone string) string

ToUFSDept returns the dept name based on zone string.

func ToUFSDeviceType

func ToUFSDeviceType(devicetype string) ufspb.ChromeOSDeviceType

ToUFSDeviceType converts devicetype string to a UFS devicetype enum.

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 ValidAntennaConnectionStr

func ValidAntennaConnectionStr() []string

ValidAntennaConnectionStr returns a valid str list for AntennaConnection strings.

func ValidAssetTypeStr

func ValidAssetTypeStr() []string

ValidAssetTypeStr returns a valid str list for AssetTypes

func ValidCableTypeStr

func ValidCableTypeStr() []string

ValidCableTypeStr returns a valid str list for CableType strings.

func ValidCameraTypeStr

func ValidCameraTypeStr() []string

ValidCameraTypeStr returns a valid str list for CameraType strings.

func ValidChameleonTypeStr

func ValidChameleonTypeStr() []string

ValidChameleonTypeStr returns a valid str list for Chameleontype strings.

func ValidClientNamespaceStr

func ValidClientNamespaceStr() []string

ValidClientNamespaceStr returns a valid str list for client namespace(set in incoming context metadata) strings.

func ValidDeploymentEnvStr

func ValidDeploymentEnvStr() []string

ValidDeploymentEnvStr returns a valid str list for DeploymentEnv

func ValidDeviceTypeStr

func ValidDeviceTypeStr() []string

ValidDeviceTypeStr returns a valid str list for devicetype strings.

func ValidFacingStr

func ValidFacingStr() []string

ValidFacingStr returns a valid str list for Facing strings.

func ValidLicenseTypeStr

func ValidLicenseTypeStr() []string

ValidLicenseTypeStr returns a valid str list for LicenseType strings.

func ValidLightStr

func ValidLightStr() []string

ValidLightStr returns a valid str list for Light strings.

func ValidRouterStr

func ValidRouterStr() []string

ValidRouterStr returns a valid str list for Router strings.

func ValidSchedulingUnitTypeStr

func ValidSchedulingUnitTypeStr() []string

ValidSchedulingUnitTypeStr returns a valid str list for SchedulingUnitType strings.

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.

func ValidateTags

func ValidateTags(tags []string) bool

ValidateTags checks if the tags contain only valid characters

Types

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 HTTPError

type HTTPError struct {
	Method     string
	URL        *url.URL
	StatusCode int
	Body       string
}

HTTPError wraps the http response errors.

func (*HTTPError) Error

func (e *HTTPError) Error() string

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 https://cloud.google.com/pubsub/docs/push?hl=en#receiving_push_messages

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL