本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/to.StringPtr函数的典型用法代码示例。如果您正苦于以下问题:Golang StringPtr函数的具体用法?Golang StringPtr怎么用?Golang StringPtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringPtr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: checkName
func checkName(name string) {
c, err := helpers.LoadCredentials()
if err != nil {
log.Fatalf("Error: %v", err)
}
ac := storage.NewAccountsClient(c["subscriptionID"])
spt, err := helpers.NewServicePrincipalTokenFromCredentials(c, azure.AzureResourceManagerScope)
if err != nil {
log.Fatalf("Error: %v", err)
}
ac.Authorizer = spt
ac.Sender = autorest.CreateSender(
autorest.WithLogging(log.New(os.Stdout, "sdk-example: ", log.LstdFlags)))
ac.RequestInspector = withInspection()
ac.ResponseInspector = byInspecting()
cna, err := ac.CheckNameAvailability(
storage.AccountCheckNameAvailabilityParameters{
Name: to.StringPtr(name),
Type: to.StringPtr("Microsoft.Storage/storageAccounts")})
if err != nil {
log.Fatalf("Error: %v", err)
} else {
if to.Bool(cna.NameAvailable) {
fmt.Printf("The name '%s' is available\n", name)
} else {
fmt.Printf("The name '%s' is unavailable because %s\n", name, to.String(cna.Message))
}
}
}
开发者ID:freimer,项目名称:azure-sdk-for-go,代码行数:35,代码来源:check.go
示例2: createAccount
func createAccount(resourceGroup, name string) {
c, err := helpers.LoadCredentials()
if err != nil {
log.Fatalf("Error: %v", err)
}
ac := storage.NewAccountsClient(c["subscriptionID"])
spt, err := helpers.NewServicePrincipalTokenFromCredentials(c, azure.AzureResourceManagerScope)
if err != nil {
log.Fatalf("Error: %v", err)
}
ac.Authorizer = spt
cna, err := ac.CheckNameAvailability(
storage.AccountCheckNameAvailabilityParameters{
Name: to.StringPtr(name),
Type: to.StringPtr("Microsoft.Storage/storageAccounts")})
if err != nil {
log.Fatalf("Error: %v", err)
return
}
if !to.Bool(cna.NameAvailable) {
fmt.Printf("%s is unavailable -- try again\n", name)
return
}
fmt.Printf("%s is available\n\n", name)
ac.Sender = autorest.CreateSender(withWatcher())
ac.PollingMode = autorest.PollUntilAttempts
ac.PollingAttempts = 5
cp := storage.AccountCreateParameters{}
cp.Location = to.StringPtr("westus")
cp.Properties = &storage.AccountPropertiesCreateParameters{AccountType: storage.StandardLRS}
sa, err := ac.Create(resourceGroup, name, cp)
if err != nil {
if sa.Response.StatusCode != http.StatusAccepted {
fmt.Printf("Creation of %s.%s failed with err -- %v\n", resourceGroup, name, err)
return
}
fmt.Printf("Create initiated for %s.%s -- poll %s to check status\n",
resourceGroup,
name,
sa.GetPollingLocation())
return
}
fmt.Printf("Successfully created %s.%s\n\n", resourceGroup, name)
ac.Sender = nil
r, err := ac.Delete(resourceGroup, name)
if err != nil {
fmt.Printf("Delete of %s.%s failed with status %s\n...%v\n", resourceGroup, name, r.Status, err)
return
}
fmt.Printf("Deletion of %s.%s succeeded -- %s\n", resourceGroup, name, r.Status)
}
开发者ID:freimer,项目名称:azure-sdk-for-go,代码行数:59,代码来源:create.go
示例3: makeVirtualMachine
func makeVirtualMachine(name string) compute.VirtualMachine {
return compute.VirtualMachine{
Name: to.StringPtr(name),
Properties: &compute.VirtualMachineProperties{
ProvisioningState: to.StringPtr("Successful"),
},
}
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:instance_test.go
示例4: attachVolume
func (v *azureVolumeSource) attachVolume(
vm *compute.VirtualMachine,
p storage.VolumeAttachmentParams,
) (_ *storage.VolumeAttachment, updated bool, _ error) {
dataDisksRoot := dataDiskVhdRoot(v.env.config.location, v.env.config.storageAccount)
dataDiskName := p.VolumeId
vhdURI := dataDisksRoot + dataDiskName + vhdExtension
var dataDisks []compute.DataDisk
if vm.Properties.StorageProfile.DataDisks != nil {
dataDisks = *vm.Properties.StorageProfile.DataDisks
}
for _, disk := range dataDisks {
if to.String(disk.Name) != p.VolumeId {
continue
}
if to.String(disk.Vhd.URI) != vhdURI {
continue
}
// Disk is already attached.
volumeAttachment := &storage.VolumeAttachment{
p.Volume,
p.Machine,
storage.VolumeAttachmentInfo{
BusAddress: diskBusAddress(to.Int(disk.Lun)),
},
}
return volumeAttachment, false, nil
}
lun, err := nextAvailableLUN(vm)
if err != nil {
return nil, false, errors.Annotate(err, "choosing LUN")
}
dataDisk := compute.DataDisk{
Lun: to.IntPtr(lun),
Name: to.StringPtr(dataDiskName),
Vhd: &compute.VirtualHardDisk{to.StringPtr(vhdURI)},
Caching: compute.ReadWrite,
CreateOption: compute.Attach,
}
dataDisks = append(dataDisks, dataDisk)
vm.Properties.StorageProfile.DataDisks = &dataDisks
volumeAttachment := storage.VolumeAttachment{
p.Volume,
p.Machine,
storage.VolumeAttachmentInfo{
BusAddress: diskBusAddress(lun),
},
}
return &volumeAttachment, true, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:55,代码来源:storage.go
示例5: createStorageAccount
func createStorageAccount(
client storage.AccountsClient,
accountType storage.AccountType,
resourceGroup string,
location string,
tags map[string]string,
accountNameGenerator func() string,
) (string, string, error) {
logger.Debugf("creating storage account (finding available name)")
const maxAttempts = 10
for remaining := maxAttempts; remaining > 0; remaining-- {
accountName := accountNameGenerator()
logger.Debugf("- checking storage account name %q", accountName)
result, err := client.CheckNameAvailability(
storage.AccountCheckNameAvailabilityParameters{
Name: to.StringPtr(accountName),
// Azure is a little inconsistent with when Type is
// required. It's required here.
Type: to.StringPtr("Microsoft.Storage/storageAccounts"),
},
)
if err != nil {
return "", "", errors.Annotate(err, "checking account name availability")
}
if !to.Bool(result.NameAvailable) {
logger.Debugf(
"%q is not available (%v): %v",
accountName, result.Reason, result.Message,
)
continue
}
createParams := storage.AccountCreateParameters{
Location: to.StringPtr(location),
Tags: toTagsPtr(tags),
Properties: &storage.AccountPropertiesCreateParameters{
AccountType: accountType,
},
}
logger.Debugf("- creating %q storage account %q", accountType, accountName)
// TODO(axw) account creation can fail if the account name is
// available, but contains profanity. We should retry a set
// number of times even if creating fails.
if _, err := client.Create(resourceGroup, accountName, createParams); err != nil {
return "", "", errors.Trace(err)
}
logger.Debugf("- listing storage account keys")
listKeysResult, err := client.ListKeys(resourceGroup, accountName)
if err != nil {
return "", "", errors.Annotate(err, "listing storage account keys")
}
return accountName, to.String(listKeysResult.Key1), nil
}
return "", "", errors.New("could not find available storage account name")
}
开发者ID:makyo,项目名称:juju,代码行数:54,代码来源:environ.go
示例6: createVolume
// createVolume updates the provided VirtualMachine's StorageProfile with the
// parameters for creating a new data disk. We don't actually interact with
// the Azure API until after all changes to the VirtualMachine are made.
func (v *azureVolumeSource) createVolume(
vm *compute.VirtualMachine,
p storage.VolumeParams,
) (*storage.Volume, *storage.VolumeAttachment, error) {
lun, err := nextAvailableLUN(vm)
if err != nil {
return nil, nil, errors.Annotate(err, "choosing LUN")
}
dataDisksRoot := dataDiskVhdRoot(v.env.config.location, v.env.config.storageAccount)
dataDiskName := p.Tag.String()
vhdURI := dataDisksRoot + dataDiskName + vhdExtension
sizeInGib := mibToGib(p.Size)
dataDisk := compute.DataDisk{
Lun: to.IntPtr(lun),
DiskSizeGB: to.IntPtr(int(sizeInGib)),
Name: to.StringPtr(dataDiskName),
Vhd: &compute.VirtualHardDisk{to.StringPtr(vhdURI)},
Caching: compute.ReadWrite,
CreateOption: compute.Empty,
}
var dataDisks []compute.DataDisk
if vm.Properties.StorageProfile.DataDisks != nil {
dataDisks = *vm.Properties.StorageProfile.DataDisks
}
dataDisks = append(dataDisks, dataDisk)
vm.Properties.StorageProfile.DataDisks = &dataDisks
// Data disks associate VHDs to machines. In Juju's storage model,
// the VHD is the volume and the disk is the volume attachment.
volume := storage.Volume{
p.Tag,
storage.VolumeInfo{
VolumeId: dataDiskName,
Size: gibToMib(sizeInGib),
// We don't currently support persistent volumes in
// Azure, as it requires removal of "comp=media" when
// deleting VMs, complicating cleanup.
Persistent: true,
},
}
volumeAttachment := storage.VolumeAttachment{
p.Tag,
p.Attachment.Machine,
storage.VolumeAttachmentInfo{
BusAddress: diskBusAddress(lun),
},
}
return &volume, &volumeAttachment, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:56,代码来源:storage.go
示例7: makePublicIPAddress
func makePublicIPAddress(pipName, vmName, ipAddress string) network.PublicIPAddress {
tags := map[string]*string{"juju-machine-name": &vmName}
pip := network.PublicIPAddress{
Name: to.StringPtr(pipName),
Tags: &tags,
Properties: &network.PublicIPAddressPropertiesFormat{},
}
if ipAddress != "" {
pip.Properties.IPAddress = to.StringPtr(ipAddress)
}
return pip
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:instance_test.go
示例8: makeSecurityRule
func makeSecurityRule(name, ipAddress, ports string) network.SecurityRule {
return network.SecurityRule{
Name: to.StringPtr(name),
Properties: &network.SecurityRulePropertiesFormat{
Protocol: network.SecurityRuleProtocolTCP,
DestinationAddressPrefix: to.StringPtr(ipAddress),
DestinationPortRange: to.StringPtr(ports),
Access: network.Allow,
Priority: to.IntPtr(200),
Direction: network.Inbound,
},
}
}
开发者ID:imoapps,项目名称:juju,代码行数:13,代码来源:instance_test.go
示例9: createStorageAccount
func createStorageAccount(
group resources.ResourceGroup,
arm arm.Client) error {
ac := arm.StorageAccounts()
cna, err := ac.CheckNameAvailability(
storage.AccountCheckNameAvailabilityParameters{
Name: group.Name,
Type: to.StringPtr("Microsoft.Storage/storageAccounts")})
if err != nil {
return err
}
if to.Bool(cna.NameAvailable) {
name := *group.Name
props := storage.AccountPropertiesCreateParameters{AccountType: storage.StandardLRS}
_, err = ac.Create(name, name,
storage.AccountCreateParameters{
Location: group.Location,
Properties: &props,
})
if err != nil {
return fmt.Errorf("Failed to create storage account '%s' in location '%s': '%s'\n", name, *group.Location, err.Error())
}
}
return nil
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:33,代码来源:create01.go
示例10: createInternalVirtualNetwork
func createInternalVirtualNetwork(
client network.ManagementClient,
controllerResourceGroup string,
location string,
tags map[string]string,
) (*network.VirtualNetwork, error) {
addressPrefixes := make([]string, 256)
for i := range addressPrefixes {
addressPrefixes[i] = fmt.Sprintf("10.%d.0.0/16", i)
}
virtualNetworkParams := network.VirtualNetwork{
Location: to.StringPtr(location),
Tags: toTagsPtr(tags),
Properties: &network.VirtualNetworkPropertiesFormat{
AddressSpace: &network.AddressSpace{&addressPrefixes},
},
}
logger.Debugf("creating virtual network %q", internalNetworkName)
vnetClient := network.VirtualNetworksClient{client}
vnet, err := vnetClient.CreateOrUpdate(
controllerResourceGroup, internalNetworkName, virtualNetworkParams,
)
if err != nil {
return nil, errors.Annotatef(err, "creating virtual network %q", internalNetworkName)
}
return &vnet, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:27,代码来源:networking.go
示例11: createVirtualMachine
func createVirtualMachine(
group resources.ResourceGroup,
vmName, adminName, adminPassword string,
availSet compute.AvailabilitySet,
networkInterface network.Interface,
arm arm.Client) error {
vmc := arm.VirtualMachines()
netRefs := make([]compute.NetworkInterfaceReference, 1, 1)
netRefs[0] = compute.NetworkInterfaceReference{ID: networkInterface.ID}
groupName := *group.Name
accountName := groupName
vmParams := compute.VirtualMachine{
Location: group.Location,
Properties: &compute.VirtualMachineProperties{
AvailabilitySet: &compute.SubResource{ID: availSet.ID},
HardwareProfile: &compute.HardwareProfile{VMSize: compute.StandardA0},
NetworkProfile: &compute.NetworkProfile{NetworkInterfaces: &netRefs},
StorageProfile: &compute.StorageProfile{
ImageReference: &compute.ImageReference{
Publisher: to.StringPtr("MicrosoftWindowsServer"),
Offer: to.StringPtr("WindowsServer"),
Sku: to.StringPtr("2012-R2-Datacenter"),
Version: to.StringPtr("latest"),
},
OsDisk: &compute.OSDisk{
Name: to.StringPtr("mytestod1"),
CreateOption: compute.FromImage,
Vhd: &compute.VirtualHardDisk{
URI: to.StringPtr("http://" + accountName + ".blob.core.windows.net/vhds/mytestod1.vhd"),
},
},
},
OsProfile: &compute.OSProfile{
AdminUsername: to.StringPtr(adminName),
AdminPassword: to.StringPtr(adminPassword),
ComputerName: to.StringPtr(vmName),
WindowsConfiguration: &compute.WindowsConfiguration{ProvisionVMAgent: to.BoolPtr(true)},
},
},
}
if _, err := vmc.CreateOrUpdate(groupName, vmName, vmParams); err != nil {
return fmt.Errorf("Failed to create virtual machine '%s' in location '%s': '%s'\n", vmName, *group.Location, err.Error())
}
return nil
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:51,代码来源:create01.go
示例12: makeIPConfiguration
func makeIPConfiguration(privateIPAddress string) network.InterfaceIPConfiguration {
ipConfiguration := network.InterfaceIPConfiguration{
Properties: &network.InterfaceIPConfigurationPropertiesFormat{},
}
if privateIPAddress != "" {
ipConfiguration.Properties.PrivateIPAddress = to.StringPtr(privateIPAddress)
}
return ipConfiguration
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:instance_test.go
示例13: initResourceGroup
// initResourceGroup creates and initialises a resource group for this
// environment. The resource group will have a storage account and a
// subnet associated with it (but not necessarily contained within:
// see subnet creation).
func (env *azureEnviron) initResourceGroup() (*config.Config, error) {
location := env.config.location
tags, _ := env.config.ResourceTags()
resourceGroupsClient := resources.GroupsClient{env.resources}
logger.Debugf("creating resource group %q", env.resourceGroup)
_, err := resourceGroupsClient.CreateOrUpdate(env.resourceGroup, resources.Group{
Location: to.StringPtr(location),
Tags: toTagsPtr(tags),
})
if err != nil {
return nil, errors.Annotate(err, "creating resource group")
}
var vnetPtr *network.VirtualNetwork
if env.resourceGroup == env.controllerResourceGroup {
// Create an internal network for all VMs to connect to.
vnetPtr, err = createInternalVirtualNetwork(
env.network, env.controllerResourceGroup, location, tags,
)
if err != nil {
return nil, errors.Annotate(err, "creating virtual network")
}
} else {
// We're creating a hosted environment, so we need to fetch
// the virtual network to create a subnet below.
vnetClient := network.VirtualNetworksClient{env.network}
vnet, err := vnetClient.Get(env.controllerResourceGroup, internalNetworkName)
if err != nil {
return nil, errors.Annotate(err, "getting virtual network")
}
vnetPtr = &vnet
}
_, err = createInternalSubnet(
env.network, env.resourceGroup, env.controllerResourceGroup,
vnetPtr, location, tags,
)
if err != nil {
return nil, errors.Annotate(err, "creating subnet")
}
// Create a storage account for the resource group.
storageAccountsClient := storage.AccountsClient{env.storage}
storageAccountName, storageAccountKey, err := createStorageAccount(
storageAccountsClient, env.config.storageAccountType,
env.resourceGroup, location, tags,
env.provider.config.StorageAccountNameGenerator,
)
if err != nil {
return nil, errors.Annotate(err, "creating storage account")
}
return env.config.Config.Apply(map[string]interface{}{
configAttrStorageAccount: storageAccountName,
configAttrStorageAccountKey: storageAccountKey,
})
}
开发者ID:makyo,项目名称:juju,代码行数:61,代码来源:environ.go
示例14: createVMExtension
// createVMExtension creates a CustomScript VM extension for the given VM
// which will execute the CustomData on the machine as a script.
func createVMExtension(
vmExtensionClient compute.VirtualMachineExtensionsClient,
os jujuos.OSType, resourceGroup, vmName, location string, vmTags map[string]string,
) error {
var commandToExecute, extensionPublisher, extensionType, extensionVersion string
switch os {
case jujuos.Windows:
commandToExecute = windowsExecuteCustomScriptCommand
extensionPublisher = windowsCustomScriptPublisher
extensionType = windowsCustomScriptType
extensionVersion = windowsCustomScriptVersion
case jujuos.CentOS:
commandToExecute = linuxExecuteCustomScriptCommand
extensionPublisher = linuxCustomScriptPublisher
extensionType = linuxCustomScriptType
extensionVersion = linuxCustomScriptVersion
default:
// Ubuntu renders CustomData as cloud-config, and interprets
// it with cloud-init. Windows and CentOS do not use cloud-init
// on Azure.
return errors.NotSupportedf("CustomScript extension for OS %q", os)
}
extensionSettings := map[string]*string{
"commandToExecute": to.StringPtr(commandToExecute),
}
extension := compute.VirtualMachineExtension{
Location: to.StringPtr(location),
Tags: toTagsPtr(vmTags),
Properties: &compute.VirtualMachineExtensionProperties{
Publisher: to.StringPtr(extensionPublisher),
Type: to.StringPtr(extensionType),
TypeHandlerVersion: to.StringPtr(extensionVersion),
AutoUpgradeMinorVersion: to.BoolPtr(true),
Settings: &extensionSettings,
},
}
_, err := vmExtensionClient.CreateOrUpdate(
resourceGroup, vmName, extensionName, extension,
)
return err
}
开发者ID:imoapps,项目名称:juju,代码行数:45,代码来源:vmextension.go
示例15: makeNetworkInterface
func makeNetworkInterface(nicName, vmName string, ipConfigurations ...network.InterfaceIPConfiguration) network.Interface {
tags := map[string]*string{"juju-machine-name": &vmName}
return network.Interface{
Name: to.StringPtr(nicName),
Tags: &tags,
Properties: &network.InterfacePropertiesFormat{
IPConfigurations: &ipConfigurations,
},
}
}
开发者ID:imoapps,项目名称:juju,代码行数:10,代码来源:instance_test.go
示例16: main
func main() {
name := "storage-account-name"
c, err := helpers.LoadCredentials()
if err != nil {
log.Fatalf("Error: %v", err)
}
sid := c["subscriptionID"]
tid := c["tenantID"]
cid := c["clientID"]
secret := c["clientSecret"]
spt, err := azure.NewServicePrincipalToken(cid, secret, tid, azure.AzureResourceManagerScope)
if err != nil {
log.Fatalf("Error: %v", err)
}
arm := arm.NewClient(sid, spt)
arm.RequestInspector = helpers.WithInspection()
arm.ResponseInspector = helpers.ByInspecting()
ac := arm.StorageAccounts()
cna, err := ac.CheckNameAvailability(
storage.AccountCheckNameAvailabilityParameters{
Name: to.StringPtr(name),
Type: to.StringPtr("Microsoft.Storage/storageAccounts")})
if err != nil {
log.Fatalf("Error: %v", err)
} else {
if to.Bool(cna.NameAvailable) {
fmt.Printf("The name '%s' is available\n", name)
} else {
fmt.Printf("The name '%s' is unavailable because %s\n", name, to.String(cna.Message))
}
}
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:40,代码来源:check.go
示例17: createNetworkInterface
func createNetworkInterface(
suffix string,
group resources.ResourceGroup,
subnet network.Subnet,
arm arm.Client) (networkInterface network.Interface, err error) {
pipc := arm.PublicIPAddresses()
nicc := arm.NetworkInterfaces()
groupName := *group.Name
ipName := "ip" + suffix
nicName := "nic" + suffix
pipResult, err := pipc.CreateOrUpdate(
groupName,
ipName,
network.PublicIPAddress{
Location: group.Location,
Properties: &network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: network.Dynamic,
},
})
if err != nil {
err = fmt.Errorf("Failed to create public ip address '%s' in location '%s': '%s'\n", ipName, *group.Location, err.Error())
return
}
nicProps := network.InterfaceIPConfigurationPropertiesFormat{
PublicIPAddress: &pipResult,
Subnet: &subnet}
ipConfigs := make([]network.InterfaceIPConfiguration, 1, 1)
ipConfigs[0] = network.InterfaceIPConfiguration{
Name: to.StringPtr(nicName + "Config"),
Properties: &nicProps,
}
props := network.InterfacePropertiesFormat{IPConfigurations: &ipConfigs}
networkInterface, err = nicc.CreateOrUpdate(
groupName,
nicName,
network.Interface{
Location: group.Location,
Properties: &props,
})
if err != nil {
err = fmt.Errorf("Failed to create network interface '%s' in location '%s': '%s'\n", nicName, *group.Location, err.Error())
}
return
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:52,代码来源:create01.go
示例18: initResourceGroup
// initResourceGroup creates and initialises a resource group for this
// environment. The resource group will have a storage account and a
// subnet associated with it (but not necessarily contained within:
// see subnet creation).
func (env *azureEnviron) initResourceGroup() (*config.Config, error) {
location := env.config.location
tags := tags.ResourceTags(
names.NewModelTag(env.config.Config.UUID()),
names.NewModelTag(env.config.Config.ControllerUUID()),
env.config,
)
resourceGroupsClient := resources.GroupsClient{env.resources}
logger.Debugf("creating resource group %q", env.resourceGroup)
_, err := resourceGroupsClient.CreateOrUpdate(env.resourceGroup, resources.Group{
Location: to.StringPtr(location),
Tags: toTagsPtr(tags),
})
if err != nil {
return nil, errors.Annotate(err, "creating resource group")
}
// Create an internal network for all VMs in the
// resource group to connect to.
vnetPtr, err := createInternalVirtualNetwork(
env.network, env.resourceGroup, location, tags,
)
if err != nil {
return nil, errors.Annotate(err, "creating virtual network")
}
_, err = createInternalSubnet(
env.network, env.resourceGroup, vnetPtr, location, tags,
)
if err != nil {
return nil, errors.Annotate(err, "creating subnet")
}
// Create a storage account for the resource group.
storageAccountsClient := storage.AccountsClient{env.storage}
storageAccountName, storageAccountKey, err := createStorageAccount(
storageAccountsClient, env.config.storageAccountType,
env.resourceGroup, location, tags,
env.provider.config.StorageAccountNameGenerator,
)
if err != nil {
return nil, errors.Annotate(err, "creating storage account")
}
return env.config.Config.Apply(map[string]interface{}{
configAttrStorageAccount: storageAccountName,
configAttrStorageAccountKey: storageAccountKey,
})
}
开发者ID:xushiwei,项目名称:juju,代码行数:53,代码来源:environ.go
示例19: assertStartInstanceRequests
func (s *environSuite) assertStartInstanceRequests(c *gc.C) startInstanceRequests {
// Clear the fields that don't get sent in the request.
s.publicIPAddress.ID = nil
s.publicIPAddress.Name = nil
s.publicIPAddress.Properties.IPAddress = nil
s.newNetworkInterface.ID = nil
s.newNetworkInterface.Name = nil
(*s.newNetworkInterface.Properties.IPConfigurations)[0].ID = nil
s.jujuAvailabilitySet.ID = nil
s.jujuAvailabilitySet.Name = nil
s.virtualMachine.ID = nil
s.virtualMachine.Name = nil
s.virtualMachine.Properties.ProvisioningState = nil
// Validate HTTP request bodies.
c.Assert(s.requests, gc.HasLen, 8)
c.Assert(s.requests[0].Method, gc.Equals, "GET") // vmSizes
c.Assert(s.requests[1].Method, gc.Equals, "GET") // juju-testenv-model-deadbeef-0bad-400d-8000-4b1d0d06f00d
c.Assert(s.requests[2].Method, gc.Equals, "GET") // skus
c.Assert(s.requests[3].Method, gc.Equals, "PUT")
assertRequestBody(c, s.requests[3], s.publicIPAddress)
c.Assert(s.requests[4].Method, gc.Equals, "GET") // NICs
c.Assert(s.requests[5].Method, gc.Equals, "PUT")
assertRequestBody(c, s.requests[5], s.newNetworkInterface)
c.Assert(s.requests[6].Method, gc.Equals, "PUT")
assertRequestBody(c, s.requests[6], s.jujuAvailabilitySet)
c.Assert(s.requests[7].Method, gc.Equals, "PUT")
// CustomData is non-deterministic, so don't compare it.
// TODO(axw) shouldn't CustomData be deterministic? Look into this.
var virtualMachine compute.VirtualMachine
unmarshalRequestBody(c, s.requests[7], &virtualMachine)
c.Assert(to.String(virtualMachine.Properties.OsProfile.CustomData), gc.Not(gc.HasLen), 0)
virtualMachine.Properties.OsProfile.CustomData = to.StringPtr("<juju-goes-here>")
c.Assert(&virtualMachine, jc.DeepEquals, s.virtualMachine)
return startInstanceRequests{
vmSizes: s.requests[0],
subnet: s.requests[1],
skus: s.requests[2],
publicIPAddress: s.requests[3],
nics: s.requests[4],
networkInterface: s.requests[5],
availabilitySet: s.requests[6],
virtualMachine: s.requests[7],
}
}
开发者ID:makyo,项目名称:juju,代码行数:47,代码来源:environ_test.go
示例20: newOSProfile
func newOSProfile(vmName string, instanceConfig *instancecfg.InstanceConfig) (*compute.OSProfile, os.OSType, error) {
logger.Debugf("creating OS profile for %q", vmName)
customData, err := providerinit.ComposeUserData(instanceConfig, nil, AzureRenderer{})
if err != nil {
return nil, os.Unknown, errors.Annotate(err, "composing user data")
}
osProfile := &compute.OSProfile{
ComputerName: to.StringPtr(vmName),
CustomData: to.StringPtr(string(customData)),
}
seriesOS, err := jujuseries.GetOSFromSeries(instanceConfig.Series)
if err != nil {
return nil, os.Unknown, errors.Trace(err)
}
switch seriesOS {
case os.Ubuntu, os.CentOS, os.Arch:
// SSH keys are handled by custom data, but must also be
// specified in order to forego providing a password, and
// disable password authentication.
publicKeys := []compute.SSHPublicKey{{
Path: to.StringPtr("/home/ubuntu/.ssh/authorized_keys"),
KeyData: to.StringPtr(instanceConfig.AuthorizedKeys),
}}
osProfile.AdminUsername = to.StringPtr("ubuntu")
osProfile.LinuxConfiguration = &compute.LinuxConfiguration{
DisablePasswordAuthentication: to.BoolPtr(true),
SSH: &compute.SSHConfiguration{PublicKeys: &publicKeys},
}
case os.Windows:
osProfile.AdminUsername = to.StringPtr("JujuAdministrator")
// A password is required by Azure, but we will never use it.
// We generate something sufficiently long and random that it
// should be infeasible to guess.
osProfile.AdminPassword = to.StringPtr(randomAdminPassword())
osProfile.WindowsConfiguration = &compute.WindowsConfiguration{
ProvisionVMAgent: to.BoolPtr(true),
EnableAutomaticUpdates: to.BoolPtr(true),
// TODO(?) add WinRM configuration here.
}
default:
return nil, os.Unknown, errors.NotSupportedf("%s", seriesOS)
}
return osProfile, seriesOS, nil
}
开发者ID:makyo,项目名称:juju,代码行数:47,代码来源:environ.go
注:本文中的github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/to.StringPtr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论