1package azureutil 2 3import ( 4 "fmt" 5 "time" 6 7 "github.com/docker/machine/version" 8 9 "github.com/Azure/azure-sdk-for-go/arm/compute" 10 "github.com/Azure/azure-sdk-for-go/arm/network" 11 "github.com/Azure/azure-sdk-for-go/arm/resources/resources" 12 "github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions" 13 "github.com/Azure/azure-sdk-for-go/arm/storage" 14 "github.com/Azure/go-autorest/autorest" 15) 16 17// TODO(ahmetalpbalkan) Remove duplication around client creation. This is 18// happening because we auto-generate our SDK and we don't have generics in Go. 19// We are hoping to come up with a factory or some defaults instance to set 20// these client configuration in a central place in azure-sdk-for-go. 21 22func oauthClient() autorest.Client { 23 c := autorest.NewClientWithUserAgent(fmt.Sprintf("docker-machine/%s", version.Version)) 24 c.RequestInspector = withInspection() 25 c.ResponseInspector = byInspecting() 26 // TODO set user agent 27 return c 28} 29 30func subscriptionsClient(baseURI string) subscriptions.Client { 31 c := subscriptions.NewClientWithBaseURI(baseURI) // used only for unauthenticated requests for generic subs IDs 32 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 33 c.RequestInspector = withInspection() 34 c.ResponseInspector = byInspecting() 35 c.PollingDelay = time.Second * 5 36 return c 37} 38 39func (a AzureClient) providersClient() resources.ProvidersClient { 40 c := resources.NewProvidersClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 41 c.Authorizer = a.auth 42 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 43 c.RequestInspector = withInspection() 44 c.ResponseInspector = byInspecting() 45 c.PollingDelay = time.Second * 5 46 return c 47} 48 49func (a AzureClient) resourceGroupsClient() resources.GroupsClient { 50 c := resources.NewGroupsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 51 c.Authorizer = a.auth 52 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 53 c.RequestInspector = withInspection() 54 c.ResponseInspector = byInspecting() 55 c.PollingDelay = time.Second * 5 56 return c 57} 58 59func (a AzureClient) securityGroupsClient() network.SecurityGroupsClient { 60 c := network.NewSecurityGroupsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 61 c.Authorizer = a.auth 62 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 63 c.RequestInspector = withInspection() 64 c.ResponseInspector = byInspecting() 65 c.PollingDelay = time.Second * 5 66 return c 67} 68 69func (a AzureClient) virtualNetworksClient() network.VirtualNetworksClient { 70 c := network.NewVirtualNetworksClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 71 c.Authorizer = a.auth 72 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 73 c.RequestInspector = withInspection() 74 c.ResponseInspector = byInspecting() 75 c.PollingDelay = time.Second * 5 76 return c 77} 78 79func (a AzureClient) subnetsClient() network.SubnetsClient { 80 c := network.NewSubnetsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 81 c.Authorizer = a.auth 82 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 83 c.RequestInspector = withInspection() 84 c.ResponseInspector = byInspecting() 85 c.PollingDelay = time.Second * 5 86 return c 87} 88 89func (a AzureClient) networkInterfacesClient() network.InterfacesClient { 90 c := network.NewInterfacesClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 91 c.Authorizer = a.auth 92 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 93 c.RequestInspector = withInspection() 94 c.ResponseInspector = byInspecting() 95 c.PollingDelay = time.Second * 5 96 return c 97} 98 99func (a AzureClient) publicIPAddressClient() network.PublicIPAddressesClient { 100 c := network.NewPublicIPAddressesClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 101 c.Authorizer = a.auth 102 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 103 c.RequestInspector = withInspection() 104 c.ResponseInspector = byInspecting() 105 c.PollingDelay = time.Second * 5 106 return c 107} 108 109func (a AzureClient) storageAccountsClient() storage.AccountsClient { 110 c := storage.NewAccountsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 111 c.Authorizer = a.auth 112 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 113 c.RequestInspector = withInspection() 114 c.ResponseInspector = byInspecting() 115 c.PollingDelay = time.Second * 5 116 return c 117} 118 119func (a AzureClient) virtualMachinesClient() compute.VirtualMachinesClient { 120 c := compute.NewVirtualMachinesClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 121 c.Authorizer = a.auth 122 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 123 c.RequestInspector = withInspection() 124 c.ResponseInspector = byInspecting() 125 c.PollingDelay = time.Second * 5 126 return c 127} 128 129func (a AzureClient) availabilitySetsClient() compute.AvailabilitySetsClient { 130 c := compute.NewAvailabilitySetsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) 131 c.Authorizer = a.auth 132 c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) 133 c.RequestInspector = withInspection() 134 c.ResponseInspector = byInspecting() 135 c.PollingDelay = time.Second * 5 136 return c 137} 138