Пример #1
0
func DeleteVM(c config.Cpi, extInput bosh.MethodArguments) error {
	var cid string
	if reflect.TypeOf(extInput[0]) != reflect.TypeOf(cid) {
		return errors.New("Received unexpected type for vm cid")
	}

	cid = extInput[0].(string)
	node, err := rackhdapi.GetNodeByVMCID(c, cid)
	if err != nil {
		return err
	}
	nodeID := node.ID

	workflowName, err := workflows.PublishDeprovisionNodeWorkflow(c, cid)
	if err != nil {
		return err
	}

	err = workflows.RunDeprovisionNodeWorkflow(c, nodeID, workflowName)
	if err != nil {
		return err
	}

	err = rackhdapi.ReleaseNode(c, nodeID)
	if err != nil {
		return err
	}

	return nil
}
func DeleteVM(c config.Cpi, extInput bosh.MethodArguments) error {
	var cid string
	if reflect.TypeOf(extInput[0]) != reflect.TypeOf(cid) {
		return errors.New("Received unexpected type for vm cid")
	}

	cid = extInput[0].(string)
	node, err := rackhdapi.GetNodeByVMCID(c, cid)
	if err != nil {
		return err
	}

	if node.PersistentDisk.IsAttached {
		err = rackhdapi.MakeDiskRequest(c, node, false)
		if err != nil {
			return err
		}
	}

	workflowName, err := workflows.PublishDeprovisionNodeWorkflow(c)
	if err != nil {
		return err
	}

	err = workflows.RunDeprovisionNodeWorkflow(c, node.ID, workflowName)
	if err != nil {
		return err
	}

	if node.PersistentDisk.DiskCID == "" {
		err = rackhdapi.ReleaseNode(c, node.ID)
		if err != nil {
			return err
		}
	}

	return nil
}