Documentation
¶
Overview ¶
Package metadata implements a client for the DigitalOcean metadata API. This API allows a droplet to inspect information about itself, like it's region, droplet ID, and so on.
Documentation for the API is available at:
https://developers.digitalocean.com/documentation/metadata/
Example ¶
Create a client and query it for all available metadata.
// Create a client client := metadata.NewClient(opts) // Request all the metadata about the current droplet all, err := client.Metadata() if err != nil { log.Fatal(err) } // Lookup what our IPv4 address is on our first public // network interface. publicIPv4Addr := all.Interfaces["public"][0].IPv4.IPAddress fmt.Println(publicIPv4Addr)
Output: 192.168.0.100
Index ¶
- type Client
- func (c *Client) AuthToken() (string, error)
- func (c *Client) DropletID() (int, error)
- func (c *Client) FloatingIPv4Active() (bool, error)
- func (c *Client) Hostname() (string, error)
- func (c *Client) Metadata() (*Metadata, error)
- func (c *Client) Nameservers() ([]string, error)
- func (c *Client) PublicKeys() ([]string, error)
- func (c *Client) Region() (string, error)
- func (c *Client) ReservedIPv4Active() (bool, error)
- func (c *Client) Tags() ([]string, error)
- func (c *Client) UserData() (string, error)
- func (c *Client) VendorData() (string, error)
- type ClientOption
- type Metadata
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client to interact with the DigitalOcean metadata API, from inside a droplet.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient creates a client for the metadata API.
func (*Client) DropletID ¶
DropletID returns the Droplet's unique identifier. This is automatically generated upon Droplet creation.
func (*Client) FloatingIPv4Active ¶
FloatingIPv4Active returns true if an IPv4 Floating IP Address is assigned to the Droplet.
func (*Client) Hostname ¶
Hostname returns the Droplet's hostname, as specified by the user during Droplet creation.
func (*Client) Metadata ¶
Metadata contains the entire contents of a Droplet's metadata. This method is unique because it returns all of the metadata at once, instead of individual metadata items.
func (*Client) Nameservers ¶
Nameservers returns the nameserver entries that are added to a Droplet's /etc/resolv.conf file during creation.
func (*Client) PublicKeys ¶
PublicKeys returns the public SSH key(s) that were added to the Droplet's root user's authorized_keys file during Droplet creation.
func (*Client) ReservedIPv4Active ¶
ReservedIPv4Active returns true if an IPv4 Reserved IP Address is assigned to the Droplet.
func (*Client) Tags ¶
Tags returns a list of DigitalOcean tags that have been applied to the Droplet.
func (*Client) UserData ¶
UserData returns the user data that was provided by the user during Droplet creation. User data can contain arbitrary data for miscellaneous use or, with certain Linux distributions, an arbitrary shell script or cloud-config file that will be consumed by a variation of cloud-init upon boot. At this time, cloud-config support is included with CoreOS, Ubuntu 14.04, and CentOS 7 images on DigitalOcean.
func (*Client) VendorData ¶
VendorData provided data that can be used to configure Droplets upon their creation. This is similar to user data, but it is provided by DigitalOcean instead of the user.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption modifies the default behavior of a metadata client. This is usually not needed.
func WithBaseURL ¶
func WithBaseURL(base *url.URL) ClientOption
WithBaseURL makes the metadata client reach the metadata API using the given base URL.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient makes the metadata client use the given HTTP client.
type Metadata ¶
type Metadata struct { DropletID int `json:"droplet_id,omitempty"` Hostname string `json:"hostname,omitempty"` UserData string `json:"user_data,omitempty"` VendorData string `json:"vendor_data,omitempty"` PublicKeys []string `json:"public_keys,omitempty"` Region string `json:"region,omitempty"` Tags []string `json:"tags,omitempty"` DNS struct { Nameservers []string `json:"nameservers,omitempty"` } `json:"dns,omitempty"` Interfaces map[string][]struct { MACAddress string `json:"mac,omitempty"` Type string `json:"type,omitempty"` IPv4 *struct { IPAddress string `json:"ip_address,omitempty"` Netmask string `json:"netmask,omitempty"` Gateway string `json:"gateway,omitempty"` } `json:"ipv4,omitempty"` IPv6 *struct { IPAddress string `json:"ip_address,omitempty"` CIDR int `json:"cidr,omitempty"` Gateway string `json:"gateway,omitempty"` } `json:"ipv6,omitempty"` AnchorIPv4 *struct { IPAddress string `json:"ip_address,omitempty"` Netmask string `json:"netmask,omitempty"` Gateway string `json:"gateway,omitempty"` } `json:"anchor_ipv4,omitempty"` } `json:"interfaces,omitempty"` FloatingIP struct { IPv4 struct { IPAddress string `json:"ip_address,omitempty"` Active bool `json:"active,omitempty"` } `json:"ipv4,omitempty"` } `json:"floating_ip,omitempty"` ReservedIP struct { IPv4 struct { IPAddress string `json:"ip_address,omitempty"` Active bool `json:"active,omitempty"` } `json:"ipv4,omitempty"` IPv6 struct { IPAddress string `json:"ip_address,omitempty"` Active bool `json:"active,omitempty"` } `json:"ipv6,omitempty"` } `json:"reserved_ip,omitempty"` Features struct { DHCPEnabled bool `json:"dhcp_enabled,omitempty"` VPCPeeringEnabled bool `json:"vpc_peering_enabled,omitempty"` } `json:"features"` }