本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/arm/compute.VirtualMachineSizeTypes函数的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachineSizeTypes函数的具体用法?Golang VirtualMachineSizeTypes怎么用?Golang VirtualMachineSizeTypes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualMachineSizeTypes函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: resourceArmVirtualMachineCreate
func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
vmClient := client.vmClient
log.Printf("[INFO] preparing arguments for Azure ARM Virtual Machine creation.")
name := d.Get("name").(string)
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)
osDisk, err := expandAzureRmVirtualMachineOsDisk(d)
if err != nil {
return err
}
storageProfile := compute.StorageProfile{
OsDisk: osDisk,
}
if _, ok := d.GetOk("storage_image_reference"); ok {
imageRef, err := expandAzureRmVirtualMachineImageReference(d)
if err != nil {
return err
}
storageProfile.ImageReference = imageRef
}
if _, ok := d.GetOk("storage_data_disk"); ok {
dataDisks, err := expandAzureRmVirtualMachineDataDisk(d)
if err != nil {
return err
}
storageProfile.DataDisks = &dataDisks
}
networkProfile := expandAzureRmVirtualMachineNetworkProfile(d)
vmSize := d.Get("vm_size").(string)
properties := compute.VirtualMachineProperties{
NetworkProfile: &networkProfile,
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(vmSize),
},
StorageProfile: &storageProfile,
}
osProfile, err := expandAzureRmVirtualMachineOsProfile(d)
if err != nil {
return err
}
properties.OsProfile = osProfile
if v, ok := d.GetOk("availability_set_id"); ok {
availabilitySet := v.(string)
availSet := compute.SubResource{
ID: &availabilitySet,
}
properties.AvailabilitySet = &availSet
}
vm := compute.VirtualMachine{
Name: &name,
Location: &location,
Properties: &properties,
Tags: expandedTags,
}
if _, ok := d.GetOk("plan"); ok {
plan, err := expandAzureRmVirtualMachinePlan(d)
if err != nil {
return err
}
vm.Plan = plan
}
_, vmErr := vmClient.CreateOrUpdate(resGroup, name, vm, make(chan struct{}))
if vmErr != nil {
return vmErr
}
read, err := vmClient.Get(resGroup, name, "")
if err != nil {
return err
}
if read.ID == nil {
return fmt.Errorf("Cannot read Virtual Machine %s (resource group %s) ID", name, resGroup)
}
d.SetId(*read.ID)
return resourceArmVirtualMachineRead(d, meta)
}
开发者ID:yonatanp,项目名称:terraform,代码行数:94,代码来源:resource_arm_virtual_machine.go
示例2: createVirtualMachine
// createVirtualMachine creates a virtual machine and related resources.
//
// All resources created are tagged with the specified "vmTags", so if
// this function fails then all resources can be deleted by tag.
func createVirtualMachine(
resourceGroup, location, vmName string,
vmTags, envTags map[string]string,
instanceSpec *instances.InstanceSpec,
instanceConfig *instancecfg.InstanceConfig,
distributionGroupFunc func() ([]instance.Id, error),
instancesFunc func([]instance.Id) ([]instance.Instance, error),
apiPort *int,
internalNetworkSubnet *network.Subnet,
nsgID, storageEndpoint, storageAccountName string,
networkClient network.ManagementClient,
vmClient compute.VirtualMachinesClient,
availabilitySetClient compute.AvailabilitySetsClient,
vmExtensionClient compute.VirtualMachineExtensionsClient,
) (compute.VirtualMachine, error) {
storageProfile, err := newStorageProfile(
vmName, instanceConfig.Series,
instanceSpec, storageEndpoint, storageAccountName,
)
if err != nil {
return compute.VirtualMachine{}, errors.Annotate(err, "creating storage profile")
}
osProfile, seriesOS, err := newOSProfile(vmName, instanceConfig)
if err != nil {
return compute.VirtualMachine{}, errors.Annotate(err, "creating OS profile")
}
networkProfile, err := newNetworkProfile(
networkClient, vmName, apiPort,
internalNetworkSubnet, nsgID,
resourceGroup, location, vmTags,
)
if err != nil {
return compute.VirtualMachine{}, errors.Annotate(err, "creating network profile")
}
availabilitySetId, err := createAvailabilitySet(
availabilitySetClient,
vmName, resourceGroup, location,
vmTags, envTags,
distributionGroupFunc, instancesFunc,
)
if err != nil {
return compute.VirtualMachine{}, errors.Annotate(err, "creating availability set")
}
vmArgs := compute.VirtualMachine{
Location: to.StringPtr(location),
Tags: toTagsPtr(vmTags),
Properties: &compute.VirtualMachineProperties{
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(
instanceSpec.InstanceType.Name,
),
},
StorageProfile: storageProfile,
OsProfile: osProfile,
NetworkProfile: networkProfile,
AvailabilitySet: &compute.SubResource{
ID: to.StringPtr(availabilitySetId),
},
},
}
vm, err := vmClient.CreateOrUpdate(resourceGroup, vmName, vmArgs)
if err != nil {
return compute.VirtualMachine{}, errors.Annotate(err, "creating virtual machine")
}
// On Windows and CentOS, we must add the CustomScript VM
// extension to run the CustomData script.
switch seriesOS {
case os.Windows, os.CentOS:
if err := createVMExtension(
vmExtensionClient, seriesOS,
resourceGroup, vmName, location, vmTags,
); err != nil {
return compute.VirtualMachine{}, errors.Annotate(
err, "creating virtual machine extension",
)
}
}
return vm, nil
}
开发者ID:makyo,项目名称:juju,代码行数:89,代码来源:environ.go
示例3: 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
}
开发者ID:RaulKite,项目名称:machine,代码行数:74,代码来源:azureutil.go
示例4: resourceArmVirtualMachineCreate
func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
vmClient := client.vmClient
log.Printf("[INFO] preparing arguments for Azure ARM Virtual Machine creation.")
name := d.Get("name").(string)
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)
osDisk, err := expandAzureRmVirtualMachineOsDisk(d)
if err != nil {
return err
}
storageProfile := compute.StorageProfile{
OsDisk: osDisk,
}
if _, ok := d.GetOk("storage_image_reference"); ok {
imageRef, err := expandAzureRmVirtualMachineImageReference(d)
if err != nil {
return err
}
storageProfile.ImageReference = imageRef
}
if _, ok := d.GetOk("storage_data_disk"); ok {
dataDisks, err := expandAzureRmVirtualMachineDataDisk(d)
if err != nil {
return err
}
storageProfile.DataDisks = &dataDisks
}
networkProfile := expandAzureRmVirtualMachineNetworkProfile(d)
vmSize := d.Get("vm_size").(string)
properties := compute.VirtualMachineProperties{
NetworkProfile: &networkProfile,
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(vmSize),
},
StorageProfile: &storageProfile,
}
osProfile, err := expandAzureRmVirtualMachineOsProfile(d)
if err != nil {
return err
}
properties.OsProfile = osProfile
if v, ok := d.GetOk("availability_set_id"); ok {
availabilitySet := v.(string)
availSet := compute.SubResource{
ID: &availabilitySet,
}
properties.AvailabilitySet = &availSet
}
vm := compute.VirtualMachine{
Name: &name,
Location: &location,
Properties: &properties,
Tags: expandedTags,
}
if _, ok := d.GetOk("plan"); ok {
plan, err := expandAzureRmVirtualMachinePlan(d)
if err != nil {
return err
}
vm.Plan = plan
}
resp, vmErr := vmClient.CreateOrUpdate(resGroup, name, vm)
if vmErr != nil {
return vmErr
}
d.SetId(*resp.ID)
log.Printf("[DEBUG] Waiting for Virtual Machine (%s) to become available", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"Creating", "Updating"},
Target: []string{"Succeeded"},
Refresh: virtualMachineStateRefreshFunc(client, resGroup, name),
Timeout: 20 * time.Minute,
MinTimeout: 10 * time.Second,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Virtual Machine (%s) to become available: %s", name, err)
}
return resourceArmVirtualMachineRead(d, meta)
}
开发者ID:22Acacia,项目名称:terraform-provider-googleappengine,代码行数:98,代码来源:resource_arm_virtual_machine.go
示例5: createVirtualMachine
//.........这里部分代码省略.........
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),
},
}}
vmDependsOn = append(vmDependsOn, nicId)
vmDependsOn = append(vmDependsOn, fmt.Sprintf(
`[resourceId('Microsoft.Storage/storageAccounts', '%s')]`,
env.storageAccountName,
))
resources = append(resources, armtemplates.Resource{
APIVersion: compute.APIVersion,
Type: "Microsoft.Compute/virtualMachines",
Name: vmName,
Location: env.location,
Tags: vmTags,
Properties: &compute.VirtualMachineProperties{
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(
instanceSpec.InstanceType.Name,
),
},
StorageProfile: storageProfile,
OsProfile: osProfile,
NetworkProfile: &compute.NetworkProfile{
&nics,
},
AvailabilitySet: availabilitySetSubResource,
},
DependsOn: vmDependsOn,
})
// On Windows and CentOS, we must add the CustomScript VM
// extension to run the CustomData script.
switch seriesOS {
case os.Windows, os.CentOS:
properties, err := vmExtensionProperties(seriesOS)
if err != nil {
return errors.Annotate(
err, "creating virtual machine extension",
)
}
resources = append(resources, armtemplates.Resource{
APIVersion: compute.APIVersion,
Type: "Microsoft.Compute/virtualMachines/extensions",
Name: vmName + "/" + extensionName,
Location: env.location,
Tags: vmTags,
Properties: properties,
DependsOn: []string{"Microsoft.Compute/virtualMachines/" + vmName},
})
}
logger.Debugf("- creating virtual machine deployment")
template := armtemplates.Template{Resources: resources}
// NOTE(axw) VMs take a long time to go to "Succeeded", so we do not
// block waiting for them to be fully provisioned. This means we won't
// return an error from StartInstance if the VM fails provisioning;
// we will instead report the error via the instance's status.
deploymentsClient.ResponseInspector = asyncCreationRespondDecorator(
deploymentsClient.ResponseInspector,
)
if err := createDeployment(
env.callAPI,
deploymentsClient,
env.resourceGroup,
vmName, // deployment name
template,
); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:101,代码来源:environ.go
示例6: configureVirtualMachine
func (clst *azureCluster) configureVirtualMachine(vmName string, osDiskName string,
nicName string, cloudConfig string, vmSize string, location string,
iface network.Interface) error {
hardwareProfile := compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(vmSize),
}
ifaceRef := compute.NetworkInterfaceReference{
ID: iface.ID,
}
networkProfile := compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{ifaceRef},
}
storageAccounts, err := clst.listStorageAccounts()
if err != nil {
return err
}
storageAccount, ok := storageAccounts[location]
if !ok {
return errors.New("a storage account is needed for location " + location)
}
vhdURI := fmt.Sprintf("http://%s.blob.core.windows.net/vhds/%s.vhd",
*storageAccount.Name, osDiskName)
vhd := compute.VirtualHardDisk{
URI: &vhdURI,
}
osDisk := compute.OSDisk{
Name: &osDiskName,
Caching: compute.ReadWrite,
CreateOption: compute.FromImage,
Vhd: &vhd,
}
imageRef := compute.ImageReference{
Publisher: stringPtr(imagePublisher),
Offer: stringPtr(imageOffer),
Sku: stringPtr(imageSku),
Version: stringPtr(imageVersion),
}
storageProfile := compute.StorageProfile{
ImageReference: &imageRef,
OsDisk: &osDisk,
}
// We have to set username and password even though we do not need it.
adminUsername := uuid.NewV4().String()
adminPassword := uuid.NewV4().String()
customData := base64.StdEncoding.EncodeToString([]byte(cloudConfig))
osProfile := compute.OSProfile{
ComputerName: &vmName,
AdminUsername: &adminUsername,
AdminPassword: &adminPassword,
CustomData: &customData,
}
properties := compute.VirtualMachineProperties{
HardwareProfile: &hardwareProfile,
NetworkProfile: &networkProfile,
StorageProfile: &storageProfile,
OsProfile: &osProfile,
}
virtualMachine := compute.VirtualMachine{
Name: &vmName,
Location: &location,
Properties: &properties,
Tags: &map[string]*string{nsTag: &clst.namespace},
}
cancel := make(chan struct{})
_, err = clst.azureClient.vmCreate(resourceGroupName, vmName, virtualMachine,
cancel)
return err
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:83,代码来源:azure.go
注:本文中的github.com/Azure/azure-sdk-for-go/arm/compute.VirtualMachineSizeTypes函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论