From 26dcef80aad8c8b4e22fe432757af9f014a2feb1 Mon Sep 17 00:00:00 2001 From: janeczku Date: Wed, 27 Jul 2016 20:55:55 +0200 Subject: [PATCH] Update go-rancher-metadata package --- Godeps/Godeps.json | 2 +- .../go-rancher-metadata/metadata/metadata.go | 41 +++++++++++++++++++ .../go-rancher-metadata/metadata/types.go | 26 ++++++++---- metadata/metadata.go | 2 +- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 21d560f..8e55236 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -207,7 +207,7 @@ }, { "ImportPath": "github.com/rancher/go-rancher-metadata/metadata", - "Rev": "9f075a094b0c421ae795af18dba1c8ee45d81ff7" + "Rev": "555b841e1e216a61e83db6d06f7282b9f8e6225b" }, { "ImportPath": "github.com/rancher/go-rancher/client", diff --git a/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/metadata.go b/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/metadata.go index 97047a0..f542861 100644 --- a/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/metadata.go +++ b/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/metadata.go @@ -54,6 +54,20 @@ func (m *Client) GetVersion() (string, error) { return string(resp[:]), nil } +func (m *Client) GetSelfHost() (Host, error) { + resp, err := m.SendRequest("/self/host") + var host Host + if err != nil { + return host, err + } + + if err = json.Unmarshal(resp, &host); err != nil { + return host, err + } + + return host, nil +} + func (m *Client) GetSelfContainer() (Container, error) { resp, err := m.SendRequest("/self/container") var container Container @@ -68,6 +82,20 @@ func (m *Client) GetSelfContainer() (Container, error) { return container, nil } +func (m *Client) GetSelfServiceByName(name string) (Service, error) { + resp, err := m.SendRequest("/self/stack/services/" + name) + var service Service + if err != nil { + return service, err + } + + if err = json.Unmarshal(resp, &service); err != nil { + return service, err + } + + return service, nil +} + func (m *Client) GetSelfService() (Service, error) { resp, err := m.SendRequest("/self/service") var service Service @@ -109,6 +137,19 @@ func (m *Client) GetServices() ([]Service, error) { return services, nil } +func (m *Client) GetStacks() ([]Stack, error) { + resp, err := m.SendRequest("/stacks") + var stacks []Stack + if err != nil { + return stacks, err + } + + if err = json.Unmarshal(resp, &stacks); err != nil { + return stacks, err + } + return stacks, nil +} + func (m *Client) GetContainers() ([]Container, error) { resp, err := m.SendRequest("/containers") var containers []Container diff --git a/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/types.go b/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/types.go index 92ec4a7..00424c7 100644 --- a/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/types.go +++ b/Godeps/_workspace/src/github.com/rancher/go-rancher-metadata/metadata/types.go @@ -1,9 +1,10 @@ package metadata type Stack struct { - EnvironmentName string `json:"environment_name"` - Name string `json:"name"` - Services []string `json:"services"` + EnvironmentName string `json:"environment_name"` + EnvironmentUUID string `json:"environment_uuid"` + Name string `json:"name"` + Services []Service `json:"services"` } type Service struct { @@ -17,11 +18,13 @@ type Service struct { UUID string `json:"uuid"` ExternalIps []string `json:"external_ips"` Sidekicks []string `json:"sidekicks"` - Containers []string `json:"containers"` + Containers []Container `json:"containers"` Ports []string `json:"ports"` Labels map[string]string `json:"labels"` Links map[string]string `json:"links"` Metadata map[string]interface{} `json:"metadata"` + Token string `json:"token"` + Fqdn string `json:"fqdn"` } type Container struct { @@ -34,12 +37,17 @@ type Container struct { Labels map[string]string `json:"labels"` CreateIndex int `json:"create_index"` HostUUID string `json:"host_uuid"` + UUID string `json:"uuid"` + State string `json:"state"` + HealthState string `json:"health_state"` + ExternalId string `json:"external_id"` } type Host struct { - Name string `json:"name"` - AgentIP string `json:"agent_ip"` - HostId int `json:"host_id"` - Labels map[string]string `json:"labels"` - UUID string `json:"uuid"` + Name string `json:"name"` + AgentIP string `json:"agent_ip"` + HostId int `json:"host_id"` + Labels map[string]string `json:"labels"` + UUID string `json:"uuid"` + Hostname string `json:"hostname"` } diff --git a/metadata/metadata.go b/metadata/metadata.go index 9a57838..ecf0e37 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -9,7 +9,7 @@ import ( ) const ( - metadataUrl = "http://rancher-metadata/2015-07-25" + metadataUrl = "http://rancher-metadata/2015-12-19" ) type MetadataClient struct {