Add a minion registry that is backed by a cloud provider.

This commit is contained in:
Brendan Burns
2014-06-24 22:27:33 -07:00
parent 60e2d4b258
commit 93019b8563
5 changed files with 180 additions and 7 deletions

View File

@@ -38,4 +38,6 @@ type TCPLoadBalancer interface {
type Instances interface {
IPAddress(name string) (net.IP, error)
// Lists instances that match 'filter' which is a regular expression which must match the entire instance name
List(filter string) ([]string, error)
}

View File

@@ -18,13 +18,15 @@ package cloudprovider
import (
"net"
"regexp"
)
type FakeCloud struct {
Exists bool
Err error
Calls []string
IP net.IP
Exists bool
Err error
Calls []string
IP net.IP
Machines []string
}
func (f *FakeCloud) addCall(desc string) {
@@ -66,3 +68,14 @@ func (f *FakeCloud) IPAddress(instance string) (net.IP, error) {
f.addCall("ip-address")
return f.IP, f.Err
}
func (f *FakeCloud) List(filter string) ([]string, error) {
f.addCall("list")
result := []string{}
for _, machine := range f.Machines {
if match, _ := regexp.MatchString(filter, machine); match {
result = append(result, machine)
}
}
return result, f.Err
}

View File

@@ -30,9 +30,10 @@ import (
)
type GCECloud struct {
service *compute.Service
projectID string
zone string
service *compute.Service
projectID string
zone string
instanceRE string
}
func getProjectAndZone() (string, string, error) {
@@ -179,3 +180,19 @@ func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
}
return ip, nil
}
func (gce *GCECloud) List(filter string) ([]string, error) {
listCall := gce.service.Instances.List(gce.projectID, gce.zone)
if len(filter) > 0 {
listCall = listCall.Filter("name eq " + filter)
}
res, err := listCall.Do()
if err != nil {
return nil, err
}
var instances []string
for _, instance := range res.Items {
instances = append(instances, instance.Name)
}
return instances, nil
}