本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/management/vmutils.ConfigureDeploymentFromPlatformImage函数的典型用法代码示例。如果您正苦于以下问题:Golang ConfigureDeploymentFromPlatformImage函数的具体用法?Golang ConfigureDeploymentFromPlatformImage怎么用?Golang ConfigureDeploymentFromPlatformImage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigureDeploymentFromPlatformImage函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
psPath := "path/to/publishSettings"
dnsName := "test-vm-from-go"
storageAccount := "mystorageaccount"
location := "central us"
vmSize := "Small"
vmImage := "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140724-en-us-30GB"
userName := "testuser"
userPassword := "Test123"
fmt.Println("Create client")
client, err := management.ClientFromPublishSettingsFile(fmt.Sprintf("%s.publishsettings", psPath), "")
if err != nil {
panic(err)
}
fmt.Println("Create hosted service")
if err := hostedservice.NewClient(client).CreateHostedService(hostedservice.CreateHostedServiceParameters{
ServiceName: dnsName,
Location: location,
Label: base64.StdEncoding.EncodeToString([]byte(dnsName))}); err != nil {
panic(err)
}
fmt.Println("Create storage account")
_, err = storageservice.NewClient(client).CreateStorageService(storageservice.StorageAccountCreateParameters{
ServiceName: storageAccount,
Label: base64.URLEncoding.EncodeToString([]byte(storageAccount)),
Location: location,
AccountType: storageservice.AccountTypeStandardLRS})
if err != nil {
panic(err)
}
fmt.Println("Create virtual machine")
role := vmutils.NewVMConfiguration(dnsName, vmSize)
vmutils.ConfigureDeploymentFromPlatformImage(
&role,
vmImage,
fmt.Sprintf("http://%s.blob.core.windows.net/%s/%s.vhd", storageAccount, dnsName, dnsName),
"")
vmutils.ConfigureForLinux(&role, dnsName, userName, userPassword)
vmutils.ConfigureWithPublicSSH(&role)
fmt.Println("Deploy")
operationID, err := virtualmachine.NewClient(client).
CreateDeployment(role, dnsName, virtualmachine.CreateDeploymentOptions{})
if err != nil {
panic(err)
}
fmt.Println("Waiting...")
if err = client.WaitForOperation(operationID, nil); err != nil {
panic(err)
}
}
开发者ID:garimakhulbe,项目名称:azure-sdk-for-go,代码行数:56,代码来源:example.go
示例2: createRole
func createRole(isOSImage bool, vmName, vmSize, certThumbprint, userName, osImageName, mediaLoc string) (role vm.Role) {
role = vmutils.NewVMConfiguration(vmName, vmSize)
vmutils.ConfigureForLinux(&role, vmName, userName, "", certThumbprint)
vmutils.ConfigureWithPublicSSH(&role)
if isOSImage {
vmutils.ConfigureDeploymentFromPlatformImage(&role, osImageName, mediaLoc, "")
} else {
vmutils.ConfigureDeploymentFromVMImage(&role, osImageName, mediaLoc, true)
}
return role
}
开发者ID:leeelavinoth,项目名称:packer-azure,代码行数:11,代码来源:step_create_vm.go
示例3: configureForLinux
//
// configureForLinux sets up the VM role for Linux specific configuration
//
// Paramters:
// role: role that needs to be updated with Linux configuration
// dnsName: name of the machine that we are trying to create
//
// Returns:
// error: errors from reading certs, getting thumbprint and adding
// certificate to hostedservice
//
func (d *Driver) configureForLinux(role *virtualmachine.Role, dnsName string) error {
// Get the Azure client
client, err := d.getClient()
if err != nil {
return err
}
mediaLink := fmt.Sprintf("http://%s.blob.core.windows.net/vhds/%s.vhd",
d.StorageAccount, dnsName)
// Setup the image configuration
vmutils.ConfigureDeploymentFromPlatformImage(
role,
d.Image,
mediaLink,
"")
// Read the certificate
data, err := ioutil.ReadFile(d.azureCertPath())
if err != nil {
return err
}
// Add the certificate to the hostedservice
if _, err := hostedservice.NewClient(client).AddCertificate(dnsName, data, "pfx", ""); err != nil {
return err
}
thumbPrint, err := getServiceCertFingerprint(d.azureCertPath())
if err != nil {
return err
}
vmutils.ConfigureForLinux(role, dnsName, d.SSHUser, d.UserPassword, thumbPrint)
vmutils.ConfigureWithPublicSSH(role)
role.UseCertAuth = true
role.CertPath = d.azureCertPath()
// Attach VM to a specific subnet
if d.Subnet != "" {
err = vmutils.ConfigureWithSubnet(role, d.Subnet)
if err != nil {
log.Error("failed to configure subnet:", d.Subnet, ", err:", err)
return err
}
log.Debug("subnet is:", d.Subnet)
}
return nil
}
开发者ID:containerx,项目名称:machine,代码行数:63,代码来源:azure.go
示例4: main
func main() {
dnsName := "test-vm-from-go"
storageAccount := "gosdktest"
location := "West US"
vmSize := "Small"
vmImage := "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140724-en-us-30GB"
userName := "testuser"
userPassword := "Test123"
client, err := management.ClientFromPublishSettingsFile("/Users/niklasg/Downloads/Internal-credentials.publishsettings", "")
if err != nil {
panic(err)
}
// create hosted service
if err := hostedservice.NewClient(client).CreateHostedService(hostedservice.CreateHostedServiceParameters{
ServiceName: dnsName,
Location: location,
Label: base64.StdEncoding.EncodeToString([]byte(dnsName))}); err != nil {
if azErr, ok := err.(management.AzureError); !ok || azErr.Code != "ConflictError" {
panic(err)
}
}
// create virtual machine
role := vmutils.NewVMConfiguration(dnsName, vmSize)
vmutils.ConfigureDeploymentFromPlatformImage(
&role,
vmImage,
fmt.Sprintf("http://%s.blob.core.windows.net/sdktest/%s.vhd", storageAccount, dnsName),
"")
vmutils.ConfigureForLinux(&role, dnsName, userName, userPassword)
vmutils.ConfigureWithPublicSSH(&role)
operationID, err := virtualmachine.NewClient(client).
CreateDeployment(role, dnsName, virtualmachine.CreateDeploymentOptions{})
if err != nil {
panic(err)
}
if err := client.WaitForOperation(operationID, nil); err != nil {
panic(err)
}
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:44,代码来源:createvm01.go
示例5: retrieveOSImageDetails
func retrieveOSImageDetails(
osImageClient osimage.OSImageClient,
label string,
name string,
storage string) (func(*virtualmachine.Role) error, string, []string, error) {
imgs, err := osImageClient.ListOSImages()
if err != nil {
return nil, "", nil, fmt.Errorf("Error retrieving image details: %s", err)
}
var labels []string
for _, img := range imgs.OSImages {
if img.Label == label {
if img.OS != linux && img.OS != windows {
return nil, "", nil, fmt.Errorf("Unsupported image OS: %s", img.OS)
}
if img.MediaLink == "" {
if storage == "" {
return nil, "", nil, PlatformStorageError
}
img.MediaLink = fmt.Sprintf(osDiskBlobStorageURL, storage, name)
}
configureForImage := func(role *virtualmachine.Role) error {
return vmutils.ConfigureDeploymentFromPlatformImage(
role,
img.Name,
img.MediaLink,
label,
)
}
return configureForImage, img.OS, nil, nil
}
labels = append(labels, img.Label)
}
return nil, "", labels, fmt.Errorf("Could not find image with label '%s'", label)
}
开发者ID:devendraPSL,项目名称:terraform-api,代码行数:41,代码来源:resource_azure_instance.go
示例6: Run
func (*StepValidate) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get(constants.RequestManager).(management.Client)
ui := state.Get(constants.Ui).(packer.Ui)
config := state.Get(constants.Config).(*Config)
ui.Say("Validating Azure options...")
role := vmutils.NewVMConfiguration(config.tmpVmName, config.InstanceSize)
ui.Message("Checking Storage Account...")
destinationVhd, err := validateStorageAccount(config, client)
if err != nil {
err = fmt.Errorf("Error checking storage account: %v", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
ui.Message(fmt.Sprintf("Destination VHD: %s", destinationVhd))
if err := func() error {
if config.RemoteSourceImageLink != "" {
ui.Message("Checking remote image source link...")
response, err := http.DefaultClient.Head(config.RemoteSourceImageLink)
if response != nil && response.Body != nil {
defer response.Body.Close()
}
if err != nil {
log.Printf("HTTP client returned error: %s", err)
return fmt.Errorf("error checking remote image source link: %v", err)
}
if response.StatusCode != 200 {
return fmt.Errorf("Unexpected status while retrieving remote image source at %s: %d %s", config.RemoteSourceImageLink, response.StatusCode, response.Status)
}
size := float64(response.ContentLength) / 1024 / 1024 / 1024
ui.Say(fmt.Sprintf("Remote image size: %.1f GiB", size))
vmutils.ConfigureDeploymentFromRemoteImage(&role, config.RemoteSourceImageLink, config.OSType, fmt.Sprintf("%s-OSDisk", config.tmpVmName), destinationVhd, "")
if config.ResizeOSVhdGB != nil {
if float64(*config.ResizeOSVhdGB) < size {
return fmt.Errorf("new OS VHD size of %d GiB is smaller than current size of %.1f GiB", *config.ResizeOSVhdGB, size)
}
ui.Say(fmt.Sprintf("Remote image will be resized to %d GiB", *config.ResizeOSVhdGB))
role.OSVirtualHardDisk.ResizedSizeInGB = *config.ResizeOSVhdGB
}
} else {
ui.Message("Checking image source...")
imageList, err := osimage.NewClient(client).ListOSImages()
if err != nil {
log.Printf("OS image client returned error: %s", err)
return err
}
if osImage, found := FindOSImage(imageList.OSImages, config.OSImageLabel, config.Location); found {
vmutils.ConfigureDeploymentFromPlatformImage(&role, osImage.Name, destinationVhd, "")
ui.Message(fmt.Sprintf("Image source is OS image %q", osImage.Name))
if osImage.OS != config.OSType {
return fmt.Errorf("OS image type (%q) does not match config (%q)", osImage.OS, config.OSType)
}
if config.ResizeOSVhdGB != nil {
if float64(*config.ResizeOSVhdGB) < osImage.LogicalSizeInGB {
return fmt.Errorf("new OS VHD size of %d GiB is smaller than current size of %.1f GiB", *config.ResizeOSVhdGB, osImage.LogicalSizeInGB)
}
ui.Say(fmt.Sprintf("OS image will be resized to %d GiB", *config.ResizeOSVhdGB))
role.OSVirtualHardDisk.ResizedSizeInGB = *config.ResizeOSVhdGB
}
} else {
imageList, err := vmimage.NewClient(client).ListVirtualMachineImages(
vmimage.ListParameters{
Location: config.Location,
})
if err != nil {
log.Printf("VM image client returned error: %s", err)
return err
}
if vmImage, found := FindVmImage(imageList.VMImages, "", config.OSImageLabel); found {
if config.ResizeOSVhdGB != nil {
return fmt.Errorf("Packer cannot resize VM images")
}
if vmImage.OSDiskConfiguration.OSState != vmimage.OSStateGeneralized {
return fmt.Errorf("Packer can only use VM user images with a generalized OS so that it can be reprovisioned. The specified image OS is not in a generalized state.")
}
if vmImage.Category == vmimage.CategoryUser {
//vmutils.ConfigureDeploymentFromUserVMImage(&role, vmImage.Name)
role.VMImageName = vmImage.Name
} else {
vmutils.ConfigureDeploymentFromPublishedVMImage(&role, vmImage.Name, destinationVhd, true)
}
ui.Message(fmt.Sprintf("Image source is VM image %q", vmImage.Name))
if vmImage.OSDiskConfiguration.OS != config.OSType {
return fmt.Errorf("VM image type (%q) does not match config (%q)", vmImage.OSDiskConfiguration.OS, config.OSType)
}
} else {
return fmt.Errorf("Can't find VM or OS image '%s' Located at '%s'", config.OSImageLabel, config.Location)
}
}
}
//.........这里部分代码省略.........
开发者ID:lopaka,项目名称:packer-azure,代码行数:101,代码来源:step_validate.go
示例7: Run
func (*StepValidate) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get(constants.RequestManager).(management.Client)
ui := state.Get(constants.Ui).(packer.Ui)
config := state.Get(constants.Config).(*Config)
ui.Say("Validating Azure options...")
role := vmutils.NewVMConfiguration(config.tmpVmName, config.InstanceSize)
ui.Message("Checking Storage Account...")
destinationVhd, err := validateStorageAccount(config, client)
if err != nil {
err = fmt.Errorf("Error checking storage account: %v", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
ui.Message(fmt.Sprintf("Destination VHD: %s", destinationVhd))
if err := func() error {
if config.RemoteSourceImageLink != "" {
ui.Message("Checking remote image source link...")
response, err := http.DefaultClient.Head(config.RemoteSourceImageLink)
if response != nil && response.Body != nil {
defer response.Body.Close()
}
if err != nil {
log.Printf("HTTP client returned error: %s", err)
return fmt.Errorf("error checking remote image source link: %v", err)
}
if response.StatusCode != 200 {
return fmt.Errorf("Unexpected status while retrieving remote image source at %s: %d %s", config.RemoteSourceImageLink, response.StatusCode, response.Status)
}
size := float64(response.ContentLength) / 1024 / 1024 / 1024
ui.Say(fmt.Sprintf("Remote image size: %.1f GiB", size))
vmutils.ConfigureDeploymentFromRemoteImage(&role, config.RemoteSourceImageLink, config.OSType, fmt.Sprintf("%s-OSDisk", config.tmpVmName), destinationVhd, "")
} else {
ui.Message("Checking image source...")
imageList, err := osimage.NewClient(client).ListOSImages()
if err != nil {
log.Printf("OS image client returned error: %s", err)
return err
}
if osImage, found := FindOSImage(imageList.OSImages, config.OSImageLabel, config.Location); found {
vmutils.ConfigureDeploymentFromPlatformImage(&role, osImage.Name, destinationVhd, "")
ui.Message(fmt.Sprintf("Image source is OS image %q", osImage.Name))
if osImage.OS != config.OSType {
return fmt.Errorf("OS image type (%q) does not match config (%q)", osImage.OS, config.OSType)
}
} else {
imageList, err := vmimage.NewClient(client).ListVirtualMachineImages()
if err != nil {
log.Printf("VM image client returned error: %s", err)
return err
}
if vmImage, found := FindVmImage(imageList.VMImages, "", config.OSImageLabel, config.Location); found {
vmutils.ConfigureDeploymentFromVMImage(&role, vmImage.Name, destinationVhd, true)
ui.Message(fmt.Sprintf("Image source is VM image %q", vmImage.Name))
if vmImage.OSDiskConfiguration.OS != config.OSType {
return fmt.Errorf("VM image type (%q) does not match config (%q)", vmImage.OSDiskConfiguration.OS, config.OSType)
}
} else {
return fmt.Errorf("Can't find VM or OS image '%s' Located at '%s'", config.OSImageLabel, config.Location)
}
}
}
return nil
}(); err != nil {
err = fmt.Errorf("Error determining deployment source: %v", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
if config.OSType == constants.Target_Linux {
certThumbprint := state.Get(constants.Thumbprint).(string)
if len(certThumbprint) == 0 {
err := fmt.Errorf("Certificate Thumbprint is empty")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
vmutils.ConfigureForLinux(&role, config.tmpVmName, config.UserName, "", certThumbprint)
vmutils.ConfigureWithPublicSSH(&role)
} else if config.OSType == constants.Target_Windows {
password := utils.RandomPassword()
state.Put("password", password)
vmutils.ConfigureForWindows(&role, config.tmpVmName, config.UserName, password, true, "")
vmutils.ConfigureWithPublicRDP(&role)
vmutils.ConfigureWithPublicPowerShell(&role)
}
if config.VNet != "" && config.Subnet != "" {
ui.Message("Checking VNet...")
if err := checkVirtualNetworkConfiguration(client, config.VNet, config.Subnet, config.Location); err != nil {
state.Put("error", err)
ui.Error(err.Error())
//.........这里部分代码省略.........
开发者ID:nivertech,项目名称:packer-azure,代码行数:101,代码来源:step_validate.go
示例8: configureForWindows
//
// configureForWindows sets up the VM role for Windows specific configuration
//
// Paramters:
// role: role that needs to be updated with Windows configuration
// dnsName: name of the machine that we are trying to create
//
// Returns:
// None
//
func (d *Driver) configureForWindows(role *virtualmachine.Role, dnsName string) error {
// Get the Azure client
client, err := d.getClient()
if err != nil {
return err
}
mediaLocation := fmt.Sprintf("http://%s.blob.core.windows.net/vhds/%s.vhd",
d.StorageAccount, dnsName)
// Setup the image configuration
vmutils.ConfigureDeploymentFromPlatformImage(
role,
d.Image,
mediaLocation,
"")
log.Debug("Configured deployment from platform image")
vmutils.ConfigureForWindows(role, dnsName, d.SSHUser, d.UserPassword, true, "")
log.Debug("Configured for windows")
vmutils.ConfigureWithPublicSSH(role)
log.Debug("Configured for SSH")
vmutils.ConfigureWithPublicRDP(role)
log.Debug("Configured for RDP")
vmutils.ConfigureWithPublicPowerShell(role)
log.Debug("Configured with Powershell")
vmutils.ConfigureWithExternalPort(role, "WinRMu", 5985, 5985,
virtualmachine.InputEndpointProtocolTCP)
log.Debug("Configured WinRM port 5985")
// Read the certificate
data, err := ioutil.ReadFile(d.azureCertPath())
if err != nil {
return err
}
log.Debug("Read certificate from Azure cert path: ", d.azureCertPath())
// Add the certificate to the hostedservice
if _, err := hostedservice.NewClient(client).AddCertificate(dnsName, data, "pfx", ""); err != nil {
log.Error("failed to add certificate:", err)
return err
}
log.Debug("Added certificate to hostedservice")
vmutils.ConfigureWinRMOverHTTP(role)
log.Debug("Configured WinRM over HTTP")
vmutils.ConfigureWinRMOverHTTPS(role, "")
log.Debug("Configured WinRM over HTTPS without using a thumbprint")
// Attach VM to a specific subnet
if d.Subnet != "" {
err = vmutils.ConfigureWithSubnet(role, d.Subnet)
if err != nil {
log.Error("failed to configure subnet:", d.Subnet, ", err:", err)
return err
}
log.Debug("subnet is:", d.Subnet)
}
return nil
}
开发者ID:containerx,项目名称:machine,代码行数:77,代码来源:azure.go
注:本文中的github.com/Azure/azure-sdk-for-go/management/vmutils.ConfigureDeploymentFromPlatformImage函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论