Esempio n. 1
0
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
}
Esempio n. 2
0
func (r *TagsCreate) Run() error {
	tag := &vmware.Tag{VmId: r.VmId, Key: r.Key, Value: r.Value}
	return vmware.UpdateTag(tag)
}
Esempio n. 3
0
func (r *TagsDelete) Run() error {
	tag := &vmware.Tag{VmId: r.VmId, Key: r.Key}
	return vmware.UpdateTag(tag)
}