Exemplo n.º 1
0
Arquivo: get.go Projeto: flazz/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	containerInfo, err := containers.Get(command.Ctx.ServiceClient, containerName).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(containerInfo)
	resource.Result.(map[string]interface{})["Name"] = containerName
}
Exemplo n.º 2
0
// print details of cloud files containers 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.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)
	}

	myC, err3 := containers.Get(serviceClient, containerName).Extract()
	if err3 != nil {
		fmt.Println(err3)
	}

	fmt.Println(myC)
}
func TestContainers(t *testing.T) {
	c, err := createClient(t, false)
	th.AssertNoErr(t, err)

	t.Logf("Containers Info available to the currently issued token:")
	count := 0
	err = raxContainers.List(c, &osContainers.ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
		t.Logf("--- Page %02d ---", count)

		containers, err := raxContainers.ExtractInfo(page)
		th.AssertNoErr(t, err)

		for i, container := range containers {
			t.Logf("[%02d]      name=[%s]", i, container.Name)
			t.Logf("            count=[%d]", container.Count)
			t.Logf("            bytes=[%d]", container.Bytes)
		}

		count++
		return true, nil
	})
	th.AssertNoErr(t, err)
	if count == 0 {
		t.Errorf("No containers listed for your current token.")
	}

	t.Logf("Container Names available to the currently issued token:")
	count = 0
	err = raxContainers.List(c, &osContainers.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
		t.Logf("--- Page %02d ---", count)

		names, err := raxContainers.ExtractNames(page)
		th.AssertNoErr(t, err)

		for i, name := range names {
			t.Logf("[%02d] %s", i, name)
		}

		count++
		return true, nil
	})
	th.AssertNoErr(t, err)
	if count == 0 {
		t.Errorf("No containers listed for your current token.")
	}

	createres := raxContainers.Create(c, "gophercloud-test", nil)
	th.AssertNoErr(t, createres.Err)
	defer func() {
		res := raxContainers.Delete(c, "gophercloud-test")
		th.AssertNoErr(t, res.Err)
	}()

	updateres := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": "mountains"}})
	th.AssertNoErr(t, updateres.Err)
	t.Logf("Headers from Update Account request: %+v\n", updateres.Header)
	defer func() {
		res := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": ""}})
		th.AssertNoErr(t, res.Err)
		metadata, err := raxContainers.Get(c, "gophercloud-test").ExtractMetadata()
		th.AssertNoErr(t, err)
		t.Logf("Metadata from Get Account request (after update reverted): %+v\n", metadata)
		th.CheckEquals(t, metadata["White"], "")
	}()

	getres := raxContainers.Get(c, "gophercloud-test")
	t.Logf("Headers from Get Account request (after update): %+v\n", getres.Header)
	metadata, err := getres.ExtractMetadata()
	th.AssertNoErr(t, err)
	t.Logf("Metadata from Get Account request (after update): %+v\n", metadata)
	th.CheckEquals(t, metadata["White"], "mountains")
}
Exemplo n.º 4
0
func (s *Swift) GetContainer() (container Container, err error) {
	cerr := make(chan error)
	m := &sync.Mutex{}
	container = Container{}

	// get account quota
	go func(mm *sync.Mutex) {
		account := accounts.Get(s.client)
		headers, err := account.ExtractHeader()
		if err != nil {
			cerr <- err
			return
		}

		var quota uint64
		strval := headers.Get("X-Account-Meta-Quota-Bytes")
		if strval != "" {
			quota, err = strconv.ParseUint(strval, 10, 64)
			if err != nil {
				quota = DEFAULT_ACCOUNT_QUOTA
			}

		} else {
			quota = DEFAULT_ACCOUNT_QUOTA
		}

		m.Lock()
		container.Quota = quota
		m.Unlock()

		cerr <- nil
	}(m)

	// get container used
	go func(mm *sync.Mutex) {
		var strval string

		result := containers.Get(s.client, s.containerName)
		if result.Err != nil {
			cerr <- result.Err
			return
		}

		headers, err := result.ExtractHeader()
		if err != nil {
			cerr <- err
			return
		}

		var used, count uint64
		strval = headers.Get("X-Container-Bytes-Used")
		if strval != "" {
			if used, err = strconv.ParseUint(strval, 10, 64); err != nil {
				used = 0
			}
		}

		strval = headers.Get("X-Container-Object-Count")
		if strval != "" {
			if count, err = strconv.ParseUint(strval, 10, 64); err != nil {
				count = 0
			}
		}

		m.Lock()
		container.Used = used
		container.Count = count
		m.Unlock()

		cerr <- nil
	}(m)

	var i = 0
	for i < 2 {
		if err = <-cerr; err != nil {
			return container, err
		}
		i++
	}

	return container, nil
}