本文整理匯總了Golang中github.com/Azure/go-autorest/autorest/to.StringPtr函數的典型用法代碼示例。如果您正苦於以下問題:Golang StringPtr函數的具體用法?Golang StringPtr怎麽用?Golang StringPtr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了StringPtr函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getTestSecurityGroup
func getTestSecurityGroup(services ...v1.Service) network.SecurityGroup {
rules := []network.SecurityRule{}
for _, service := range services {
for _, port := range service.Spec.Ports {
ruleName := getRuleName(&service, port)
sources := getServiceSourceRanges(&service)
for _, src := range sources {
rules = append(rules, network.SecurityRule{
Name: to.StringPtr(ruleName),
Properties: &network.SecurityRulePropertiesFormat{
SourceAddressPrefix: to.StringPtr(src),
DestinationPortRange: to.StringPtr(fmt.Sprintf("%d", port.Port)),
},
})
}
}
}
sg := network.SecurityGroup{
Properties: &network.SecurityGroupPropertiesFormat{
SecurityRules: &rules,
},
}
return sg
}
示例2: vmExtensionProperties
// vmExtension creates a CustomScript VM extension for the given VM
// which will execute the CustomData on the machine as a script.
func vmExtensionProperties(os jujuos.OSType) (*compute.VirtualMachineExtensionProperties, 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 nil, errors.NotSupportedf("CustomScript extension for OS %q", os)
}
extensionSettings := map[string]interface{}{
"commandToExecute": commandToExecute,
}
return &compute.VirtualMachineExtensionProperties{
Publisher: to.StringPtr(extensionPublisher),
Type: to.StringPtr(extensionType),
TypeHandlerVersion: to.StringPtr(extensionVersion),
AutoUpgradeMinorVersion: to.BoolPtr(true),
Settings: &extensionSettings,
}, nil
}
示例3: TestDestroyController
func (s *environSuite) TestDestroyController(c *gc.C) {
groups := []resources.ResourceGroup{{
Name: to.StringPtr("group1"),
}, {
Name: to.StringPtr("group2"),
}}
result := resources.ResourceGroupListResult{Value: &groups}
env := s.openEnviron(c)
s.sender = azuretesting.Senders{
s.makeSender(".*/resourcegroups", result), // GET
s.makeSender(".*/resourcegroups/group[12]", nil), // DELETE
s.makeSender(".*/resourcegroups/group[12]", nil), // DELETE
}
err := env.DestroyController(s.controllerUUID)
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.requests, gc.HasLen, 3)
c.Assert(s.requests[0].Method, gc.Equals, "GET")
c.Assert(s.requests[0].URL.Query().Get("$filter"), gc.Equals, fmt.Sprintf(
"tagname eq 'juju-controller-uuid' and tagvalue eq '%s'",
testing.ControllerTag.Id(),
))
c.Assert(s.requests[1].Method, gc.Equals, "DELETE")
c.Assert(s.requests[2].Method, gc.Equals, "DELETE")
// Groups are deleted concurrently, so there's no known order.
groupsDeleted := []string{
path.Base(s.requests[1].URL.Path),
path.Base(s.requests[2].URL.Path),
}
c.Assert(groupsDeleted, jc.SameContents, []string{"group1", "group2"})
}
示例4: CreatePublicIPAddress
func (a AzureClient) CreatePublicIPAddress(ctx *DeploymentContext, resourceGroup, name, location string, isStatic bool, dnsLabel string) error {
log.Info("Creating public IP address.", logutil.Fields{
"name": name,
"static": isStatic})
var ipType network.IPAllocationMethod
if isStatic {
ipType = network.Static
} else {
ipType = network.Dynamic
}
var dns *network.PublicIPAddressDNSSettings
if dnsLabel != "" {
dns = &network.PublicIPAddressDNSSettings{
DomainNameLabel: to.StringPtr(dnsLabel),
}
}
_, err := a.publicIPAddressClient().CreateOrUpdate(resourceGroup, name,
network.PublicIPAddress{
Location: to.StringPtr(location),
Properties: &network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: ipType,
DNSSettings: dns,
},
}, nil)
if err != nil {
return err
}
ip, err := a.publicIPAddressClient().Get(resourceGroup, name, "")
ctx.PublicIPAddressID = to.String(ip.ID)
return err
}
示例5: getTestLoadBalancer
func getTestLoadBalancer(services ...api.Service) network.LoadBalancer {
rules := []network.LoadBalancingRule{}
probes := []network.Probe{}
for _, service := range services {
for _, port := range service.Spec.Ports {
ruleName := getRuleName(&service, port)
rules = append(rules, network.LoadBalancingRule{
Name: to.StringPtr(ruleName),
Properties: &network.LoadBalancingRulePropertiesFormat{
FrontendPort: to.Int32Ptr(port.Port),
BackendPort: to.Int32Ptr(port.Port),
},
})
probes = append(probes, network.Probe{
Name: to.StringPtr(ruleName),
Properties: &network.ProbePropertiesFormat{
Port: to.Int32Ptr(port.NodePort),
},
})
}
}
lb := network.LoadBalancer{
Properties: &network.LoadBalancerPropertiesFormat{
LoadBalancingRules: &rules,
Probes: &probes,
},
}
return lb
}
示例6: TestStartInstanceCentOS
func (s *environSuite) TestStartInstanceCentOS(c *gc.C) {
// Starting a CentOS VM, we should not expect an image query.
s.PatchValue(&s.ubuntuServerSKUs, nil)
env := s.openEnviron(c)
s.sender = s.startInstanceSenders(false)
s.requests = nil
args := makeStartInstanceParams(c, s.controllerUUID, "centos7")
_, err := env.StartInstance(args)
c.Assert(err, jc.ErrorIsNil)
vmExtensionSettings := map[string]interface{}{
"commandToExecute": `bash -c 'base64 -d /var/lib/waagent/CustomData | bash'`,
}
s.assertStartInstanceRequests(c, s.requests, assertStartInstanceRequestsParams{
imageReference: ¢os7ImageReference,
diskSizeGB: 32,
vmExtension: &compute.VirtualMachineExtensionProperties{
Publisher: to.StringPtr("Microsoft.OSTCExtensions"),
Type: to.StringPtr("CustomScriptForLinux"),
TypeHandlerVersion: to.StringPtr("1.4"),
AutoUpgradeMinorVersion: to.BoolPtr(true),
Settings: &vmExtensionSettings,
},
osProfile: &linuxOsProfile,
})
}
示例7: 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.PublicCloud.ResourceManagerEndpoint)
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))
}
}
}
示例8: deviceCodeSender
func deviceCodeSender() autorest.Sender {
return azuretesting.NewSenderWithValue(azure.DeviceCode{
DeviceCode: to.StringPtr("device-code"),
Interval: to.Int64Ptr(1), // 1 second between polls
Message: to.StringPtr("open your browser, etc."),
})
}
示例9: BuildWindows
func (s *TemplateBuilder) BuildWindows(keyVaultName, winRMCertificateUrl string) error {
resource, err := s.getResourceByType(resourceVirtualMachine)
if err != nil {
return err
}
profile := resource.Properties.OsProfile
profile.Secrets = &[]compute.VaultSecretGroup{
{
SourceVault: &compute.SubResource{
ID: to.StringPtr(s.toResourceID(resourceKeyVaults, keyVaultName)),
},
VaultCertificates: &[]compute.VaultCertificate{
{
CertificateStore: to.StringPtr("My"),
CertificateURL: to.StringPtr(winRMCertificateUrl),
},
},
},
}
profile.WindowsConfiguration = &compute.WindowsConfiguration{
ProvisionVMAgent: to.BoolPtr(true),
WinRM: &compute.WinRMConfiguration{
Listeners: &[]compute.WinRMListener{
{
Protocol: "https",
CertificateURL: to.StringPtr(winRMCertificateUrl),
},
},
},
}
return nil
}
示例10: ensurePublicIPExists
func (az *Cloud) ensurePublicIPExists(serviceName, pipName string) (*network.PublicIPAddress, error) {
pip, existsPip, err := az.getPublicIPAddress(pipName)
if err != nil {
return nil, err
}
if existsPip {
return &pip, nil
}
pip.Name = to.StringPtr(pipName)
pip.Location = to.StringPtr(az.Location)
pip.Properties = &network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: network.Static,
}
pip.Tags = &map[string]*string{"service": &serviceName}
glog.V(3).Infof("ensure(%s): pip(%s) - creating", serviceName, *pip.Name)
_, err = az.PublicIPAddressesClient.CreateOrUpdate(az.ResourceGroup, *pip.Name, pip, nil)
if err != nil {
return nil, err
}
pip, err = az.PublicIPAddressesClient.Get(az.ResourceGroup, *pip.Name, "")
if err != nil {
return nil, err
}
return &pip, nil
}
示例11: 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)
}
示例12: makeVirtualMachine
func makeVirtualMachine(name string) compute.VirtualMachine {
return compute.VirtualMachine{
Name: to.StringPtr(name),
Properties: &compute.VirtualMachineProperties{
ProvisioningState: to.StringPtr("Succeeded"),
},
}
}
示例13: roleDefinitionListSender
func roleDefinitionListSender() autorest.Sender {
roleDefinitions := []authorization.RoleDefinition{{
ID: to.StringPtr("owner-role-id"),
Name: to.StringPtr("Owner"),
}}
return azuretesting.NewSenderWithValue(authorization.RoleDefinitionListResult{
Value: &roleDefinitions,
})
}
示例14: main
func main() {
resourceGroup := "resourceGroupName"
name := "gosdktestname01"
c := map[string]string{
"AZURE_CLIENT_ID": os.Getenv("AZURE_CLIENT_ID"),
"AZURE_CLIENT_SECRET": os.Getenv("AZURE_CLIENT_SECRET"),
"AZURE_SUBSCRIPTION_ID": os.Getenv("AZURE_SUBSCRIPTION_ID"),
"AZURE_TENANT_ID": os.Getenv("AZURE_TENANT_ID")}
if err := checkEnvVar(&c); err != nil {
log.Fatalf("Error: %v", err)
return
}
spt, err := helpers.NewServicePrincipalTokenFromCredentials(c, azure.PublicCloud.ResourceManagerEndpoint)
if err != nil {
log.Fatalf("Error: %v", err)
return
}
ac := storage.NewAccountsClient(c["AZURE_SUBSCRIPTION_ID"])
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 with another name\n", name)
return
}
fmt.Printf("%s is available\n\n", name)
cp := storage.AccountCreateParameters{
Sku: &storage.Sku{
Name: storage.StandardLRS,
Tier: storage.Standard},
Location: to.StringPtr("westus")}
cancel := make(chan struct{})
if _, err = ac.Create(resourceGroup, name, cp, cancel); err != nil {
fmt.Printf("Create '%s' storage account failed: %v\n", name, err)
return
}
fmt.Printf("Successfully created '%s' storage account in '%s' resource group\n\n", name, resourceGroup)
r, err := ac.Delete(resourceGroup, name)
if err != nil {
fmt.Printf("Delete of '%s' failed with status %s\n...%v\n", name, r.Status, err)
return
}
fmt.Printf("Deletion of '%s' storage account in '%s' resource group succeeded -- %s\n", name, resourceGroup, r.Status)
}
示例15: 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,
storageAccount *armstorage.Account,
) (*storage.Volume, *storage.VolumeAttachment, error) {
lun, err := nextAvailableLUN(vm)
if err != nil {
return nil, nil, errors.Annotate(err, "choosing LUN")
}
dataDisksRoot := dataDiskVhdRoot(storageAccount)
dataDiskName := p.Tag.String()
vhdURI := dataDisksRoot + dataDiskName + vhdExtension
sizeInGib := mibToGib(p.Size)
dataDisk := compute.DataDisk{
Lun: to.Int32Ptr(lun),
DiskSizeGB: to.Int32Ptr(int32(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
}