~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/azure/vmextension.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "github.com/Azure/azure-sdk-for-go/arm/compute"
8
 
        "github.com/Azure/go-autorest/autorest"
9
8
        "github.com/Azure/go-autorest/autorest/to"
10
9
        "github.com/juju/errors"
11
10
        jujuos "github.com/juju/utils/os"
32
31
        linuxCustomScriptVersion        = "1.4"
33
32
)
34
33
 
35
 
// createVMExtension creates a CustomScript VM extension for the given VM
 
34
// vmExtension creates a CustomScript VM extension for the given VM
36
35
// which will execute the CustomData on the machine as a script.
37
 
func createVMExtension(
38
 
        callAPI callAPIFunc,
39
 
        vmExtensionClient compute.VirtualMachineExtensionsClient,
40
 
        os jujuos.OSType, resourceGroup, vmName, location string, vmTags map[string]string,
41
 
) error {
 
36
func vmExtensionProperties(os jujuos.OSType) (*compute.VirtualMachineExtensionProperties, error) {
42
37
        var commandToExecute, extensionPublisher, extensionType, extensionVersion string
43
38
 
44
39
        switch os {
56
51
                // Ubuntu renders CustomData as cloud-config, and interprets
57
52
                // it with cloud-init. Windows and CentOS do not use cloud-init
58
53
                // on Azure.
59
 
                return errors.NotSupportedf("CustomScript extension for OS %q", os)
 
54
                return nil, errors.NotSupportedf("CustomScript extension for OS %q", os)
60
55
        }
61
56
 
62
57
        extensionSettings := map[string]interface{}{
63
58
                "commandToExecute": commandToExecute,
64
59
        }
65
 
        extension := compute.VirtualMachineExtension{
66
 
                Location: to.StringPtr(location),
67
 
                Tags:     to.StringMapPtr(vmTags),
68
 
                Properties: &compute.VirtualMachineExtensionProperties{
69
 
                        Publisher:               to.StringPtr(extensionPublisher),
70
 
                        Type:                    to.StringPtr(extensionType),
71
 
                        TypeHandlerVersion:      to.StringPtr(extensionVersion),
72
 
                        AutoUpgradeMinorVersion: to.BoolPtr(true),
73
 
                        Settings:                &extensionSettings,
74
 
                },
75
 
        }
76
 
        err := callAPI(func() (autorest.Response, error) {
77
 
                return vmExtensionClient.CreateOrUpdate(
78
 
                        resourceGroup, vmName, extensionName, extension,
79
 
                        nil, // abort channel
80
 
                )
81
 
        })
82
 
        return err
 
60
        return &compute.VirtualMachineExtensionProperties{
 
61
                Publisher:               to.StringPtr(extensionPublisher),
 
62
                Type:                    to.StringPtr(extensionType),
 
63
                TypeHandlerVersion:      to.StringPtr(extensionVersion),
 
64
                AutoUpgradeMinorVersion: to.BoolPtr(true),
 
65
                Settings:                &extensionSettings,
 
66
        }, nil
83
67
}