当前位置: 首页>>代码示例>>Golang>>正文


Golang vix.VM类代码示例

本文整理汇总了Golang中github.com/hooklift/terraform-provider-vix/provider/vix.VM的典型用法代码示例。如果您正苦于以下问题:Golang VM类的具体用法?Golang VM怎么用?Golang VM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了VM类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: resourceVIXVMCreate

func resourceVIXVMCreate(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	if err := tf_to_vix(d, vm); err != nil {
		return err
	}

	id, err := vm.Create()
	if err != nil {
		return err
	}

	log.Printf("[DEBUG] Resource ID: %s\n", id)
	d.SetId(id)

	// Initialize the connection info
	d.SetConnInfo(map[string]string{
		"type": "ssh",
		"host": vm.IPAddress,
	})

	return resourceVIXVMRead(d, meta)
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: resourceVIXVMDelete

func resourceVIXVMDelete(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)
	vmxFile := d.Id()

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	if password := d.Get("password"); password != nil {
		vm.Image.Password = d.Get("password").(string)
	}

	return vm.Destroy(vmxFile)
}
开发者ID:,项目名称:,代码行数:14,代码来源:

示例3: resourceVIXVMUpdate

func resourceVIXVMUpdate(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	// Maps terraform.ResourceState attrbutes to vix.VM
	tf_to_vix(d, vm)

	err := vm.Update(d.Id())
	if err != nil {
		return err
	}

	return resourceVIXVMRead(d, meta)
}
开发者ID:,项目名称:,代码行数:17,代码来源:

示例4: cdrom_tf_to_vix

func cdrom_tf_to_vix(d *schema.ResourceData, vm *vix.VM) error {
	cdromCount := d.Get("cdrom.#").(int)
	vm.CDDVDDrives = make([]*govix.CDDVDDrive, 0, cdromCount)

	for i := 0; i < cdromCount; i++ {
		prefix := fmt.Sprintf("cdrom.%d.", i)
		cdrom := new(govix.CDDVDDrive)

		if attr, ok := d.Get(prefix + "bus_type").(string); ok && attr != "" {
			cdrom.Bus = vmx.BusType(attr)
		}

		if attr, ok := d.Get(prefix + "image").(string); ok && attr != "" {
			cdrom.Filename = attr
		}
		vm.CDDVDDrives = append(vm.CDDVDDrives, cdrom)
	}

	return nil
}
开发者ID:,项目名称:,代码行数:20,代码来源:

示例5: resourceVIXVMRead

func resourceVIXVMRead(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	vmxFile := d.Id()

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	running, err := vm.Refresh(vmxFile)
	if err != nil {
		return err
	}

	// This is to let TF know the resource is gone
	if !running {
		return nil
	}

	// Refreshes only what makes sense, for example, we do not refresh settings
	// that modify the behavior of this provider
	d.Set("name", vm.Name)
	d.Set("description", vm.Description)
	d.Set("cpus", vm.CPUs)
	d.Set("memory", vm.Memory)
	d.Set("ip_address", vm.IPAddress)

	err = net_vix_to_tf(vm, d)
	if err != nil {
		return err
	}

	err = cdrom_vix_to_tf(vm, d)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:,项目名称:,代码行数:39,代码来源:

示例6: tf_to_vix

// Maps Terraform attributes to provider's structs
func tf_to_vix(d *schema.ResourceData, vm *vix.VM) error {
	var err error

	vm.Name = d.Get("name").(string)
	vm.Description = d.Get("description").(string)
	vm.CPUs = uint(d.Get("cpus").(int))

	vm.Memory = d.Get("memory").(string)
	vm.UpgradeVHardware = d.Get("upgrade_vhardware").(bool)
	vm.LaunchGUI = d.Get("gui").(bool)
	vm.SharedFolders = d.Get("sharedfolders").(bool)

	vm.ToolsInitTimeout, err = time.ParseDuration(d.Get("tools_init_timeout").(string))

	// Maps any defined networks to VIX provider's data types
	err = net_tf_to_vix(d, vm)
	if err != nil {
		return fmt.Errorf("Error mapping TF network adapter resource to VIX data types: %s", err)
	}

	if i := d.Get("image.#").(int); i > 0 {
		prefix := "image.0."
		vm.Image = vix.Image{
			URL:          d.Get(prefix + "url").(string),
			Checksum:     d.Get(prefix + "checksum").(string),
			ChecksumType: d.Get(prefix + "checksum_type").(string),
			Password:     d.Get(prefix + "password").(string),
		}
	}

	err = cdrom_tf_to_vix(d, vm)
	if err != nil {
		return fmt.Errorf("Error mapping TF cdrom resource to VIX data types: %s", err)
	}

	return nil
}
开发者ID:,项目名称:,代码行数:38,代码来源:

示例7: net_tf_to_vix

func net_tf_to_vix(d *schema.ResourceData, vm *vix.VM) error {
	tf_to_vix_virtual_device := func(attr string) (govix.VNetDevice, error) {
		switch attr {
		case "vlance":
			return govix.NETWORK_DEVICE_VLANCE, nil
		case "e1000":
			return govix.NETWORK_DEVICE_E1000, nil
		case "vmxnet3":
			return govix.NETWORK_DEVICE_VMXNET3, nil
		default:
			return "", fmt.Errorf("[ERROR] Invalid virtual network device: %s", attr)
		}
	}

	tf_to_vix_network_type := func(attr string) (govix.NetworkType, error) {
		switch attr {
		case "bridged":
			return govix.NETWORK_BRIDGED, nil
		case "nat":
			return govix.NETWORK_NAT, nil
		case "hostonly":
			return govix.NETWORK_HOSTONLY, nil
		case "custom":
			return govix.NETWORK_CUSTOM, nil
		default:
			return "", fmt.Errorf("[ERROR] Invalid virtual network adapter type: %s", attr)
		}
	}

	// tf_to_vix_vswitch := func(attr string) (vix.VSwitch, error) {
	// 	return vix.VSwitch{}, nil
	// }

	var err error
	var errs []error
	adaptersCount := d.Get("network_adapter.#").(int)
	vm.VNetworkAdapters = make([]*govix.NetworkAdapter, 0, adaptersCount)

	for i := 0; i < adaptersCount; i++ {
		prefix := fmt.Sprintf("network_adapter.%d.", i)
		adapter := new(govix.NetworkAdapter)

		if attr, ok := d.Get(prefix + "driver").(string); ok && attr != "" {
			adapter.Vdevice, err = tf_to_vix_virtual_device(attr)
		}

		if attr, ok := d.Get(prefix + "mac_address").(string); ok && attr != "" {
			// Only set a MAC address if it is declared as static
			// otherwise leave Govix to assign or continue using the generated
			// one.
			if addrtype, ok := d.Get(prefix + "mac_address_type").(string); ok && addrtype == "static" {
				adapter.MacAddress, err = net.ParseMAC(attr)
			}
		}

		if attr, ok := d.Get(prefix + "type").(string); ok && attr != "" {
			adapter.ConnType, err = tf_to_vix_network_type(attr)
		}

		// if attr, ok := adapter["vswitch"].(string); ok && attr != "" {
		// 	vnic.VSwitch, err = tf_to_vix_vswitch(attr)
		// }
		if err != nil {
			errs = append(errs, err)
		}

		log.Printf("[DEBUG] Network adapter: %+v\n", adapter)
		vm.VNetworkAdapters = append(vm.VNetworkAdapters, adapter)
	}

	if len(errs) > 0 {
		return &multierror.Error{Errors: errs}
	}

	return nil
}
开发者ID:,项目名称:,代码行数:76,代码来源:


注:本文中的github.com/hooklift/terraform-provider-vix/provider/vix.VM类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。