本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack.NewComputeV2函数的典型用法代码示例。如果您正苦于以下问题:Golang NewComputeV2函数的具体用法?Golang NewComputeV2怎么用?Golang NewComputeV2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewComputeV2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AttachDisk
// Attaches given cinder volume to the compute running kubelet
func (os *OpenStack) AttachDisk(instanceID string, diskName string) (string, error) {
disk, err := os.getVolume(diskName)
if err != nil {
return "", err
}
cClient, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil || cClient == nil {
glog.Errorf("Unable to initialize nova client for region: %s", os.region)
return "", err
}
if len(disk.Attachments) > 0 && disk.Attachments[0]["server_id"] != nil {
if instanceID == disk.Attachments[0]["server_id"] {
glog.V(4).Infof("Disk: %q is already attached to compute: %q", diskName, instanceID)
return disk.ID, nil
} else {
errMsg := fmt.Sprintf("Disk %q is attached to a different compute: %q, should be detached before proceeding", diskName, disk.Attachments[0]["server_id"])
glog.Errorf(errMsg)
return "", errors.New(errMsg)
}
}
// add read only flag here if possible spothanis
_, err = volumeattach.Create(cClient, instanceID, &volumeattach.CreateOpts{
VolumeID: disk.ID,
}).Extract()
if err != nil {
glog.Errorf("Failed to attach %s volume to %s compute", diskName, instanceID)
return "", err
}
glog.V(2).Infof("Successfully attached %s volume to %s compute", diskName, instanceID)
return disk.ID, nil
}
示例2: TCPLoadBalancer
func (os *OpenStack) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
glog.V(4).Info("openstack.TCPLoadBalancer() called")
if err := openstack.Authenticate(os.provider, os.authOpts); err != nil {
glog.Warningf("Failed to reauthenticate: %v", err)
return nil, false
}
// TODO: Search for and support Rackspace loadbalancer API, and others.
network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find neutron endpoint: %v", err)
return nil, false
}
compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find compute endpoint: %v", err)
return nil, false
}
glog.V(1).Info("Claiming to support TCPLoadBalancer")
return &LoadBalancer{network, compute, os.lbOpts}, true
}
示例3: DetachDisk
// Detaches given cinder volume from the compute running kubelet
func (os *OpenStack) DetachDisk(instanceID string, partialDiskId string) error {
disk, err := os.getVolume(partialDiskId)
if err != nil {
return err
}
cClient, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil || cClient == nil {
glog.Errorf("Unable to initialize nova client for region: %s", os.region)
return err
}
if len(disk.Attachments) > 0 && disk.Attachments[0]["server_id"] != nil && instanceID == disk.Attachments[0]["server_id"] {
// This is a blocking call and effects kubelet's performance directly.
// We should consider kicking it out into a separate routine, if it is bad.
err = volumeattach.Delete(cClient, instanceID, disk.ID).ExtractErr()
if err != nil {
glog.Errorf("Failed to delete volume %s from compute %s attached %v", disk.ID, instanceID, err)
return err
}
glog.V(2).Infof("Successfully detached volume: %s from compute: %s", disk.ID, instanceID)
} else {
errMsg := fmt.Sprintf("Disk: %s has no attachments or is not attached to compute: %s", disk.Name, instanceID)
glog.Errorf(errMsg)
return errors.New(errMsg)
}
return nil
}
示例4: LoadBalancer
func (os *OpenStack) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
glog.V(4).Info("openstack.LoadBalancer() called")
// TODO: Search for and support Rackspace loadbalancer API, and others.
network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find neutron endpoint: %v", err)
return nil, false
}
compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find compute endpoint: %v", err)
return nil, false
}
glog.V(1).Info("Claiming to support LoadBalancer")
if os.lbOpts.LBVersion == "v2" {
return &LbaasV2{LoadBalancer{network, compute, os.lbOpts}}, true
} else {
return &LbaasV1{LoadBalancer{network, compute, os.lbOpts}}, true
}
}
示例5: computeClient
func (c *Config) computeClient() (*gophercloud.ServiceClient, error) {
providerClient, err := c.client()
if err != nil {
return nil, err
}
return openstack.NewComputeV2(providerClient,
gophercloud.EndpointOpts{Region: c.Region})
}
示例6: Init
func (d *driver) Init(context types.Context, config gofig.Config) error {
d.config = config
fields := eff(map[string]interface{}{})
var err error
if d.instanceID, err = d.getInstanceID(); err != nil {
return err
}
fields["moduleName"] = context
fields["instanceId"] = d.instanceID
if d.region, err = d.getInstanceRegion(); err != nil {
return err
}
fields["region"] = d.region
d.region = strings.ToUpper(d.region)
authOpts := d.getAuthOptions()
fields["identityEndpoint"] = d.authURL()
fields["userId"] = d.userID()
fields["userName"] = d.userName()
if d.password() == "" {
fields["password"] = ""
} else {
fields["password"] = "******"
}
fields["tenantId"] = d.tenantID()
fields["tenantName"] = d.tenantName()
fields["domainId"] = d.domainID()
fields["domainName"] = d.domainName()
if d.provider, err = openstack.AuthenticatedClient(authOpts); err != nil {
return goof.WithFieldsE(fields,
"error getting authenticated client", err)
}
if d.client, err = openstack.NewComputeV2(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
goof.WithFieldsE(fields, "error getting newComputeV2", err)
}
if d.clientBlockStorage, err = openstack.NewBlockStorageV1(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
return goof.WithFieldsE(fields,
"error getting newBlockStorageV1", err)
}
log.WithFields(fields).Info("storage driver initialized")
return nil
}
示例7: Init
func (d *driver) Init(r *core.RexRay) error {
d.r = r
fields := ef()
var err error
if d.instanceID, err = getInstanceID(d.r.Config); err != nil {
return err
}
fields["instanceId"] = d.instanceID
if d.region, err = getInstanceRegion(d.r.Config); err != nil {
return err
}
fields["region"] = d.region
d.region = strings.ToUpper(d.region)
authOpts := getAuthOptions(d.r.Config)
fields["identityEndpoint"] = d.r.Config.RackspaceAuthURL
fields["userId"] = d.r.Config.RackspaceUserID
fields["userName"] = d.r.Config.RackspaceUserName
if d.r.Config.RackspacePassword == "" {
fields["password"] = ""
} else {
fields["password"] = "******"
}
fields["tenantId"] = d.r.Config.RackspaceTenantID
fields["tenantName"] = d.r.Config.RackspaceTenantName
fields["domainId"] = d.r.Config.RackspaceDomainID
fields["domainName"] = d.r.Config.RackspaceDomainName
if d.provider, err = openstack.AuthenticatedClient(authOpts); err != nil {
return errors.WithFieldsE(fields,
"error getting authenticated client", err)
}
if d.client, err = openstack.NewComputeV2(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
errors.WithFieldsE(fields, "error getting newComputeV2", err)
}
if d.clientBlockStorage, err = openstack.NewBlockStorageV1(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
return errors.WithFieldsE(fields,
"error getting newBlockStorageV1", err)
}
log.WithField("provider", providerName).Info("storage driver initialized")
return nil
}
示例8: LoadBalancer
func (os *OpenStack) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
glog.V(4).Info("openstack.LoadBalancer() called")
// TODO: Search for and support Rackspace loadbalancer API, and others.
network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find network endpoint: %v", err)
return nil, false
}
compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find compute endpoint: %v", err)
return nil, false
}
lbversion := os.lbOpts.LBVersion
if lbversion == "" {
// No version specified, try newest supported by server
netExts, err := networkExtensions(network)
if err != nil {
glog.Warningf("Failed to list neutron extensions: %v", err)
return nil, false
}
if netExts["lbaasv2"] {
lbversion = "v2"
} else if netExts["lbaas"] {
lbversion = "v1"
} else {
glog.Warningf("Failed to find neutron LBaaS extension (v1 or v2)")
return nil, false
}
glog.V(3).Infof("Using LBaaS extension %v", lbversion)
}
glog.V(1).Info("Claiming to support LoadBalancer")
if lbversion == "v2" {
return &LbaasV2{LoadBalancer{network, compute, os.lbOpts}}, true
} else if lbversion == "v1" {
return &LbaasV1{LoadBalancer{network, compute, os.lbOpts}}, true
} else {
glog.Warningf("Config error: unrecognised lb-version \"%v\"", lbversion)
return nil, false
}
}
示例9: InitComputeClient
func (c *GenericClient) InitComputeClient(d *Driver) error {
if c.Compute != nil {
return nil
}
compute, err := openstack.NewComputeV2(c.Provider, gophercloud.EndpointOpts{
Region: d.Region,
Availability: c.getEndpointType(d),
})
if err != nil {
return err
}
c.Compute = compute
return nil
}
示例10: newClient
func newClient() (*gophercloud.ServiceClient, error) {
ao, err := openstack.AuthOptionsFromEnv()
if err != nil {
return nil, err
}
client, err := openstack.AuthenticatedClient(ao)
if err != nil {
return nil, err
}
return openstack.NewComputeV2(client, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
}
示例11: Instances
// Instances returns an implementation of Instances for OpenStack.
func (os *OpenStack) Instances() (cloudprovider.Instances, bool) {
glog.V(4).Info("openstack.Instances() called")
if err := openstack.Authenticate(os.provider, os.authOpts); err != nil {
glog.Warningf("Failed to reauthenticate: %v", err)
return nil, false
}
compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find compute endpoint: %v", err)
return nil, false
}
pager := flavors.ListDetail(compute, nil)
flavor_to_resource := make(map[string]*api.NodeResources)
err = pager.EachPage(func(page pagination.Page) (bool, error) {
flavorList, err := flavors.ExtractFlavors(page)
if err != nil {
return false, err
}
for _, flavor := range flavorList {
rsrc := api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewQuantity(int64(flavor.VCPUs), resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(int64(flavor.RAM)*MiB, resource.BinarySI),
"openstack.org/disk": *resource.NewQuantity(int64(flavor.Disk)*GB, resource.DecimalSI),
"openstack.org/rxTxFactor": *resource.NewMilliQuantity(int64(flavor.RxTxFactor)*1000, resource.DecimalSI),
"openstack.org/swap": *resource.NewQuantity(int64(flavor.Swap)*MiB, resource.BinarySI),
},
}
flavor_to_resource[flavor.ID] = &rsrc
}
return true, nil
})
if err != nil {
glog.Warningf("Failed to find compute flavors: %v", err)
return nil, false
}
glog.V(3).Infof("Found %v compute flavors", len(flavor_to_resource))
glog.V(1).Info("Claiming to support Instances")
return &Instances{compute, flavor_to_resource}, true
}
示例12: initComputeClient
// initComputeClient initializes openstack api using
// gophercloud which handles auth tokens keeping api calls
// simpler. Currently it uses environment variables for
// authenticating with openstack identity.
func initComputeClient() (*gophercloud.ServiceClient, error) {
opts, err := openstack.AuthOptionsFromEnv()
if err != nil {
log.Println("Error fetching openstack env vars: ", err)
return nil, err
}
provider, err := openstack.AuthenticatedClient(opts)
if err != nil {
log.Println("Error authenticating with openstack: ", err)
return nil, err
}
return openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
Name: "compute",
Region: os.Getenv("OS_REGION_NAME"),
})
}
示例13: Init
func Init() (storagedriver.Driver, error) {
instanceID, err := getInstanceID()
if err != nil {
return nil, fmt.Errorf("Error: %v", err)
}
region, err := getInstanceRegion()
if err != nil {
return nil, fmt.Errorf("Error: %v", err)
}
opts, err := openstack.AuthOptionsFromEnv()
if err != nil {
return nil, fmt.Errorf("Error: %v", err)
}
provider, err := openstack.AuthenticatedClient(opts)
if err != nil {
return nil, fmt.Errorf("Error: %v", err)
}
region = strings.ToUpper(region)
client, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: region,
})
if err != nil {
return nil, fmt.Errorf("Error: %v", err)
}
clientBlockStorage, err := openstack.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
Region: region,
})
if err != nil {
return nil, fmt.Errorf("Error: %v", err)
}
driver := &Driver{
Provider: provider,
Client: client,
ClientBlockStorage: clientBlockStorage,
Region: region,
InstanceID: instanceID,
}
return driver, nil
}
示例14: Routes
func (os *OpenStack) Routes() (cloudprovider.Routes, bool) {
glog.V(4).Info("openstack.Routes() called")
network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find network endpoint: %v", err)
return nil, false
}
netExts, err := networkExtensions(network)
if err != nil {
glog.Warningf("Failed to list neutron extensions: %v", err)
return nil, false
}
if !netExts["extraroute"] {
glog.V(3).Infof("Neutron extraroute extension not found, required for Routes support")
return nil, false
}
compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find compute endpoint: %v", err)
return nil, false
}
r, err := NewRoutes(compute, network, os.routeOpts)
if err != nil {
glog.Warningf("Error initialising Routes support: %v", err)
return nil, false
}
glog.V(1).Info("Claiming to support Routes")
return r, true
}
示例15: FetchPublicKey
func FetchPublicKey(userName string, config *Config) (*keypairs.KeyPair, error) {
regionOpts := gophercloud.EndpointOpts{Region: config.Region}
provider, err := initClient(config)
if err != nil {
return nil, err
}
computeClient, err := openstack.NewComputeV2(provider, regionOpts)
if err != nil {
return nil, err
}
key, err := FindKeyPairByName(computeClient, userName)
if err != nil {
return nil, err
}
return key, nil
}