//
// SPDX-License-Identifier: AGPL-3.0
-package dispatchcloud
+package cloud
import (
"context"
"golang.org/x/crypto/ssh"
)
-type AzureProviderConfig struct {
+type AzureInstanceSetConfig struct {
SubscriptionID string `json:"subscription_id"`
ClientID string `json:"key"`
ClientSecret string `json:"secret"`
return err
}
-type AzureProvider struct {
- azconfig AzureProviderConfig
+type AzureInstanceSet struct {
+ azconfig AzureInstanceSetConfig
vmClient VirtualMachinesClientWrapper
netClient InterfacesClientWrapper
storageAcctClient storageacct.AccountsClient
namePrefix string
}
-func NewAzureProvider(azcfg AzureProviderConfig, dispatcherID string) (prv InstanceProvider, err error) {
- ap := AzureProvider{}
+func NewAzureInstanceSet(config map[string]interface{}, dispatcherID string) (prv InstanceProvider, err error) {
+ azcfg := AzureInstanceSetConfig{}
+ err = mapstructure.Decode(config, &azcfg)
+ if err != nil {
+ return nil, err
+ }
+ ap := AzureInstanceSet{}
err = ap.setup(azcfg, dispatcherID)
if err != nil {
return nil, err
return &ap, nil
}
-func (az *AzureProvider) setup(azcfg AzureProviderConfig, dispatcherID string) (err error) {
+func (az *AzureInstanceSet) setup(azcfg AzureInstanceSetConfig, dispatcherID string) (err error) {
az.azconfig = azcfg
vmClient := compute.NewVirtualMachinesClient(az.azconfig.SubscriptionID)
netClient := network.NewInterfacesClient(az.azconfig.SubscriptionID)
return nil
}
-func (az *AzureProvider) Create(ctx context.Context,
+func (az *AzureInstanceSet) Create(ctx context.Context,
instanceType arvados.InstanceType,
imageId ImageID,
newTags InstanceTags,
}, nil
}
-func (az *AzureProvider) Instances(ctx context.Context) ([]Instance, error) {
+func (az *AzureInstanceSet) Instances(ctx context.Context) ([]Instance, error) {
interfaces, err := az.ManageNics(ctx)
if err != nil {
return nil, err
return instances, nil
}
-func (az *AzureProvider) ManageNics(ctx context.Context) (map[string]network.Interface, error) {
+func (az *AzureInstanceSet) ManageNics(ctx context.Context) (map[string]network.Interface, error) {
result, err := az.netClient.ListComplete(ctx, az.azconfig.ResourceGroup)
if err != nil {
return nil, WrapAzureError(err)
return interfaces, nil
}
-func (az *AzureProvider) ManageBlobs(ctx context.Context) {
+func (az *AzureInstanceSet) ManageBlobs(ctx context.Context) {
result, err := az.storageAcctClient.ListKeys(ctx, az.azconfig.ResourceGroup, az.azconfig.StorageAccount)
if err != nil {
log.Printf("Couldn't get account keys %v", err)
}
}
-func (az *AzureProvider) Stop() {
+func (az *AzureInstanceSet) Stop() {
}
type AzureInstance struct {
- provider *AzureProvider
+ provider *AzureInstanceSet
nic network.Interface
vm compute.VirtualMachine
}
//
// SPDX-License-Identifier: AGPL-3.0
-package dispatchcloud
+package cloud
import (
"context"
"git.curoverse.com/arvados.git/sdk/go/arvados"
)
-var drivers = map[string]cloud.Driver{}
+var drivers = map[string]cloud.Driver{
+ "azure": "",
+}
func newInstanceSet(cluster *arvados.Cluster, setID cloud.InstanceSetID) (cloud.InstanceSet, error) {
driver, ok := drivers[cluster.CloudVMs.Driver]
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-package dispatchcloud
-
-import (
- "context"
- "time"
-
- "git.curoverse.com/arvados.git/sdk/go/arvados"
- "golang.org/x/crypto/ssh"
-)
-
-// A RateLimitError should be returned by a Provider when the cloud
-// service indicates it is rejecting all API calls for some time
-// interval.
-type RateLimitError interface {
- // Time before which the caller should expect requests to
- // fail.
- EarliestRetry() time.Time
- error
-}
-
-// A QuotaError should be returned by a Provider when the cloud
-// service indicates the account cannot create more VMs than already
-// exist.
-type QuotaError interface {
- // If true, don't create more instances until some existing
- // instances are destroyed. If false, don't handle the error
- // as a quota error.
- IsQuotaError() bool
- error
-}
-
-type InstanceTags map[string]string
-type InstanceID string
-type ImageID string
-
-// instance is implemented by the provider-specific instance types.
-type Instance interface {
- // ID returns the provider's instance ID. It must be stable
- // for the life of the instance.
- ID() InstanceID
-
- // String typically returns the cloud-provided instance ID.
- String() string
-
- // Get tags
- Tags(context.Context) (InstanceTags, error)
-
- // Replace tags with the given tags
- SetTags(context.Context, InstanceTags) error
-
- // Shut down the node
- Destroy(context.Context) error
-
- // SSH server hostname or IP address, or empty string if unknown pending creation.
- Address() string
-
- // Return nil if the given public key matches the instance's
- // SSH server key. If the provided ssh client is not nil,
- // VerifyPublicKey can use it to make outgoing network
- // connections from the instance -- e.g., to use the cloud's
- // "this instance's metadata" API.
- VerifyPublicKey(context.Context, ssh.PublicKey, *ssh.Client) error
-}
-
-type InstanceProvider interface {
- // Create a new instance. If supported by the driver, add the
- // provided public key to /root/.ssh/authorized_keys.
- //
- // The returned error should implement RateLimitError and
- // QuotaError where applicable.
- Create(context.Context, arvados.InstanceType, ImageID, InstanceTags, ssh.PublicKey) (Instance, error)
-
- // Return all instances, including ones that are booting or
- // shutting down.
- //
- // An instance returned by successive calls to Instances() may
- // -- but does not need to -- be represented by the same
- // Instance object each time. Thus, the caller is responsible
- // for de-duplicating the returned instances by comparing the
- // InstanceIDs returned by the instances' ID() methods.
- Instances(context.Context) ([]Instance, error)
-
- // Stop any background tasks and release other resources.
- Stop()
-}