platform

package
v0.0.0-...-7638cb1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package platform provides instance information

Package platform provides instance information

Package platform contains platform specific utilities.

Package platform contains platform specific utilities.

Index

Examples

Constants

View Source
const (
	// EC2MetadataServiceURL is url for instance metadata.
	EC2MetadataServiceURL = "http://169.254.169.254"
	// SecurityCredentialsResource provides iam credentials
	SecurityCredentialsResource = "/latest/meta-data/iam/security-credentials/"
	// InstanceIdentityDocumentResource provides instance information like instance id, region, availability
	InstanceIdentityDocumentResource = "/latest/dynamic/instance-identity/document"
	// InstanceIdentityDocumentSignatureResource provides instance identity signature
	InstanceIdentityDocumentSignatureResource = "/latest/dynamic/instance-identity/signature"
	// SignedInstanceIdentityDocumentResource provides pkcs7 public key pair value
	SignedInstanceIdentityDocumentResource = "/latest/dynamic/instance-identity/pkcs7"
	// EC2MetadataRequestTimeout specifies the timeout when making web request
	EC2MetadataRequestTimeout = time.Duration(2 * time.Second)
)

Variables

This section is empty.

Functions

func Hostname

func Hostname() (name string, err error)

Hostname of the computer.

func IP

func IP() (ip string, err error)

IP of the network interface

func InstanceID

func InstanceID() (string, error)

InstanceID returns the current instance id

Example
metadata = &metadataStub{instanceID: sampleInstanceID}
managedInstance = registrationStub{err: errors.New(sampleManagedInstError)}
result, err := InstanceID()
fmt.Println(result)
fmt.Println(err)
Output:

i-e6c6f145
<nil>

func IsManagedInstance

func IsManagedInstance() (bool, error)

IsManagedInstance returns if the current instance is managed instance

func IsPlatformNanoServer

func IsPlatformNanoServer(log log.T) (bool, error)

func PlatformName

func PlatformName(log log.T) (name string, err error)

PlatformName gets the OS specific platform name.

func PlatformSku

func PlatformSku(log log.T) (sku string, err error)

PlatformSku gets the OS specific platform SKU number

func PlatformVersion

func PlatformVersion(log log.T) (version string, err error)

PlatformVersion gets the OS specific platform version.

func Region

func Region() (string, error)

Region returns the instance region

Example
metadata = &metadataStub{region: sampleInstanceRegion}
managedInstance = registrationStub{err: errors.New(sampleManagedInstError)}
cachedRegion = ""
result, err := Region()
fmt.Println(result)
fmt.Println(err)
Output:

us-east-1
<nil>

func SetInstanceID

func SetInstanceID(instanceID string) error

SetInstanceID overrides the platform instanceID

Example
err := SetRegion(sampleInstanceID)
fmt.Println(Region())
fmt.Println(err)
Output:

i-e6c6f145 <nil>
<nil>

func SetRegion

func SetRegion(region string) error

SetRegion overrides the platform region

Example
err := SetRegion(sampleInstanceRegion)
fmt.Println(Region())
fmt.Println(err)
Output:

us-east-1 <nil>
<nil>

Types

type EC2MetadataClient

type EC2MetadataClient struct {
	// contains filtered or unexported fields
}

EC2MetadataClient is used to make requests to instance metadata

func NewEC2MetadataClient

func NewEC2MetadataClient() *EC2MetadataClient

NewEC2MetadataClient creates new EC2MetadataClient

func (EC2MetadataClient) InstanceIdentityDocument

func (c EC2MetadataClient) InstanceIdentityDocument() (*InstanceIdentityDocument, error)

InstanceIdentityDocument returns the instance document details querying the metadata

func (EC2MetadataClient) ReadResource

func (c EC2MetadataClient) ReadResource(path string) ([]byte, error)

ReadResource reads from the url path

type InstanceIdentityDocument

type InstanceIdentityDocument struct {
	InstanceID          string   `json:"instanceId"`
	BillingProducts     []string `json:"billingProducts"`
	ImageID             string   `json:"imageId"`
	Architecture        string   `json:"architecture"`
	PendingTimeAsString string   `json:"pendingTime"`
	InstanceType        string   `json:"instanceType"`
	AccountID           string   `json:"accountId"`
	KernelID            string   `json:"kernelId"`
	RamdiskID           string   `json:"ramdiskId"`
	Region              string   `json:"region"`
	Version             string   `json:"version"`
	PrivateIP           string   `json:"privateIp"`
	DevpayProductCodes  string   `json:"devpayProductCodes"`
	AvailabilityZone    string   `json:"availabilityZone"`
}

InstanceIdentityDocument stores the values fetched from querying instance metadata

Sample Result
{
  "devpayProductCodes" : null,
  "availabilityZone" : "us-east-1c",
  "privateIp" : "172.31.32.24",
  "instanceId" : "i-e0a8424b",
  "billingProducts" : null,
  "version" : "2010-08-31",
  "instanceType" : "m3.medium",
  "accountId" : "099688301723",
  "pendingTime" : "2015-08-06T17:06:28Z",
  "imageId" : "ami-1ecae776",
  "kernelId" : null,
  "ramdiskId" : null,
  "architecture" : "x86_64",
  "region" : "us-east-1"
}

func (*InstanceIdentityDocument) PendingTime

func (iid *InstanceIdentityDocument) PendingTime() (time.Time, error)

PendingTime parses the PendingTimeAsString field into a time.

func (*InstanceIdentityDocument) SetPendingTime

func (iid *InstanceIdentityDocument) SetPendingTime(pendingTime time.Time)

SetPendingTime sets the PendingTimeAsString field by formatting a given time.

Jump to

Keyboard shortcuts

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