本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
}
}
示例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)
}
示例3: makeVirtualMachine
func makeVirtualMachine(name string) compute.VirtualMachine {
return compute.VirtualMachine{
Name: to.StringPtr(name),
Properties: &compute.VirtualMachineProperties{
ProvisioningState: to.StringPtr("Successful"),
},
}
}
示例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
}
示例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")
}
示例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
}
示例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
}
示例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,
},
}
}
示例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
}
示例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
}
示例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
}
示例12: makeIPConfiguration
func makeIPConfiguration(privateIPAddress string) network.InterfaceIPConfiguration {
ipConfiguration := network.InterfaceIPConfiguration{
Properties: &network.InterfaceIPConfigurationPropertiesFormat{},
}
if privateIPAddress != "" {
ipConfiguration.Properties.PrivateIPAddress = to.StringPtr(privateIPAddress)
}
return ipConfiguration
}
示例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,
})
}
示例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
}
示例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,
},
}
}