Exemple #1
0
// 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
}
Exemple #2
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
}
Exemple #3
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(),
			},
		})
	})

	// 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
}
Exemple #4
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
}
Exemple #5
0
// 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
}
Exemple #6
0
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
}
Exemple #7
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
}
Exemple #8
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
}
Exemple #9
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
}
Exemple #10
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
}
Exemple #11
0
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
}
Exemple #12
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
}
Exemple #13
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
}