Beispiel #1
0
func (c *Client) InitNetworkClient(d *openstack.Driver) error {
	if c.Network != nil {
		return nil
	}

	network, err := rackspace.NewNetworkV2(c.Provider, gophercloud.EndpointOpts{
		Region: d.Region,
	})
	if err != nil {
		return err
	}
	c.Network = network
	return nil
}
Beispiel #2
0
func List(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")

	// step 1, set up auth options
	ao := gophercloud.AuthOptions{
		Username: user,
		APIKey:   key,
	}
	// step 2, rax auth to get back provider instance
	//provider, err := rackspace.AuthenticatedClient(ao)
	provider, err := rackspace.AuthenticatedClient(ao)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewNetworkV2(provider, gophercloud.EndpointOpts{
		Name: "cloudNetworks",
		//Type: "network",
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	// Retrieve a pager (i.e. a paginated collection)
	networks_pager := networks.List(serviceClient)
	fmt.Println("networks_pager: ", networks_pager)

	// Define an anonymous function to be executed on each page's iteration
	err6 := networks_pager.EachPage(func(page pagination.Page) (bool, error) {
		networkList, err7 := networks.ExtractNetworks(page)
		if err7 != nil {
			fmt.Println(err7)
		}
		for _, n := range networkList {
			// "s" will be a servers.Server
			// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/servers/results.go
			fmt.Println(n)
		}
		return true, nil
	})
	if err6 != nil {
		fmt.Println(err6)
	}
}
Beispiel #3
0
func authFromScratch(ao gophercloud.AuthOptions, region, serviceType string) (*gophercloud.ServiceClient, error) {
	pc, err := rackspace.AuthenticatedClient(ao)
	if err != nil {
		return nil, err
	}
	var sc *gophercloud.ServiceClient
	switch serviceType {
	case "compute":
		sc, err = rackspace.NewComputeV2(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	case "object-store":
		sc, err = rackspace.NewObjectStorageV1(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	case "blockstorage":
		sc, err = rackspace.NewBlockStorageV1(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	case "network":
		sc, err = rackspace.NewNetworkV2(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	}
	if err != nil {
		return nil, err
	}
	if sc == nil {
		return nil, fmt.Errorf("Unable to create service client: Unknown service type: %s", serviceType)
	}
	sc.UserAgent.Prepend(util.UserAgent)
	return sc, nil
}