當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CustomizationIdentification.DomainAdmin方法代碼示例

本文整理匯總了Golang中github.com/vmware/govmomi/vim25/types.CustomizationIdentification.DomainAdmin方法的典型用法代碼示例。如果您正苦於以下問題:Golang CustomizationIdentification.DomainAdmin方法的具體用法?Golang CustomizationIdentification.DomainAdmin怎麽用?Golang CustomizationIdentification.DomainAdmin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/vmware/govmomi/vim25/types.CustomizationIdentification的用法示例。


在下文中一共展示了CustomizationIdentification.DomainAdmin方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: deployVirtualMachine


//.........這裏部分代碼省略.........

    var template_mo mo.VirtualMachine
    err = template.Properties(context.TODO(), template.Reference(), []string{"parent", "config.template", "config.guestId", "resourcePool", "snapshot", "guest.toolsVersionStatus2", "config.guestFullName"}, &template_mo)

    var identity_options types.BaseCustomizationIdentitySettings
    if strings.HasPrefix(template_mo.Config.GuestId, "win") {
        var timeZone int
        if vm.timeZone == "Etc/UTC" {
            vm.timeZone = "085"
        }
        timeZone, err := strconv.Atoi(vm.timeZone)
        if err != nil {
            return fmt.Errorf("Error converting TimeZone: %s", err)
        }

        guiUnattended := types.CustomizationGuiUnattended{
            AutoLogon:      false,
            AutoLogonCount: 1,
            TimeZone:       timeZone,
        }

        customIdentification := types.CustomizationIdentification{}

        userData := types.CustomizationUserData{
            ComputerName: &types.CustomizationFixedName{
                Name: strings.Split(vm.name, ".")[0],
            },
            ProductId: vm.windowsOptionalConfig.productKey,
            FullName:  "terraform",
            OrgName:   "terraform",
        }

        if vm.windowsOptionalConfig.domainUserPassword != "" && vm.windowsOptionalConfig.domainUser != "" && vm.windowsOptionalConfig.domain != "" {
            customIdentification.DomainAdminPassword = &types.CustomizationPassword{
                PlainText: true,
                Value:     vm.windowsOptionalConfig.domainUserPassword,
            }
            customIdentification.DomainAdmin = vm.windowsOptionalConfig.domainUser
            customIdentification.JoinDomain = vm.windowsOptionalConfig.domain
        }

        if vm.windowsOptionalConfig.adminPassword != "" {
            guiUnattended.Password = &types.CustomizationPassword{
                PlainText: true,
                Value:     vm.windowsOptionalConfig.adminPassword,
            }
        }

        identity_options = &types.CustomizationSysprep{
            GuiUnattended:  guiUnattended,
            Identification: customIdentification,
            UserData:       userData,
        }
    } else {
        identity_options = &types.CustomizationLinuxPrep{
            HostName: &types.CustomizationFixedName{
                Name: strings.Split(vm.name, ".")[0],
            },
            Domain:     vm.domain,
            TimeZone:   vm.timeZone,
            HwClockUTC: types.NewBool(true),
        }
    }

    // create CustomizationSpec
    customSpec := types.CustomizationSpec{
開發者ID:mafrosis,項目名稱:terraform,代碼行數:67,代碼來源:resource_vsphere_virtual_machine.go

示例2: setupVirtualMachine


//.........這裏部分代碼省略.........
            return fmt.Errorf("[ERROR] setupVirtualMachine - Neither vmdk path nor vmdk name was given: %#v", vm.hardDisks[i])
        }

        err = addHardDisk(newVM, vm.hardDisks[i].size, vm.hardDisks[i].iops, vm.hardDisks[i].initType, datastore, diskPath, vm.hardDisks[i].controller)
        if err != nil {
            return err
        }
    }

    if vm.skipCustomization || vm.template == "" {
        log.Printf("[DEBUG] VM customization skipped")
    } else {
        var identity_options types.BaseCustomizationIdentitySettings
        if strings.HasPrefix(template_mo.Config.GuestId, "win") {
            var timeZone int
            if vm.timeZone == "Etc/UTC" {
                vm.timeZone = "085"
            }
            timeZone, err := strconv.Atoi(vm.timeZone)
            if err != nil {
                return fmt.Errorf("Error converting TimeZone: %s", err)
            }

            guiUnattended := types.CustomizationGuiUnattended{
                AutoLogon:      false,
                AutoLogonCount: 1,
                TimeZone:       int32(timeZone),
            }

            customIdentification := types.CustomizationIdentification{}

            userData := types.CustomizationUserData{
                ComputerName: &types.CustomizationFixedName{
                    Name: strings.Split(vm.name, ".")[0],
                },
                ProductId: vm.windowsOptionalConfig.productKey,
                FullName:  "terraform",
                OrgName:   "terraform",
            }

            if vm.windowsOptionalConfig.domainUserPassword != "" && vm.windowsOptionalConfig.domainUser != "" && vm.windowsOptionalConfig.domain != "" {
                customIdentification.DomainAdminPassword = &types.CustomizationPassword{
                    PlainText: true,
                    Value:     vm.windowsOptionalConfig.domainUserPassword,
                }
                customIdentification.DomainAdmin = vm.windowsOptionalConfig.domainUser
                customIdentification.JoinDomain = vm.windowsOptionalConfig.domain
            }

            if vm.windowsOptionalConfig.adminPassword != "" {
                guiUnattended.Password = &types.CustomizationPassword{
                    PlainText: true,
                    Value:     vm.windowsOptionalConfig.adminPassword,
                }
            }

            identity_options = &types.CustomizationSysprep{
                GuiUnattended:  guiUnattended,
                Identification: customIdentification,
                UserData:       userData,
            }
        } else {
            identity_options = &types.CustomizationLinuxPrep{
                HostName: &types.CustomizationFixedName{
                    Name: strings.Split(vm.name, ".")[0],
                },
                Domain:     vm.domain,
                TimeZone:   vm.timeZone,
                HwClockUTC: types.NewBool(true),
            }
        }

        // create CustomizationSpec
        customSpec := types.CustomizationSpec{
            Identity: identity_options,
            GlobalIPSettings: types.CustomizationGlobalIPSettings{
                DnsSuffixList: vm.dnsSuffixes,
                DnsServerList: vm.dnsServers,
            },
            NicSettingMap: networkConfigs,
        }
        log.Printf("[DEBUG] custom spec: %v", customSpec)

        log.Printf("[DEBUG] VM customization starting")
        taskb, err := newVM.Customize(context.TODO(), customSpec)
        if err != nil {
            return err
        }
        _, err = taskb.WaitForResult(context.TODO(), nil)
        if err != nil {
            return err
        }
        log.Printf("[DEBUG] VM customization finished")
    }

    if vm.hasBootableVmdk || vm.template != "" {
        newVM.PowerOn(context.TODO())
    }
    return nil
}
開發者ID:srikalyan,項目名稱:terraform,代碼行數:101,代碼來源:resource_vsphere_virtual_machine.go


注:本文中的github.com/vmware/govmomi/vim25/types.CustomizationIdentification.DomainAdmin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。