import ( "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/openstack" "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers" "github.com/rackspace/gophercloud/pagination" ) func main() { // Authenticate with OpenStack authOpts, err := openstack.AuthOptionsFromEnv() if err != nil { panic(err) } provider, err := openstack.AuthenticatedClient(authOpts) if err != nil { panic(err) } // Instantiate a ServiceClient for Object Storage serviceClient, err := openstack.NewObjectStorageV1(provider, gophercloud.EndpointOpts{}) if err != nil { panic(err) } // Create a container createOpts := containers.CreateOpts{ Name: "mycontainer", } container, err := containers.Create(serviceClient, createOpts).Extract() if err != nil { panic(err) } // Upload an object to the container objectName := "myobject" objectContent := "Hello, World!" objectOpts := gophercloud.ObjectOpts{ ContentType: "text/plain", } err = serviceClient.PutObject(container.Name, objectName, []byte(objectContent), &objectOpts).ExtractErr() if err != nil { panic(err) } }
import ( "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/openstack" "github.com/rackspace/gophercloud/openstack/loadbalancer/v2/loadbalancers" "github.com/rackspace/gophercloud/pagination" ) func main() { // Authenticate with OpenStack authOpts, err := openstack.AuthOptionsFromEnv() if err != nil { panic(err) } provider, err := openstack.AuthenticatedClient(authOpts) if err != nil { panic(err) } // Instantiate a ServiceClient for Octavia serviceClient, err := openstack.NewLoadBalancerV2(provider, gophercloud.EndpointOpts{}) if err != nil { panic(err) } // Retrieve the ID of the LoadBalancer to update loadBalancerName := "myloadbalancer" listOpts := loadbalancers.ListOpts{ Name: loadBalancerName, } loadBalancer, err := loadbalancers.List(serviceClient, listOpts).FirstPage() if err != nil { panic(err) } loadBalancerID := loadBalancer[0].ID // Update the LoadBalancer's configuration updateOpts := loadbalancers.UpdateOpts{ Name: "newname", Description: "newdescription", AdminStateUp: gophercloud.Enabled, } _, err = loadbalancers.Update(serviceClient, loadBalancerID, updateOpts).Extract() if err != nil { panic(err) } }This example updates the configuration of an OpenStack Octavia LoadBalancer using the ServiceClient's Update method.