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 ¶
- Constants
- func Hostname() (name string, err error)
- func IP() (ip string, err error)
- func InstanceID() (string, error)
- func IsManagedInstance() (bool, error)
- func IsPlatformNanoServer(log log.T) (bool, error)
- func PlatformName(log log.T) (name string, err error)
- func PlatformSku(log log.T) (sku string, err error)
- func PlatformVersion(log log.T) (version string, err error)
- func Region() (string, error)
- func SetInstanceID(instanceID string) error
- func SetRegion(region string) error
- type EC2MetadataClient
- type InstanceIdentityDocument
Examples ¶
Constants ¶
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 InstanceID ¶
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 ¶
IsManagedInstance returns if the current instance is managed instance
func PlatformName ¶
PlatformName gets the OS specific platform name.
func PlatformSku ¶
PlatformSku gets the OS specific platform SKU number
func PlatformVersion ¶
PlatformVersion gets the OS specific platform version.
func Region ¶
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 ¶
SetInstanceID overrides the platform instanceID
Example ¶
err := SetRegion(sampleInstanceID) fmt.Println(Region()) fmt.Println(err)
Output: i-e6c6f145 <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.