本文整理汇总了Golang中github.com/Azure/go-autorest/autorest/to.BoolPtr函数的典型用法代码示例。如果您正苦于以下问题:Golang BoolPtr函数的具体用法?Golang BoolPtr怎么用?Golang BoolPtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BoolPtr函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newOSProfile
func newOSProfile(
vmName string,
instanceConfig *instancecfg.InstanceConfig,
randomAdminPassword func() string,
) (*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:
// 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
}
示例2: toVirtualMachineCaptureParameters
func (c *Config) toVirtualMachineCaptureParameters() *compute.VirtualMachineCaptureParameters {
return &compute.VirtualMachineCaptureParameters{
DestinationContainerName: &c.CaptureContainerName,
VhdPrefix: &c.CaptureNamePrefix,
OverwriteVhds: to.BoolPtr(false),
}
}
示例3: 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,
})
}
示例4: 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
}
示例5: 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
}
示例6: testStartInstanceWindows
func (s *environSuite) testStartInstanceWindows(
c *gc.C, cons constraints.Value,
expect uint64, requestValue int,
) {
// Starting a Windows 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, "win2012")
args.Constraints = cons
result, err := env.StartInstance(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.NotNil)
c.Assert(result.Hardware.RootDisk, jc.DeepEquals, &expect)
vmExtensionSettings := map[string]interface{}{
"commandToExecute": `` +
`move C:\AzureData\CustomData.bin C:\AzureData\CustomData.ps1 && ` +
`powershell.exe -ExecutionPolicy Unrestricted -File C:\AzureData\CustomData.ps1 && ` +
`del /q C:\AzureData\CustomData.ps1`,
}
s.assertStartInstanceRequests(c, s.requests, assertStartInstanceRequestsParams{
imageReference: &win2012ImageReference,
diskSizeGB: requestValue,
vmExtension: &compute.VirtualMachineExtensionProperties{
Publisher: to.StringPtr("Microsoft.Compute"),
Type: to.StringPtr("CustomScriptExtension"),
TypeHandlerVersion: to.StringPtr("1.4"),
AutoUpgradeMinorVersion: to.BoolPtr(true),
Settings: &vmExtensionSettings,
},
osProfile: &windowsOsProfile,
})
}
示例7: reconcileLoadBalancer
//.........这里部分代码省略.........
Protocol: network.ProbeProtocolHTTP,
Port: to.Int32Ptr(podPresencePort),
IntervalInSeconds: to.Int32Ptr(5),
NumberOfProbes: to.Int32Ptr(2),
},
}
} else {
expectedProbes[i] = network.Probe{
Name: &lbRuleName,
Properties: &network.ProbePropertiesFormat{
Protocol: probeProto,
Port: to.Int32Ptr(port.NodePort),
IntervalInSeconds: to.Int32Ptr(5),
NumberOfProbes: to.Int32Ptr(2),
},
}
}
expectedRules[i] = network.LoadBalancingRule{
Name: &lbRuleName,
Properties: &network.LoadBalancingRulePropertiesFormat{
Protocol: transportProto,
FrontendIPConfiguration: &network.SubResource{
ID: to.StringPtr(lbFrontendIPConfigID),
},
BackendAddressPool: &network.SubResource{
ID: to.StringPtr(lbBackendPoolID),
},
Probe: &network.SubResource{
ID: to.StringPtr(az.getLoadBalancerProbeID(lbName, lbRuleName)),
},
FrontendPort: to.Int32Ptr(port.Port),
BackendPort: to.Int32Ptr(port.Port),
EnableFloatingIP: to.BoolPtr(true),
},
}
}
// remove unwanted probes
dirtyProbes := false
var updatedProbes []network.Probe
if lb.Properties.Probes != nil {
updatedProbes = *lb.Properties.Probes
}
for i := len(updatedProbes) - 1; i >= 0; i-- {
existingProbe := updatedProbes[i]
if serviceOwnsRule(service, *existingProbe.Name) {
glog.V(10).Infof("reconcile(%s)(%t): lb probe(%s) - considering evicting", serviceName, wantLb, *existingProbe.Name)
keepProbe := false
if findProbe(expectedProbes, existingProbe) {
glog.V(10).Infof("reconcile(%s)(%t): lb probe(%s) - keeping", serviceName, wantLb, *existingProbe.Name)
keepProbe = true
}
if !keepProbe {
updatedProbes = append(updatedProbes[:i], updatedProbes[i+1:]...)
glog.V(10).Infof("reconcile(%s)(%t): lb probe(%s) - dropping", serviceName, wantLb, *existingProbe.Name)
dirtyProbes = true
}
}
}
// add missing, wanted probes
for _, expectedProbe := range expectedProbes {
foundProbe := false
if findProbe(updatedProbes, expectedProbe) {
glog.V(10).Infof("reconcile(%s)(%t): lb probe(%s) - already exists", serviceName, wantLb, *expectedProbe.Name)
foundProbe = true
示例8: CreateVirtualMachine
func (a AzureClient) CreateVirtualMachine(resourceGroup, name, location, size, availabilitySetID, networkInterfaceID,
username, sshPublicKey, imageName string, storageAccount *storage.AccountProperties) error {
log.Info("Creating virtual machine.", logutil.Fields{
"name": name,
"location": location,
"size": size,
"username": username,
"osImage": imageName,
})
img, err := parseImageName(imageName)
if err != nil {
return err
}
var (
osDiskBlobURL = osDiskStorageBlobURL(storageAccount, name)
sshKeyPath = fmt.Sprintf("/home/%s/.ssh/authorized_keys", username)
)
log.Debugf("OS disk blob will be placed at: %s", osDiskBlobURL)
log.Debugf("SSH key will be placed at: %s", sshKeyPath)
_, err = a.virtualMachinesClient().CreateOrUpdate(resourceGroup, name,
compute.VirtualMachine{
Location: to.StringPtr(location),
Properties: &compute.VirtualMachineProperties{
AvailabilitySet: &compute.SubResource{
ID: to.StringPtr(availabilitySetID),
},
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(size),
},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{
{
ID: to.StringPtr(networkInterfaceID),
},
},
},
OsProfile: &compute.OSProfile{
ComputerName: to.StringPtr(name),
AdminUsername: to.StringPtr(username),
LinuxConfiguration: &compute.LinuxConfiguration{
DisablePasswordAuthentication: to.BoolPtr(true),
SSH: &compute.SSHConfiguration{
PublicKeys: &[]compute.SSHPublicKey{
{
Path: to.StringPtr(sshKeyPath),
KeyData: to.StringPtr(sshPublicKey),
},
},
},
},
},
StorageProfile: &compute.StorageProfile{
ImageReference: &compute.ImageReference{
Publisher: to.StringPtr(img.publisher),
Offer: to.StringPtr(img.offer),
Sku: to.StringPtr(img.sku),
Version: to.StringPtr(img.version),
},
OsDisk: &compute.OSDisk{
Name: to.StringPtr(fmt.Sprintf(fmtOSDiskResourceName, name)),
Caching: compute.ReadWrite,
CreateOption: compute.FromImage,
Vhd: &compute.VirtualHardDisk{
URI: to.StringPtr(osDiskBlobURL),
},
},
},
},
}, nil)
return err
}
示例9: assertStartInstanceRequests
func (s *environSuite) assertStartInstanceRequests(
c *gc.C,
requests []*http.Request,
args assertStartInstanceRequestsParams,
) startInstanceRequests {
nsgId := `[resourceId('Microsoft.Network/networkSecurityGroups', 'juju-internal-nsg')]`
securityRules := []network.SecurityRule{{
Name: to.StringPtr("SSHInbound"),
Properties: &network.SecurityRulePropertiesFormat{
Description: to.StringPtr("Allow SSH access to all machines"),
Protocol: network.TCP,
SourceAddressPrefix: to.StringPtr("*"),
SourcePortRange: to.StringPtr("*"),
DestinationAddressPrefix: to.StringPtr("*"),
DestinationPortRange: to.StringPtr("22"),
Access: network.Allow,
Priority: to.Int32Ptr(100),
Direction: network.Inbound,
},
}, {
Name: to.StringPtr("JujuAPIInbound"),
Properties: &network.SecurityRulePropertiesFormat{
Description: to.StringPtr("Allow API connections to controller machines"),
Protocol: network.TCP,
SourceAddressPrefix: to.StringPtr("*"),
SourcePortRange: to.StringPtr("*"),
DestinationAddressPrefix: to.StringPtr("192.168.16.0/20"),
DestinationPortRange: to.StringPtr("17777"),
Access: network.Allow,
Priority: to.Int32Ptr(101),
Direction: network.Inbound,
},
}}
subnets := []network.Subnet{{
Name: to.StringPtr("juju-internal-subnet"),
Properties: &network.SubnetPropertiesFormat{
AddressPrefix: to.StringPtr("192.168.0.0/20"),
NetworkSecurityGroup: &network.SecurityGroup{
ID: to.StringPtr(nsgId),
},
},
}, {
Name: to.StringPtr("juju-controller-subnet"),
Properties: &network.SubnetPropertiesFormat{
AddressPrefix: to.StringPtr("192.168.16.0/20"),
NetworkSecurityGroup: &network.SecurityGroup{
ID: to.StringPtr(nsgId),
},
},
}}
subnetName := "juju-internal-subnet"
privateIPAddress := "192.168.0.4"
if args.availabilitySetName == "juju-controller" {
subnetName = "juju-controller-subnet"
privateIPAddress = "192.168.16.4"
}
subnetId := fmt.Sprintf(
`[concat(resourceId('Microsoft.Network/virtualNetworks', 'juju-internal-network'), '/subnets/%s')]`,
subnetName,
)
publicIPAddressId := `[resourceId('Microsoft.Network/publicIPAddresses', 'machine-0-public-ip')]`
ipConfigurations := []network.InterfaceIPConfiguration{{
Name: to.StringPtr("primary"),
Properties: &network.InterfaceIPConfigurationPropertiesFormat{
Primary: to.BoolPtr(true),
PrivateIPAddress: to.StringPtr(privateIPAddress),
PrivateIPAllocationMethod: network.Static,
Subnet: &network.Subnet{ID: to.StringPtr(subnetId)},
PublicIPAddress: &network.PublicIPAddress{
ID: to.StringPtr(publicIPAddressId),
},
},
}}
nicId := `[resourceId('Microsoft.Network/networkInterfaces', 'machine-0-primary')]`
nics := []compute.NetworkInterfaceReference{{
ID: to.StringPtr(nicId),
Properties: &compute.NetworkInterfaceReferenceProperties{
Primary: to.BoolPtr(true),
},
}}
vmDependsOn := []string{
nicId,
`[resourceId('Microsoft.Storage/storageAccounts', '` + storageAccountName + `')]`,
}
addressPrefixes := []string{"192.168.0.0/20", "192.168.16.0/20"}
templateResources := []armtemplates.Resource{{
APIVersion: network.APIVersion,
Type: "Microsoft.Network/networkSecurityGroups",
Name: "juju-internal-nsg",
Location: "westus",
Tags: to.StringMap(s.envTags),
Properties: &network.SecurityGroupPropertiesFormat{
SecurityRules: &securityRules,
},
}, {
//.........这里部分代码省略.........
示例10:
Publisher: to.StringPtr("OpenLogic"),
Offer: to.StringPtr("CentOS"),
Sku: to.StringPtr("7.1"),
Version: to.StringPtr("latest"),
}
sshPublicKeys = []compute.SSHPublicKey{{
Path: to.StringPtr("/home/ubuntu/.ssh/authorized_keys"),
KeyData: to.StringPtr(testing.FakeAuthKeys),
}}
linuxOsProfile = compute.OSProfile{
ComputerName: to.StringPtr("machine-0"),
CustomData: to.StringPtr("<juju-goes-here>"),
AdminUsername: to.StringPtr("ubuntu"),
LinuxConfiguration: &compute.LinuxConfiguration{
DisablePasswordAuthentication: to.BoolPtr(true),
SSH: &compute.SSHConfiguration{
PublicKeys: &sshPublicKeys,
},
},
}
windowsOsProfile = compute.OSProfile{
ComputerName: to.StringPtr("machine-0"),
CustomData: to.StringPtr("<juju-goes-here>"),
AdminUsername: to.StringPtr("JujuAdministrator"),
AdminPassword: to.StringPtr("sorandom"),
WindowsConfiguration: &compute.WindowsConfiguration{
ProvisionVMAgent: to.BoolPtr(true),
EnableAutomaticUpdates: to.BoolPtr(true),
},
}
示例11: TestInstanceOpenPortsAlreadyOpen
func (s *instanceSuite) TestInstanceOpenPortsAlreadyOpen(c *gc.C) {
internalSubnetId := path.Join(
"/subscriptions", fakeSubscriptionId,
"resourceGroups/juju-testenv-model-deadbeef-0bad-400d-8000-4b1d0d06f00d",
"providers/Microsoft.Network/virtualnetworks/juju-internal-network/subnets/juju-internal-subnet",
)
ipConfiguration := network.InterfaceIPConfiguration{
Properties: &network.InterfaceIPConfigurationPropertiesFormat{
Primary: to.BoolPtr(true),
PrivateIPAddress: to.StringPtr("10.0.0.4"),
Subnet: &network.Subnet{
ID: to.StringPtr(internalSubnetId),
},
},
}
s.networkInterfaces = []network.Interface{
makeNetworkInterface("nic-0", "machine-0", ipConfiguration),
}
inst := s.getInstance(c)
okSender := mocks.NewSender()
okSender.AppendResponse(mocks.NewResponseWithContent("{}"))
nsgSender := networkSecurityGroupSender([]network.SecurityRule{{
Name: to.StringPtr("machine-0-tcp-1000"),
Properties: &network.SecurityRulePropertiesFormat{
Protocol: network.Asterisk,
DestinationPortRange: to.StringPtr("1000"),
Access: network.Allow,
Priority: to.Int32Ptr(202),
Direction: network.Inbound,
},
}})
s.sender = azuretesting.Senders{nsgSender, okSender, okSender}
err := inst.OpenPorts("0", []jujunetwork.PortRange{{
Protocol: "tcp",
FromPort: 1000,
ToPort: 1000,
}, {
Protocol: "udp",
FromPort: 1000,
ToPort: 2000,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.requests, gc.HasLen, 2)
c.Assert(s.requests[0].Method, gc.Equals, "GET")
c.Assert(s.requests[0].URL.Path, gc.Equals, internalSecurityGroupPath)
c.Assert(s.requests[1].Method, gc.Equals, "PUT")
c.Assert(s.requests[1].URL.Path, gc.Equals, securityRulePath("machine-0-udp-1000-2000"))
assertRequestBody(c, s.requests[1], &network.SecurityRule{
Properties: &network.SecurityRulePropertiesFormat{
Description: to.StringPtr("1000-2000/udp"),
Protocol: network.UDP,
SourcePortRange: to.StringPtr("*"),
SourceAddressPrefix: to.StringPtr("*"),
DestinationPortRange: to.StringPtr("1000-2000"),
DestinationAddressPrefix: to.StringPtr("10.0.0.4"),
Access: network.Allow,
Priority: to.Int32Ptr(200),
Direction: network.Inbound,
},
})
}
示例12: createVirtualMachine
//.........这里部分代码省略.........
APIVersion: network.APIVersion,
Type: "Microsoft.Network/publicIPAddresses",
Name: publicIPAddressName,
Location: env.location,
Tags: vmTags,
Properties: &network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: network.Dynamic,
},
})
// Controller and non-controller machines are assigned to separate
// subnets. This enables us to create controller-specific NSG rules
// just by targeting the controller subnet.
subnetName := internalSubnetName
subnetPrefix := internalSubnetPrefix
if instanceConfig.Controller != nil {
subnetName = controllerSubnetName
subnetPrefix = controllerSubnetPrefix
}
subnetId := fmt.Sprintf(
`[concat(resourceId('Microsoft.Network/virtualNetworks', '%s'), '/subnets/%s')]`,
internalNetworkName, subnetName,
)
privateIP, err := machineSubnetIP(subnetPrefix, instanceConfig.MachineId)
if err != nil {
return errors.Annotatef(err, "computing private IP address")
}
nicName := vmName + "-primary"
nicId := fmt.Sprintf(`[resourceId('Microsoft.Network/networkInterfaces', '%s')]`, nicName)
ipConfigurations := []network.InterfaceIPConfiguration{{
Name: to.StringPtr("primary"),
Properties: &network.InterfaceIPConfigurationPropertiesFormat{
Primary: to.BoolPtr(true),
PrivateIPAddress: to.StringPtr(privateIP.String()),
PrivateIPAllocationMethod: network.Static,
Subnet: &network.Subnet{ID: to.StringPtr(subnetId)},
PublicIPAddress: &network.PublicIPAddress{
ID: to.StringPtr(publicIPAddressId),
},
},
}}
resources = append(resources, armtemplates.Resource{
APIVersion: network.APIVersion,
Type: "Microsoft.Network/networkInterfaces",
Name: nicName,
Location: env.location,
Tags: vmTags,
Properties: &network.InterfacePropertiesFormat{
IPConfigurations: &ipConfigurations,
},
DependsOn: []string{
publicIPAddressId,
fmt.Sprintf(
`[resourceId('Microsoft.Network/virtualNetworks', '%s')]`,
internalNetworkName,
),
},
})
nics := []compute.NetworkInterfaceReference{{
ID: to.StringPtr(nicId),
Properties: &compute.NetworkInterfaceReferenceProperties{
Primary: to.BoolPtr(true),
},
}}