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


Golang ConfigTemplate.Validate方法代碼示例

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


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

示例1: Prepare

func (c *VBoxManagePostConfig) Prepare(t *packer.ConfigTemplate) []error {
	if c.VBoxManagePost == nil {
		c.VBoxManagePost = make([][]string, 0)
	}

	errs := make([]error, 0)
	for i, args := range c.VBoxManagePost {
		for j, arg := range args {
			if err := t.Validate(arg); err != nil {
				errs = append(errs,
					fmt.Errorf("Error processing vboxmanage_post[%d][%d]: %s", i, j, err))
			}
		}
	}

	return errs
}
開發者ID:JNPRAutomate,項目名稱:packer,代碼行數:17,代碼來源:vboxmanage_post_config.go

示例2: Prepare

func (c *PrlctlConfig) Prepare(t *packer.ConfigTemplate) []error {
	if c.Prlctl == nil {
		c.Prlctl = make([][]string, 0)
	}

	errs := make([]error, 0)
	for i, args := range c.Prlctl {
		for j, arg := range args {
			if err := t.Validate(arg); err != nil {
				errs = append(errs,
					fmt.Errorf("Error processing prlctl[%d][%d]: %s", i, j, err))
			}
		}
	}

	return errs
}
開發者ID:JNPRAutomate,項目名稱:packer,代碼行數:17,代碼來源:prlctl_config.go

示例3: Prepare


//.........這裏部分代碼省略.........
		"http_directory":   &c.HTTPDir,
		"ssh_key_path":     &c.SSHKeyPath,
		"ssh_password":     &c.SSHPassword,
		"ssh_username":     &c.SSHUser,
		"ssh_wait_timeout": &c.RawSSHWaitTimeout,
		"output_directory": &c.OutputDir,
		"format":           &c.Format,
		"keep_vm":          &c.KeepVM,
		"ip_getter":        &c.IPGetter,
	}
	for i := range c.FloppyFiles {
		templates[fmt.Sprintf("floppy_files[%d]", i)] = &c.FloppyFiles[i]
	}

	errs := make([]error, 0)
	for n, ptr := range templates {
		*ptr, err = t.Process(*ptr, nil)
		if err != nil {
			errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
		}
	}

	// Validation

	if c.Username == "" {
		errs = append(errs, errors.New("remote_username must be specified."))
	}

	if c.Password == "" {
		errs = append(errs, errors.New("remote_password must be specified."))
	}

	if c.HostIp == "" {
		errs = append(errs, errors.New("remote_host must be specified."))
	}

	if c.HostPortMin > c.HostPortMax {
		errs = append(errs, errors.New("the host min port must be less than the max"))
	}

	if c.HTTPPortMin > c.HTTPPortMax {
		errs = append(errs, errors.New("the HTTP min port must be less than the max"))
	}

	c.BootWait, err = time.ParseDuration(c.RawBootWait)
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed to parse boot_wait: %s", err))
	}

	for i, command := range c.BootCommand {
		if err := t.Validate(command); err != nil {
			errs = append(errs,
				fmt.Errorf("Error processing boot_command[%d]: %s", i, err))
		}
	}

	if c.SSHKeyPath != "" {
		if _, err := os.Stat(c.SSHKeyPath); err != nil {
			errs = append(errs, fmt.Errorf("ssh_key_path is invalid: %s", err))
		} else if _, err := commonssh.FileSigner(c.SSHKeyPath); err != nil {
			errs = append(errs, fmt.Errorf("ssh_key_path is invalid: %s", err))
		}
	}

	/*
		if c.SSHHostPortMin > c.SSHHostPortMax {
			errs = append(errs,
				errors.New("ssh_host_port_min must be less than ssh_host_port_max"))
		}
	*/

	if c.SSHUser == "" {
		errs = append(errs, errors.New("An ssh_username must be specified."))
	}

	c.SSHWaitTimeout, err = time.ParseDuration(c.RawSSHWaitTimeout)
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed to parse ssh_wait_timeout: %s", err))
	}

	switch c.Format {
	case "xva", "vdi_raw", "vdi_vhd", "none":
	default:
		errs = append(errs, errors.New("format must be one of 'xva', 'vdi_raw', 'vdi_vhd', 'none'"))
	}

	switch c.KeepVM {
	case "always", "never", "on_success":
	default:
		errs = append(errs, errors.New("keep_vm must be one of 'always', 'never', 'on_success'"))
	}

	switch c.IPGetter {
	case "auto", "tools", "http":
	default:
		errs = append(errs, errors.New("ip_getter must be one of 'auto', 'tools', 'http'"))
	}

	return errs
}
開發者ID:simonfuhrer,項目名稱:packer-builder-xenserver-1,代碼行數:101,代碼來源:common_config.go


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