Esempio n. 1
0
// delete cloud files object from container
func Delete(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	containerName := c.String("container")
	objectName := c.String("name")

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	_, err2 := objects.Delete(serviceClient, containerName, objectName, nil).Extract()
	if err2 != nil {
		fmt.Println(err2)
	}
	fmt.Printf("%v Deleted.", objectName)
}
Esempio n. 2
0
// print list of cloud block storage volumes to stdout
func Show(c *cli.Context) {
    // assign vars from cli args
    user := c.String("user")
    key := c.String("key")
    region := c.String("region")
    volumeId := c.Args().First()
    if c.String("uuid") != "" { volumeId = c.String("uuid") }

    // 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)
    if err != nil { fmt.Println(err) }

    // set rax region
    serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
      Region: region,
    })
    if err2 != nil { fmt.Println(err2) }

    v, err3 := volumes.Get(serviceClient, volumeId).Extract()
    if err3 != nil { fmt.Println(err3) }
    fmt.Println("Name: ", v.Name)
    fmt.Println("ID: ", v.ID)
    fmt.Println("Size: ", v.Size)
    fmt.Println("Status: ", v.Status)
    fmt.Println("Type: ", v.VolumeType)
    fmt.Println("Created: ", v.CreatedAt)
}
Esempio n. 3
0
// delete a cloud block storage snapshots from volume uuid
func Delete(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	volumeId := c.Args().First()
	if c.String("uuid") != "" {
		volumeId = c.String("uuid")
	}

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	// delete snapshot from uuid
	err3 := snapshots.Delete(serviceClient, volumeId).ExtractErr()
	if err3 != nil {
		fmt.Println(err3)
	}
}
Esempio n. 4
0
// create a cloud files container
func Create(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	containerName := c.Args().First()
	if c.String("name") != "" {
		containerName = c.String("name")
	}

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	err2 := containers.Create(serviceClient, containerName, nil)
	fmt.Println(err2)
}
Esempio n. 5
0
func newClient() (*gophercloud.ServiceClient, error) {
	// Obtain credentials from the environment.
	options, err := rackspace.AuthOptionsFromEnv()
	if err != nil {
		return nil, err
	}
	options = tools.OnlyRS(options)
	region := os.Getenv("RS_REGION")

	if options.Username == "" {
		return nil, errors.New("Please provide a Rackspace username as RS_USERNAME.")
	}
	if options.APIKey == "" {
		return nil, errors.New("Please provide a Rackspace API key as RS_API_KEY.")
	}
	if region == "" {
		return nil, errors.New("Please provide a Rackspace region as RS_REGION.")
	}

	client, err := rackspace.AuthenticatedClient(options)
	if err != nil {
		return nil, err
	}

	return rackspace.NewComputeV2(client, gophercloud.EndpointOpts{
		Region: region,
	})
}
Esempio n. 6
0
func NewRackspaceSDK(username, apiKey, SSHKeyName string) *RackspaceSDK {
	if SSHKeyName == "" {
		panic("Empty SSHKeyName of instance don't allow!")
	}
	sdk := &RackspaceSDK{
		Username:     username,
		APIKey:       apiKey,
		SSHKeyName:   SSHKeyName,
		Region:       "HKG",
		InstanceName: "kmg-RackspaceSDK-auto-build",
		ImageName:    "Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)",
		FlavorName:   "4 GB General Purpose v1",
	}
	ao := gophercloud.AuthOptions{
		Username: sdk.Username,
		APIKey:   sdk.APIKey,
	}
	provider, err := rackspace.AuthenticatedClient(ao)
	handleErr(err)
	serviceClient, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: sdk.Region,
	})
	handleErr(err)
	sdk.p = serviceClient
	return sdk
}
Esempio n. 7
0
func GetList(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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	// Retrieve a pager (i.e. a paginated collection)
	server_pager := servers.List(serviceClient, nil)

	// Define an anonymous function to be executed on each page's iteration
	err6 := server_pager.EachPage(func(page pagination.Page) (bool, error) {
		serverList, err7 := servers.ExtractServers(page)
		if err7 != nil {
			fmt.Println(err7)
		}
		for _, s := range serverList {
			// "s" will be a servers.Server
			// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/servers/results.go
			fmt.Println("Name: ", s.Name)
			fmt.Println("UUID: ", s.ID)
			fmt.Println("Created: ", s.Created)
			fmt.Println("Updated: ", s.Updated)
			fmt.Println("Progress: ", s.Progress)
			fmt.Println("HostID: ", s.HostID)
			fmt.Println("Image: ", s.Image["id"])
			fmt.Println("Flavor ID: ", s.Flavor["id"])
			fmt.Println("Status: ", s.Status)
			fmt.Println("Access: ", s.AccessIPv4)
			fmt.Println("Public: ", s.Addresses["public"])
			fmt.Println("Addresses: ", s.Addresses)
			fmt.Println("\n")
		}
		return true, nil
	})
	if err6 != nil {
		fmt.Println(err6)
	}
}
Esempio n. 8
0
func newProvider() (*gophercloud.ProviderClient, error) {
	opts, err := rackspace.AuthOptionsFromEnv()
	if err != nil {
		return nil, err
	}
	opts = tools.OnlyRS(opts)

	return rackspace.AuthenticatedClient(opts)
}
Esempio n. 9
0
func newBlockClient(t *testing.T) (*gophercloud.ServiceClient, error) {
	ao, err := rackspace.AuthOptionsFromEnv()
	th.AssertNoErr(t, err)

	client, err := rackspace.AuthenticatedClient(ao)
	th.AssertNoErr(t, err)

	return openstack.NewBlockStorageV1(client, gophercloud.EndpointOpts{
		Region: os.Getenv("RS_REGION_NAME"),
	})
}
Esempio n. 10
0
func newClient(t *testing.T) *gophercloud.ServiceClient {
	ao, err := rackspace.AuthOptionsFromEnv()
	th.AssertNoErr(t, err)

	client, err := rackspace.AuthenticatedClient(ao)
	th.AssertNoErr(t, err)

	c, err := rackspace.NewCDNV1(client, gophercloud.EndpointOpts{})
	th.AssertNoErr(t, err)
	return c
}
Esempio n. 11
0
func newRackspace(cfg Config) (*Rackspace, error) {
	provider, err := rackspace.AuthenticatedClient(cfg.toAuthOptions())
	if err != nil {
		return nil, err
	}

	os := Rackspace{
		provider: provider,
		region:   cfg.Global.Region,
		lbOpts:   cfg.LoadBalancer,
	}
	return &os, nil
}
Esempio n. 12
0
func newClient(t *testing.T) *gophercloud.ServiceClient {
	ao, err := rackspace.AuthOptionsFromEnv()
	th.AssertNoErr(t, err)

	client, err := rackspace.AuthenticatedClient(ao)
	th.AssertNoErr(t, err)

	c, err := rackspace.NewOrchestrationV1(client, gophercloud.EndpointOpts{
		Region: os.Getenv("RS_REGION_NAME"),
	})
	th.AssertNoErr(t, err)
	return c
}
Esempio n. 13
0
func newClusterClient(endpoint string, ao gophercloud.AuthOptions) (*ClusterClient, error) {
	provider, err := rackspace.AuthenticatedClient(ao)
	if err != nil {
		return nil, err
	}

	return &ClusterClient{
		Client:   &http.Client{},
		Username: ao.Username,
		Token:    provider.TokenID,
		Endpoint: endpoint,
	}, nil
}
Esempio n. 14
0
// create cloud block storage volume in rackspace public cloud
func Create(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	name := c.String("name")
	size := c.Int("size")
	var volType string
	if c.String("type") != "" {
		volType = c.String("type")
	}

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	// https://github.com/rackspace/gophercloud/blob/master/openstack/blockstorage/v1/volumes/requests.go
	opts := osvolumes.CreateOpts{
		Name:       name,
		Size:       size,
		VolumeType: volType,
	}
	if volType == "" {
		opts = osvolumes.CreateOpts{
			Name: name,
			Size: size,
		}
	}

	vol, err3 := volumes.Create(serviceClient, opts).Extract()

	if err3 != nil {
		fmt.Println(err3)
	}
	fmt.Println(vol)
}
Esempio n. 15
0
// print list of cloud servers images to stdout
func Get(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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	//opts3 := images.ListOpts{}
	cmdErr := images.ListDetail(serviceClient, nil).EachPage(func(page pagination.Page) (bool, error) {
		images, err := images.ExtractImages(page)
		if err != nil {
			fmt.Println(err)
		}
		// Use the page of []images.Image
		// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/images/results.go
		for _, i := range images {
			fmt.Println("Name: ", i.Name)
			fmt.Println("ID: ", i.ID)
			fmt.Println("Created: ", i.Created)
			fmt.Println("Updated: ", i.Updated)
			fmt.Println("MinDisk: ", i.MinDisk)
			fmt.Println("MinRAM: ", i.MinRAM)
			fmt.Println("Progress: ", i.Progress)
			fmt.Println("Status: ", i.Status)
			fmt.Println("\n")
		}
		return true, nil
	})
	if cmdErr != nil {
		fmt.Println(cmdErr)
	}
}
Esempio n. 16
0
// print details of cloud servers instance to stdout
func Details(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	// server create specific options
	// check both options and arguments for server uuid
	serverid := c.Args().First()
	if c.String("uuid") != "" {
		serverid = c.String("uuid")
	}

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	// get cloud server
	s, id := servers.Get(serviceClient, serverid).Extract()
	fmt.Println("Name: ", s.Name)
	fmt.Println("UUID: ", s.ID)
	fmt.Println("Created: ", s.Created)
	fmt.Println("Updated: ", s.Updated)
	fmt.Println("Progress: ", s.Progress)
	fmt.Println("HostID: ", s.HostID)
	fmt.Println("Image: ", s.Image["id"])
	fmt.Println("Flavor ID: ", s.Flavor["id"])
	fmt.Println("Status: ", s.Status)
	fmt.Println("Access: ", s.AccessIPv4)
	fmt.Println("Public: ", s.Addresses["public"])
	fmt.Println("Addresses: ", s.Addresses)
	if id != nil {
		fmt.Println(id)
	}
}
Esempio n. 17
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)
	}
}
Esempio n. 18
0
// delete all cloud files object from container
func DeleteAll(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	containerName := c.String("container")
	useConcurrency := c.String("concurrency")

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	// get objects List and delete each
	err3 := objects.List(serviceClient, containerName, nil).EachPage(func(page pagination.Page) (bool, error) {
		objectList, err4 := objects.ExtractNames(page)
		// https://github.com/rackspace/gophercloud/blob/master/openstack/blockstorage/v1/volumes/results.go
		for _, objectName := range objectList {
			// now delete each object here
			// fmt.Println(objName)
			if strings.Compare(useConcurrency, "TRUE") == 0 {
				go deleteObj(serviceClient, containerName, objectName)
			} else {
				deleteObj(serviceClient, containerName, objectName)
			}
		}
		if err4 != nil {
			fmt.Println(err4)
		}
		return true, nil
	})
	if err3 != nil {
		fmt.Println(err3)
	}
}
Esempio n. 19
0
func newClient(t *testing.T) *gophercloud.ServiceClient {
	opts, err := rackspace.AuthOptionsFromEnv()
	th.AssertNoErr(t, err)
	opts = tools.OnlyRS(opts)

	client, err := rackspace.AuthenticatedClient(opts)
	th.AssertNoErr(t, err)

	c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
		Region: "IAD",
	})
	th.AssertNoErr(t, err)

	return c
}
Esempio n. 20
0
func TestAuthenticatedClient(t *testing.T) {
	// Obtain credentials from the environment.
	ao, err := rackspace.AuthOptionsFromEnv()
	th.AssertNoErr(t, err)

	client, err := rackspace.AuthenticatedClient(tools.OnlyRS(ao))
	if err != nil {
		t.Fatalf("Unable to authenticate: %v", err)
	}

	if client.TokenID == "" {
		t.Errorf("No token ID assigned to the client")
	}

	t.Logf("Client successfully acquired a token: %v", client.TokenID)
}
Esempio n. 21
0
// print list of cloud servers flavors to stdout
func Get(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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	opts := flavors.ListOpts{}
	cmdErr := flavors.ListDetail(serviceClient, opts).EachPage(func(page pagination.Page) (bool, error) {
		flavors, err := flavors.ExtractFlavors(page)
		if err != nil {
			fmt.Println(err)
		}
		// Use the page of []flavors.Flavor
		// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/flavors/results.go
		for _, f := range flavors {
			fmt.Println("ID: ", f.ID)
			fmt.Println("Name: ", f.Name)
			fmt.Println("Disk: ", f.Disk)
			fmt.Println("RAM: ", f.RAM)
			fmt.Println("VCPUs: ", f.VCPUs)
			fmt.Println("\n")
		}
		return true, nil
	})
	if cmdErr != nil {
		fmt.Println(cmdErr)
	}
}
Esempio n. 22
0
// upload file to Cloud File container
func Upload(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	containerName := c.String("container")
	objectName := c.String("name")
	path := c.String("path")

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	f, err2 := os.Open(path)
	if err2 != nil {
		fmt.Println(err2)
	}
	defer f.Close()
	// reader := bufio.NewReader(f)

	_, err3 := objects.Create(
		serviceClient,
		containerName,
		objectName,
		f,
		nil,
	).ExtractHeader()
	if err3 != nil {
		fmt.Println(err3)
	}
	fmt.Printf("%v Uploaded.", path)
}
Esempio n. 23
0
// print list of cloud block storage volumes to stdout
func GetList(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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	err3 := volumes.List(serviceClient).EachPage(func(page pagination.Page) (bool, error) {
		volumeList, err4 := volumes.ExtractVolumes(page)
		// https://github.com/rackspace/gophercloud/blob/master/openstack/blockstorage/v1/volumes/results.go
		for _, v := range volumeList {
			fmt.Println("Name: ", v.Name)
			fmt.Println("ID: ", v.ID)
			fmt.Println("Size: ", v.Size)
			fmt.Println("Status: ", v.Status)
			fmt.Println("Type: ", v.VolumeType)
			fmt.Println("Created: ", v.CreatedAt)
			fmt.Println("\n")
		}
		if err4 != nil {
			fmt.Println(err4)
		}
		return true, nil
	})
	if err3 != nil {
		fmt.Println(err3)
	}
}
Esempio n. 24
0
func newClient() (*gophercloud.ServiceClient, error) {
	opts, err := rackspace.AuthOptionsFromEnv()
	if err != nil {
		return nil, err
	}
	opts = tools.OnlyRS(opts)
	region := os.Getenv("RS_REGION")

	provider, err := rackspace.AuthenticatedClient(opts)
	if err != nil {
		return nil, err
	}

	return rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
}
Esempio n. 25
0
// print list of cloud files containers to stdout
func List(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	containerName := c.Args().First()
	if c.String("container") != "" {
		containerName = c.String("container")
	}

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	// _, err := containers.Get(serviceClient, "{containerName}").ExtractMetadata()

	err3 := objects.List(serviceClient, containerName, nil).EachPage(func(page pagination.Page) (bool, error) {
		objectList, err4 := objects.ExtractNames(page)
		// https://github.com/rackspace/gophercloud/blob/master/openstack/blockstorage/v1/volumes/results.go
		for _, o := range objectList {
			fmt.Println(o)
		}
		if err4 != nil {
			fmt.Println(err4)
		}
		return true, nil
	})
	if err3 != nil {
		fmt.Println(err3)
	}
}
Esempio n. 26
0
// print list of cloud block storage snapshots to stdout
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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	err3 := snapshots.List(serviceClient).EachPage(func(page pagination.Page) (bool, error) {
		snapshotList, err4 := snapshots.ExtractSnapshots(page)
		for _, s := range snapshotList {
			fmt.Println("Name: ", s.Name)
			fmt.Println("ID: ", s.ID)
			fmt.Println("Size: ", s.Size)
			fmt.Println("Status: ", s.Status)
			fmt.Println("Parent: ", s.VolumeID)
			fmt.Println("Created: ", s.CreatedAt)
			fmt.Println("\n")
		}
		if err4 != nil {
			fmt.Println(err4)
		}
		return true, nil
	})
	if err3 != nil {
		fmt.Println(err3)
	}
}
Esempio n. 27
0
// create cloud servers instance and print out results to stdout (eg. password)
func Create(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	// server create specific options
	newservername := c.String("name")
	imageid := c.String("image")
	flavorid := c.String("flavor")

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err2 := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err2 != nil {
		fmt.Println(err2)
	}

	// create the cloud server
	server, err3 := servers.Create(serviceClient, servers.CreateOpts{
		Name:      newservername,
		ImageRef:  imageid,
		FlavorRef: flavorid,
	}).Extract()

	fmt.Println(server)
	if err3 != nil {
		fmt.Println(err3)
	}
}
Esempio n. 28
0
// Authenticate creates a Rackspace-specific Gophercloud client.
func (c *Client) Authenticate(d *openstack.Driver) error {
	if c.Provider != nil {
		return nil
	}

	log.WithFields(log.Fields{
		"Username": d.Username,
	}).Debug("Authenticating to Rackspace.")

	apiKey := c.driver.APIKey
	opts := gophercloud.AuthOptions{
		Username: d.Username,
		APIKey:   apiKey,
	}

	provider, err := rackspace.AuthenticatedClient(opts)
	if err != nil {
		return err
	}
	c.Provider = provider

	return nil
}
Esempio n. 29
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
}
Esempio n. 30
0
// print details of cloud files object to stdout
func Show(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	containerName := c.String("container")
	objectName := c.String("name")

	// 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)
	if err != nil {
		fmt.Println(err)
	}

	// set rax region
	serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	myObject, err3 := objects.Get(serviceClient, containerName, objectName, nil).Extract()
	if err3 != nil {
		fmt.Println(err3)
	}

	fmt.Println("Name: ", objectName)
	fmt.Println("Bytes: ", myObject.ContentLength)
	fmt.Println("Type: ", myObject.ContentType)
	fmt.Println("Last Modified: ", myObject.LastModified)
}