func AttachDisk(c config.Cpi, extInput bosh.MethodArguments) error {
	var vmCID string
	var diskCID string

	if reflect.TypeOf(extInput[0]) != reflect.TypeOf(vmCID) {
		return errors.New("Received unexpected type for vm cid")
	}

	if reflect.TypeOf(extInput[1]) != reflect.TypeOf(diskCID) {
		return errors.New("Received unexpected type for disk cid")
	}

	vmCID = extInput[0].(string)
	diskCID = extInput[1].(string)

	node, err := rackhdapi.GetNodeByVMCID(c, vmCID)
	if err != nil {
		return fmt.Errorf("VM: %s not found\n", vmCID)
	}

	if node.PersistentDisk.DiskCID == "" {
		return fmt.Errorf("Disk: %s not found on VM: %s", diskCID, vmCID)
	}

	if node.PersistentDisk.DiskCID != diskCID {
		if node.PersistentDisk.IsAttached {
			return fmt.Errorf("Node %s has persistent disk %s attached. Cannot attach additional disk %s.", vmCID, node.PersistentDisk.DiskCID, diskCID)
		} else {
			return fmt.Errorf("Node %s has persistent disk %s, but detached. Cannot attach disk %s.", vmCID, node.PersistentDisk.DiskCID, diskCID)
		}
	}

	if node.CID != vmCID {
		return fmt.Errorf("Disk: %s does not belong to VM: %s\n", diskCID, vmCID)
	}

	if !node.PersistentDisk.IsAttached {
		err = rackhdapi.MakeDiskRequest(c, node, true)
		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
}
func DetachDisk(c config.Cpi, extInput bosh.MethodArguments) error {
	var vmCID string
	var diskCID string

	if reflect.TypeOf(extInput[0]) != reflect.TypeOf(vmCID) {
		return errors.New("Received unexpected type for vm cid")
	}

	if reflect.TypeOf(extInput[1]) != reflect.TypeOf(diskCID) {
		return errors.New("Received unexpected type for disk cid")
	}

	vmCID = extInput[0].(string)
	diskCID = extInput[1].(string)

	nodes, err := rackhdapi.GetNodes(c)
	if err != nil {
		return err
	}

	for _, node := range nodes {
		if node.PersistentDisk.DiskCID == diskCID {
			if !node.PersistentDisk.IsAttached {
				return fmt.Errorf("Disk: %s is detached\n", diskCID)
			}

			if node.CID != vmCID {
				return fmt.Errorf("Disk %s does not belong to VM %s\n", diskCID, vmCID)
			}

			return rackhdapi.MakeDiskRequest(c, node, false)
		}
	}

	return fmt.Errorf("Disk: %s not found\n", diskCID)
}