// See the CloudImagesProvider interface for details.
func (gsp *genericServersProvider) ListKeyPairs() ([]KeyPair, error) {
	type KeyPairs struct {
		KeyPairs []struct {
			KeyPair KeyPair `json:"keypair"`
		} `json:"keypairs"`
	}

	var kp KeyPairs

	err := gsp.context.WithReauth(gsp.access, func() error {
		url := gsp.endpoint + "/os-keypairs"
		return perigee.Get(url, perigee.Options{
			CustomClient: gsp.context.httpClient,
			Results:      &kp,
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
		})
	})

	// Flatten out the list of keypairs
	var keypairs []KeyPair
	for _, k := range kp.KeyPairs {
		keypairs = append(keypairs, k.KeyPair)
	}
	return keypairs, err
}
Beispiel #2
0
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) ServerById(id string) (*Server, error) {
	var s *Server

	err := gsp.context.WithReauth(gsp.access, func() error {
		url := gsp.endpoint + "/servers/" + id
		return perigee.Get(url, perigee.Options{
			Results: &struct{ Server **Server }{&s},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
			OkCodes: []int{200},
		})
	})

	// Compatibility with v0.0.x -- we "map" our public and private
	// addresses into a legacy structure field for the benefit of
	// earlier software.

	if err != nil {
		return s, err
	}

	err = mapstructure.Decode(s.RawAddresses, &s.Addresses)

	return s, err
}
Beispiel #3
0
// See the CloudServersProvider interface for details.
func (gcp *genericServersProvider) ListServers() ([]Server, error) {
	var ss []Server

	err := gcp.context.WithReauth(gcp.access, func() error {
		url := gcp.endpoint + "/servers/detail"
		return perigee.Get(url, perigee.Options{
			CustomClient: gcp.context.httpClient,
			Results:      &struct{ Servers *[]Server }{&ss},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gcp.access.AuthToken(),
			},
		})
	})

	// Compatibility with v0.0.x -- we "map" our public and private
	// addresses into a legacy structure field for the benefit of
	// earlier software.

	if err != nil {
		return ss, err
	}

	for _, s := range ss {
		err = mapstructure.Decode(s.RawAddresses, &s.Addresses)
		if err != nil {
			return ss, err
		}
	}

	return ss, err
}
Beispiel #4
0
// Images method provides a complete list of images hosted at the region.
func (r *raxRegion) Images() ([]Image, error) {
	var is []Image
	url, _ := r.EndpointByName("images")
	err := perigee.Get(url, perigee.Options{
		CustomClient: r.httpClient,
		Results:      &struct{ Images *[]Image }{&is},
		MoreHeaders: map[string]string{
			"X-Auth-Token": r.token,
		},
	})
	return is, err
}
Beispiel #5
0
// Servers method provides a complete list of servers hosted by the user
// at a given region.
func (r *raxRegion) Servers() ([]Server, error) {
	var ss []Server

	url, _ := r.EndpointByName("servers/detail")
	err := perigee.Get(url, perigee.Options{
		CustomClient: r.httpClient,
		Results:      &struct{ Servers *[]Server }{&ss},
		MoreHeaders: map[string]string{
			"X-Auth-Token": r.token,
		},
	})
	return ss, err
}
Beispiel #6
0
// ServerInfoById provides the complete server information record
// given you know its unique ID.
func (r *raxRegion) ServerInfoById(id string) (*Server, error) {
	var s *Server

	baseUrl, err := r.EndpointByName("servers")
	serverUrl := fmt.Sprintf("%s/%s", baseUrl, id)
	err = perigee.Get(serverUrl, perigee.Options{
		Results: &struct{ Server **Server }{&s},
		MoreHeaders: map[string]string{
			"X-Auth-Token": r.token,
		},
	})
	return s, err
}
Beispiel #7
0
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) GetSGRule(id string) (*SGRule, error) {
	var sgr *SGRule
	err := gsp.context.WithReauth(gsp.access, func() error {
		ep := fmt.Sprintf("%s/os-security-group-default-rules/%s", gsp.endpoint, id)
		return perigee.Get(ep, perigee.Options{
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
			Results: &struct{ Security_group_default_rule **SGRule }{&sgr},
		})
	})
	return sgr, err
}
Beispiel #8
0
// Flavors method provides a complete list of machine configurations (called flavors) available at the region.
func (r *raxRegion) Flavors() ([]Flavor, error) {
	var fs []Flavor

	url, _ := r.EndpointByName("flavors")
	err := perigee.Get(url, perigee.Options{
		CustomClient: r.httpClient,
		Results:      &struct{ Flavors *[]Flavor }{&fs},
		MoreHeaders: map[string]string{
			"X-Auth-Token": r.token,
		},
	})
	return fs, err
}
Beispiel #9
0
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) ServerById(id string) (*Server, error) {
	var s *Server

	err := gsp.context.WithReauth(gsp.access, func() error {
		url := gsp.endpoint + "/servers/" + id
		return perigee.Get(url, perigee.Options{
			Results: &struct{ Server **Server }{&s},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
		})
	})
	return s, err
}
func (gnp *genericNetworksProvider) GetFirewall(firewallId string) (*Firewall, error) {
	var firewall *Firewall

	ep := gnp.endpoint + "/v2.0/fw/firewalls/" + firewallId
	err := perigee.Get(ep, perigee.Options{
		Results: &struct{ Firewall **Firewall }{&firewall},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return firewall, err
}
func (gnp *genericNetworksProvider) GetVip(vipId string) (*Vip, error) {
	var vip *Vip

	ep := gnp.endpoint + "/v2.0/lb/vips/" + vipId
	err := perigee.Get(ep, perigee.Options{
		Results: &struct{ Vip **Vip }{&vip},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return vip, err
}
func (gnp *genericNetworksProvider) GetNetwork(id string) (*Network, error) {
	var n *Network

	ep := gnp.endpoint + "/v2.0/networks/" + id
	err := perigee.Get(ep, perigee.Options{
		Results: &struct{ Network **Network }{&n},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return n, err
}
func (gnp *genericNetworksProvider) GetMember(memberId string) (*Member, error) {
	var member *Member

	ep := gnp.endpoint + "/v2.0/lb/members/" + memberId
	err := perigee.Get(ep, perigee.Options{
		Results: &struct{ Member **Member }{&member},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return member, err
}
func (gnp *genericNetworksProvider) GetPool(poolId string) (*Pool, error) {
	var pool *Pool

	ep := gnp.endpoint + "/v2.0/lb/pools/" + poolId
	err := perigee.Get(ep, perigee.Options{
		Results: &struct{ Pool **Pool }{&pool},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return pool, err
}
func (gnp *genericNetworksProvider) GetSecurityGroup(id string) (*SecurityGroup, error) {
	var s *SecurityGroup

	ep := gnp.endpoint + "/v2.0/security-groups/" + id
	err := perigee.Get(ep, perigee.Options{
		Results: &struct{ SecurityGroup **SecurityGroup }{&s},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return s, err
}
func (gnp *genericNetworksProvider) GetRouter(routerId string) (*Router, error) {
	var r *Router

	ep := gnp.endpoint + "/v2.0/routers/" + routerId
	err := perigee.Get(ep, perigee.Options{
		Results: &struct{ Router **Router }{&r},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return r, err
}
// See CloudServersProvider interface for details.
func (gsp *genericServersProvider) ListFlavors() ([]Flavor, error) {
	var fs []Flavor

	err := gsp.context.WithReauth(gsp.access, func() error {
		url := gsp.endpoint + "/flavors/detail"
		return perigee.Get(url, perigee.Options{
			CustomClient: gsp.context.httpClient,
			Results:      &struct{ Flavors *[]Flavor }{&fs},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
		})
	})
	return fs, err
}
Beispiel #18
0
// See the CloudServersProvider interface for details.
func (gcp *genericServersProvider) ListServersLinksOnly() ([]Server, error) {
	var ss []Server

	err := gcp.context.WithReauth(gcp.access, func() error {
		url := gcp.endpoint + "/servers"
		return perigee.Get(url, perigee.Options{
			CustomClient: gcp.context.httpClient,
			Results:      &struct{ Servers *[]Server }{&ss},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gcp.access.AuthToken(),
			},
		})
	})
	return ss, err
}
Beispiel #19
0
// See the CloudImagesProvider interface for details.
func (gsp *genericServersProvider) ListImages() ([]Image, error) {
	var is []Image

	err := gsp.context.WithReauth(gsp.access, func() error {
		url := gsp.endpoint + "/images/detail"
		return perigee.Get(url, perigee.Options{
			CustomClient: gsp.context.httpClient,
			Results:      &struct{ Images *[]Image }{&is},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
		})
	})
	return is, err
}
func (gsp *genericServersProvider) ShowKeyPair(name string) (KeyPair, error) {
	var kp KeyPair

	err := gsp.context.WithReauth(gsp.access, func() error {
		url := gsp.endpoint + "/os-keypairs/" + name
		return perigee.Get(url, perigee.Options{
			CustomClient: gsp.context.httpClient,
			Results:      &struct{ KeyPair *KeyPair }{&kp},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
		})
	})
	return kp, err
}
func (gnp *genericNetworksProvider) GetMonitor(monitorId string) (*Monitor, error) {
	var monitor *Monitor

	ep := gnp.endpoint + "/v2.0/lb/health_monitors/" + monitorId
	err := perigee.Get(ep, perigee.Options{
		Results: &struct {
			Monitor **Monitor `json:"health_monitor"`
		}{&monitor},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return monitor, err
}
func (gnp *genericNetworksProvider) ListFloatingIps() ([]FloatingIp, error) {
	var floatingips []FloatingIp

	ep := gnp.endpoint + "/v2.0/floatingips"
	err := perigee.Get(ep, perigee.Options{
		Results: &struct {
			FloatingIp *[]FloatingIp `json:"floatingips"`
		}{&floatingips},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return floatingips, err
}
Beispiel #23
0
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) SecurityGroupById(id int) (*SecurityGroup, error) {
	var actual *SecurityGroup

	err := gsp.context.WithReauth(gsp.access, func() error {
		ep := fmt.Sprintf("%s/os-security-groups/%d", gsp.endpoint, id)
		return perigee.Get(ep, perigee.Options{
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
			Results: &struct {
				SecurityGroup **SecurityGroup `json:"security_group"`
			}{&actual},
		})
	})
	return actual, err
}
Beispiel #24
0
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) ListSecurityGroupsByServerId(id string) ([]SecurityGroup, error) {
	var sgs []SecurityGroup

	err := gsp.context.WithReauth(gsp.access, func() error {
		ep := fmt.Sprintf("%s/servers/%s/os-security-groups", gsp.endpoint, id)
		return perigee.Get(ep, perigee.Options{
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
			Results: &struct {
				SecurityGroups *[]SecurityGroup `json:"security_groups"`
			}{&sgs},
		})
	})
	return sgs, err
}
func (gnp *genericNetworksProvider) GetFirewallRule(policyId string) (*FirewallRule, error) {
	var policy *FirewallRule

	ep := gnp.endpoint + "/v2.0/fw/firewall_rules/" + policyId
	err := perigee.Get(ep, perigee.Options{
		Results: &struct {
			FirewallRule **FirewallRule `json:"firewall_rule"`
		}{&policy},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return policy, err
}
func (gnp *genericNetworksProvider) GetPorts() ([]*Port, error) {
	var ports []*Port

	ep := gnp.endpoint + "/v2.0/ports"
	err := perigee.Get(ep, perigee.Options{
		Results: &struct {
			Port *[]*Port `json:"ports"`
		}{&ports},
		MoreHeaders: map[string]string{
			"X-Auth-Token": gnp.access.AuthToken(),
		},
		OkCodes: []int{200},
	})

	return ports, err
}
func (gsp *genericServersProvider) ListFloatingIps() ([]FloatingIp, error) {
	var fips []FloatingIp

	err := gsp.context.WithReauth(gsp.access, func() error {
		url := gsp.endpoint + "/os-floating-ips"
		return perigee.Get(url, perigee.Options{
			CustomClient: gsp.context.httpClient,
			Results: &struct {
				FloatingIps *[]FloatingIp `json:"floating_ips"`
			}{&fips},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
		})
	})
	return fips, err
}
Beispiel #28
0
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) ListAddressesByNetwork(id, networkLabel string) (NetworkAddress, error) {
	pas := make(NetworkAddress)
	var statusCode int

	err := gsp.context.WithReauth(gsp.access, func() error {
		ep := fmt.Sprintf("%s/servers/%s/ips/%s", gsp.endpoint, id, networkLabel)
		return perigee.Get(ep, perigee.Options{
			Results: &pas,
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
			OkCodes:    []int{200, 203},
			StatusCode: &statusCode,
		})
	})

	if err != nil {
		if statusCode == 203 {
			err = WarnUnauthoritative
		}
	}

	return pas, err
}
Beispiel #29
0
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) ListAddresses(id string) (AddressSet, error) {
	var pas *AddressSet
	var statusCode int

	err := gsp.context.WithReauth(gsp.access, func() error {
		ep := fmt.Sprintf("%s/servers/%s/ips", gsp.endpoint, id)
		return perigee.Get(ep, perigee.Options{
			Results: &struct{ Addresses **AddressSet }{&pas},
			MoreHeaders: map[string]string{
				"X-Auth-Token": gsp.access.AuthToken(),
			},
			OkCodes:    []int{200, 203},
			StatusCode: &statusCode,
		})
	})

	if err != nil {
		if statusCode == 203 {
			err = WarnUnauthoritative
		}
	}

	return *pas, err
}
Beispiel #30
0
func listServices(cmd *cli.Cmd) {
	cmd.Action = func() {
		var services ServiceList

		err := perigee.Get(fmt.Sprintf("%s/v1/agent/services", *consulURL), perigee.Options{
			Results: &services,
			OkCodes: []int{200},
		})
		if err != nil {
			fmt.Printf("Error %v", err)
		} else {
			w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
			fmt.Fprint(w, "ID\tSERVICE\tADDRESS\tPORT\n")
			for _, service := range services {
				fmt.Fprintf(w, "%s\t%s\t%s\t%d\n",
					service.ID,
					service.Service,
					service.Address,
					service.Port)
			}
			w.Flush()
		}
	}
}