Exemplo n.º 1
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
}
Exemplo n.º 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
}
Exemplo n.º 3
0
// AllAddressPools returns a complete set of address pools available on the server.
// The name of each pool supported keys the map.
// The value of the map contains the addresses provided in the corresponding pool.
func (s *Server) AllAddressPools() (map[string][]VersionedAddress, error) {
	pools := make(map[string][]VersionedAddress, 0)
	for pool, subtree := range s.RawAddresses {
		addresses := make([]VersionedAddress, 0)
		err := mapstructure.Decode(subtree, &addresses)
		if err != nil {
			return nil, err
		}
		pools[pool] = addresses
	}
	return pools, nil
}
Exemplo n.º 4
0
//Populates an ApiCriteria struct with the api values
//from one of the api maps
func PopulateApi(variant string) (ApiCriteria, error) {
	var Api ApiCriteria
	var variantMap map[string]interface{}

	switch variant {
	case "":
		variantMap = OpenstackApi

	case "openstack":
		variantMap = OpenstackApi

	case "rackspace":
		variantMap = RackspaceApi
	}

	err := mapstructure.Decode(variantMap, &Api)
	if err != nil {
		return Api, err
	}
	return Api, err
}