Exemplo n.º 1
0
// AttachNode - attach node
func (dt donut) AttachNode(hostname string, disks []string) error {
	if hostname == "" || len(disks) == 0 {
		return iodine.New(InvalidArgument{}, nil)
	}
	node, err := newNode(hostname)
	if err != nil {
		return iodine.New(err, nil)
	}
	dt.nodes[hostname] = node
	for i, d := range disks {
		newDisk, err := disk.New(d)
		if err != nil {
			return iodine.New(err, nil)
		}
		if err := newDisk.MakeDir(dt.name); err != nil {
			return iodine.New(err, nil)
		}
		if err := node.AttachDisk(newDisk, i); err != nil {
			return iodine.New(err, nil)
		}
	}
	return nil
}
Exemplo n.º 2
0
// attachDonutNode - wrapper function to instantiate a new node for associated donut
// based on the provided configuration
func (d donut) attachDonutNode(hostname string, disks []string) error {
	node, err := NewNode(hostname)
	if err != nil {
		return iodine.New(err, nil)
	}
	donutName := d.name
	for i, d := range disks {
		// Order is necessary for maps, keep order number separately
		newDisk, err := disk.New(d)
		if err != nil {
			return iodine.New(err, nil)
		}
		if err := newDisk.MakeDir(donutName); err != nil {
			return iodine.New(err, nil)
		}
		if err := node.AttachDisk(newDisk, i); err != nil {
			return iodine.New(err, nil)
		}
	}
	if err := d.AttachNode(node); err != nil {
		return iodine.New(err, nil)
	}
	return nil
}