13964: Return Arvados instance type
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 23 Aug 2018 02:42:26 +0000 (22:42 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Wed, 9 Jan 2019 21:28:15 +0000 (16:28 -0500)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

lib/dispatchcloud/azure.go
lib/dispatchcloud/azure_test.go
lib/dispatchcloud/provider.go

index 29631e6dc616ca4e0605ee431dcd28372663a218..195bd8182f6ff2dbafce0f8acbe7b3eedd311048 100644 (file)
@@ -230,9 +230,10 @@ func (az *AzureProvider) Create(ctx context.Context,
        vmParameters := compute.VirtualMachine{
                Location: &az.azconfig.Location,
                Tags: map[string]*string{
-                       "arvados-class":   to.StringPtr("crunch-dynamic-compute"),
-                       "arvados-cluster": &az.arvconfig.ClusterID,
-                       "created-at":      &timestamp,
+                       "arvados-class":         to.StringPtr("crunch-dynamic-compute"),
+                       "arvados-instance-type": &instanceType.Name,
+                       "arvados-cluster":       &az.arvconfig.ClusterID,
+                       "created-at":            &timestamp,
                },
                VirtualMachineProperties: &compute.VirtualMachineProperties{
                        HardwareProfile: &compute.HardwareProfile{
@@ -311,11 +312,13 @@ func (az *AzureProvider) Instances(ctx context.Context) ([]Instance, error) {
                        return nil, err
                }
                if result.Value().Tags["arvados-class"] != nil &&
+                       result.Value().Tags["arvados-instance-type"] != nil &&
                        (*result.Value().Tags["arvados-class"]) == "crunch-dynamic-compute" {
                        instances = append(instances, &AzureInstance{
-                               provider: az,
-                               vm:       result.Value(),
-                               nic:      interfaces[*(*result.Value().NetworkProfile.NetworkInterfaces)[0].ID]})
+                               provider:     az,
+                               vm:           result.Value(),
+                               nic:          interfaces[*(*result.Value().NetworkProfile.NetworkInterfaces)[0].ID],
+                               instanceType: az.arvconfig.InstanceTypes[(*result.Value().Tags["arvados-instance-type"])]})
                }
        }
        return instances, nil
@@ -464,10 +467,6 @@ func (ai *AzureInstance) String() string {
        return *ai.vm.Name
 }
 
-func (ai *AzureInstance) ProviderType() string {
-       return string(ai.vm.VirtualMachineProperties.HardwareProfile.VMSize)
-}
-
 func (ai *AzureInstance) InstanceType() arvados.InstanceType {
        return ai.instanceType
 }
index 2791ea6bf29ccd3fc26a78235a78ed009aed1322..bcba51bfdf809880f6ac3576bfea37c3db295f2a 100644 (file)
@@ -61,45 +61,49 @@ func (*InterfacesClientStub) ListComplete(ctx context.Context, resourceGroupName
 
 var live = flag.String("live-azure-cfg", "", "Test with real azure API, provide config file")
 
-func GetProvider() (Provider, ImageID, error) {
+func GetProvider() (Provider, ImageID, arvados.Cluster, error) {
+       cluster := arvados.Cluster{
+               InstanceTypes: arvados.InstanceTypeMap(map[string]arvados.InstanceType{
+                       "tiny": arvados.InstanceType{
+                               Name:         "tiny",
+                               ProviderType: "Standard_D1_v2",
+                               VCPUs:        1,
+                               RAM:          4000000000,
+                               Scratch:      10000000000,
+                               Price:        .02,
+                               Preemptible:  false,
+                       },
+               })}
        if *live != "" {
                cfg := AzureProviderConfig{}
                err := config.LoadFile(&cfg, *live)
                if err != nil {
-                       return nil, ImageID(""), err
+                       return nil, ImageID(""), cluster, err
                }
-               ap, err := NewAzureProvider(cfg, arvados.Cluster{})
-               return ap, ImageID(cfg.Image), err
+               ap, err := NewAzureProvider(cfg, cluster)
+               return ap, ImageID(cfg.Image), cluster, err
        } else {
                ap := AzureProvider{
                        azconfig: AzureProviderConfig{
                                BlobContainer: "vhds",
                        },
+                       arvconfig: cluster,
                }
                ap.vmClient = &VirtualMachinesClientStub{}
                ap.netClient = &InterfacesClientStub{}
-               return &ap, ImageID("blob"), nil
+               return &ap, ImageID("blob"), cluster, nil
        }
 }
 
 func (*AzureProviderSuite) TestCreate(c *check.C) {
-       ap, img, err := GetProvider()
+       ap, img, cluster, err := GetProvider()
        if err != nil {
                c.Fatal("Error making provider", err)
        }
 
        inst, err := ap.Create(context.Background(),
-               arvados.InstanceType{
-                       Name:         "tiny",
-                       ProviderType: "Standard_D1_v2",
-                       VCPUs:        1,
-                       RAM:          4000000000,
-                       Scratch:      10000000000,
-                       Price:        .02,
-                       Preemptible:  false,
-               },
-               img,
-               []InstanceTag{"tag1"})
+               cluster.InstanceTypes["tiny"],
+               img, []InstanceTag{"tag1"})
 
        c.Assert(err, check.IsNil)
 
@@ -107,7 +111,7 @@ func (*AzureProviderSuite) TestCreate(c *check.C) {
 }
 
 func (*AzureProviderSuite) TestListInstances(c *check.C) {
-       ap, _, err := GetProvider()
+       ap, _, _, err := GetProvider()
        if err != nil {
                c.Fatal("Error making provider", err)
        }
@@ -117,12 +121,12 @@ func (*AzureProviderSuite) TestListInstances(c *check.C) {
        c.Assert(err, check.IsNil)
 
        for _, i := range l {
-               log.Printf("%v %v", i.String(), i.Address())
+               log.Printf("%v %v %v", i.String(), i.Address(), i.InstanceType())
        }
 }
 
 func (*AzureProviderSuite) TestManageNics(c *check.C) {
-       ap, _, err := GetProvider()
+       ap, _, _, err := GetProvider()
        if err != nil {
                c.Fatal("Error making provider", err)
        }
@@ -131,7 +135,7 @@ func (*AzureProviderSuite) TestManageNics(c *check.C) {
 }
 
 func (*AzureProviderSuite) TestManageBlobs(c *check.C) {
-       ap, _, err := GetProvider()
+       ap, _, _, err := GetProvider()
        if err != nil {
                c.Fatal("Error making provider", err)
        }
@@ -140,7 +144,7 @@ func (*AzureProviderSuite) TestManageBlobs(c *check.C) {
 }
 
 func (*AzureProviderSuite) TestDestroyInstances(c *check.C) {
-       ap, _, err := GetProvider()
+       ap, _, _, err := GetProvider()
        if err != nil {
                c.Fatal("Error making provider", err)
        }
index e896ac650158660e8135f9402005299d0cee2faa..c5411128afa217ed39cec62bbd905804cb6b1088 100644 (file)
@@ -18,9 +18,8 @@ type ImageID string
 type Instance interface {
        // String typically returns the cloud-provided instance ID.
        String() string
-       // Cloud provider's "instance type" ID. Matches a key in
-       // configured arvados.InstanceTypeMap.
-       ProviderType() string
+       // Configured Arvados instance type
+       InstanceType() arvados.InstanceType
        // Get tags
        GetTags() ([]InstanceTag, error)
        // Replace tags with the given tags