示例#1
0
文件: clone.go 项目: ibmendoza/dgtk
func (action *Clone) Run() error {
	out := fmt.Sprintf("cloning vm %q", action.VmName)
	if action.SnapshotName != "" {
		out += fmt.Sprintf(" and snapshot=%q", action.SnapshotName)
	}
	logger.Printf(out)
	vms, e := vmware.AllWithTemplates()
	if e != nil {
		return e
	}
	vm := vms.FindFirst(action.VmName)
	clone, e := vmware.Create(vm, action.SnapshotName)
	if e != nil {
		return e
	}
	logger.Printf("using %d cpus", action.Cpus)
	e = clone.ModifyCpu(action.Cpus)
	if e != nil {
		return e
	}
	logger.Printf("using %d memory", action.Memory)
	e = clone.ModifyMemory(action.Memory)
	if e != nil {
		return e
	}
	started := time.Now()
	e = clone.Start()
	logger.Printf("started in %.3f", time.Since(started).Seconds())
	if e != nil {
		return e
	}

	if action.Name != "" {
		return vmware.UpdateTag(&vmware.Tag{VmId: clone.Id(), Key: "Name", Value: action.Name})
	}
	return nil
}
示例#2
0
func (r *TagsCreate) Run() error {
	tag := &vmware.Tag{VmId: r.VmId, Key: r.Key, Value: r.Value}
	return vmware.UpdateTag(tag)
}
示例#3
0
func (r *TagsDelete) Run() error {
	tag := &vmware.Tag{VmId: r.VmId, Key: r.Key}
	return vmware.UpdateTag(tag)
}