...

Source file src/github.com/Azure/azure-sdk-for-go/services/classic/management/vmutils/extensions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/classic/management/vmutils

     1  // +build go1.7
     2  
     3  package vmutils
     4  
     5  // Copyright (c) Microsoft Corporation. All rights reserved.
     6  // Licensed under the MIT License. See License.txt in the project root for license information.
     7  
     8  import (
     9  	"encoding/base64"
    10  	"encoding/json"
    11  	"fmt"
    12  
    13  	vm "github.com/Azure/azure-sdk-for-go/services/classic/management/virtualmachine"
    14  )
    15  
    16  const (
    17  	dockerPublicConfigVersion = 2
    18  )
    19  
    20  func AddAzureVMExtensionConfiguration(role *vm.Role, name, publisher, version, referenceName, state string,
    21  	publicConfigurationValue, privateConfigurationValue []byte) error {
    22  	if role == nil {
    23  		return fmt.Errorf(errParamNotSpecified, "role")
    24  	}
    25  
    26  	extension := vm.ResourceExtensionReference{
    27  		Name:          name,
    28  		Publisher:     publisher,
    29  		Version:       version,
    30  		ReferenceName: referenceName,
    31  		State:         state,
    32  	}
    33  
    34  	if len(privateConfigurationValue) != 0 {
    35  		extension.ParameterValues = append(extension.ParameterValues, vm.ResourceExtensionParameter{
    36  			Key:   "ignored",
    37  			Value: base64.StdEncoding.EncodeToString(privateConfigurationValue),
    38  			Type:  "Private",
    39  		})
    40  	}
    41  
    42  	if len(publicConfigurationValue) != 0 {
    43  		extension.ParameterValues = append(extension.ParameterValues, vm.ResourceExtensionParameter{
    44  			Key:   "ignored",
    45  			Value: base64.StdEncoding.EncodeToString(publicConfigurationValue),
    46  			Type:  "Public",
    47  		})
    48  	}
    49  
    50  	if role.ResourceExtensionReferences == nil {
    51  		role.ResourceExtensionReferences = &[]vm.ResourceExtensionReference{}
    52  	}
    53  	extensionList := append(*role.ResourceExtensionReferences, extension)
    54  	role.ResourceExtensionReferences = &extensionList
    55  	return nil
    56  }
    57  
    58  // AddAzureDockerVMExtensionConfiguration adds the DockerExtension to the role
    59  // configuratioon and opens a port "dockerPort"
    60  // TODO(ahmetalpbalkan) Deprecate this and move to 'docker-machine' codebase.
    61  func AddAzureDockerVMExtensionConfiguration(role *vm.Role, dockerPort int, version string) error {
    62  	if role == nil {
    63  		return fmt.Errorf(errParamNotSpecified, "role")
    64  	}
    65  
    66  	if err := ConfigureWithExternalPort(role, "docker", dockerPort, dockerPort, vm.InputEndpointProtocolTCP); err != nil {
    67  		return err
    68  	}
    69  
    70  	publicConfiguration, err := createDockerPublicConfig(dockerPort)
    71  	if err != nil {
    72  		return err
    73  	}
    74  
    75  	privateConfiguration, err := json.Marshal(dockerPrivateConfig{})
    76  	if err != nil {
    77  		return err
    78  	}
    79  
    80  	return AddAzureVMExtensionConfiguration(role,
    81  		"DockerExtension", "MSOpenTech.Extensions",
    82  		version, "DockerExtension", "enable",
    83  		publicConfiguration, privateConfiguration)
    84  }
    85  
    86  func createDockerPublicConfig(dockerPort int) ([]byte, error) {
    87  	return json.Marshal(dockerPublicConfig{DockerPort: dockerPort, Version: dockerPublicConfigVersion})
    88  }
    89  
    90  type dockerPublicConfig struct {
    91  	DockerPort int `json:"dockerport"`
    92  	Version    int `json:"version"`
    93  }
    94  
    95  type dockerPrivateConfig struct{}
    96  

View as plain text