diff options
author | Bob Gilligan <gilligan@vyatta.com> | 2008-09-10 15:54:16 -0700 |
---|---|---|
committer | Bob Gilligan <gilligan@vyatta.com> | 2008-09-10 15:54:16 -0700 |
commit | 15c75d023be453a717aefc82f02b6ef6fd8b7ace (patch) | |
tree | 3aafdd6511dd56d79de6599d5eed17a625f5a56a | |
parent | 39ef568ad5da594f92ea445bfd1190aa54ff0fb8 (diff) | |
download | vyatta-op-15c75d023be453a717aefc82f02b6ef6fd8b7ace.tar.gz vyatta-op-15c75d023be453a717aefc82f02b6ef6fd8b7ace.zip |
Add operational mode commands for RAID.
-rw-r--r-- | templates/add/node.def | 1 | ||||
-rw-r--r-- | templates/add/raid/node.def | 1 | ||||
-rw-r--r-- | templates/add/raid/node.tag/member/node.def | 1 | ||||
-rw-r--r-- | templates/add/raid/node.tag/member/node.tag/node.def | 38 | ||||
-rw-r--r-- | templates/add/raid/node.tag/node.def | 6 | ||||
-rw-r--r-- | templates/format/disk/node.def | 1 | ||||
-rw-r--r-- | templates/format/disk/node.tag/like/node.def | 1 | ||||
-rw-r--r-- | templates/format/disk/node.tag/like/node.tag/node.def | 59 | ||||
-rw-r--r-- | templates/format/disk/node.tag/node.def | 6 | ||||
-rw-r--r-- | templates/format/node.def | 1 | ||||
-rw-r--r-- | templates/remove/node.def | 1 | ||||
-rw-r--r-- | templates/remove/raid/node.def | 1 | ||||
-rw-r--r-- | templates/remove/raid/node.tag/member/node.def | 1 | ||||
-rw-r--r-- | templates/remove/raid/node.tag/member/node.tag/node.def | 35 | ||||
-rw-r--r-- | templates/remove/raid/node.tag/node.def | 6 | ||||
-rw-r--r-- | templates/show/disk/node.def | 1 | ||||
-rw-r--r-- | templates/show/disk/node.tag/format/node.def | 12 | ||||
-rw-r--r-- | templates/show/disk/node.tag/node.def | 7 | ||||
-rw-r--r-- | templates/show/raid/node.def | 2 | ||||
-rw-r--r-- | templates/show/raid/node.tag/node.def | 16 |
20 files changed, 197 insertions, 0 deletions
diff --git a/templates/add/node.def b/templates/add/node.def new file mode 100644 index 0000000..39ff67a --- /dev/null +++ b/templates/add/node.def @@ -0,0 +1 @@ +help: Add an object to a service diff --git a/templates/add/raid/node.def b/templates/add/raid/node.def new file mode 100644 index 0000000..26cc4a3 --- /dev/null +++ b/templates/add/raid/node.def @@ -0,0 +1 @@ +help: Add a RAID set element diff --git a/templates/add/raid/node.tag/member/node.def b/templates/add/raid/node.tag/member/node.def new file mode 100644 index 0000000..efa1d45 --- /dev/null +++ b/templates/add/raid/node.tag/member/node.def @@ -0,0 +1 @@ +help: Add a member to a RAID set
\ No newline at end of file diff --git a/templates/add/raid/node.tag/member/node.tag/node.def b/templates/add/raid/node.tag/member/node.tag/node.def new file mode 100644 index 0000000..60eff63 --- /dev/null +++ b/templates/add/raid/node.tag/member/node.tag/node.def @@ -0,0 +1,38 @@ +help: Name of RAID set member to add + +allowed: + raid_set=${COMP_WORDS[2]} + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + membership=`echo $membership | sed -e 's/(F)//g'` + partitions=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep "[0-9]"` + for member in $membership; do + partitions=`echo $partitions | sed -e s/$member//g` + done + partitions=`echo $partitions | sed -e 's/md[0-9]*//g'` + echo "$partitions" + +run: + raid_set=$3 + member_to_add=$5 + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + is_in=`echo $membership | grep $member_to_add` + + partitions=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep "[0-9]"` + partitions=`echo $partitions | sed -e 's/md[0-9]*//g'` + valid_partition=`echo $partitions | grep $member_to_add` + + if [ -z "$membership" ]; then + echo "$raid_set is not a RAID set" + elif [ -n "$is_in" ]; then + echo "$member_to_add is already a member of RAID set $raid_set" + echo "actual members are: $membership" + elif [ -z "$valid_partition" ]; then + echo "$member_to_add is not a valid disk partition" + else + echo "adding member $member_to_add to RAID set $raid_set" + mdadm /dev/$raid_set --add /dev/$member_to_add + if [ $? -ne 0 ]; then + echo "Unable to add member to RAID set" + fi + fi + diff --git a/templates/add/raid/node.tag/node.def b/templates/add/raid/node.tag/node.def new file mode 100644 index 0000000..e0ae4d9 --- /dev/null +++ b/templates/add/raid/node.tag/node.def @@ -0,0 +1,6 @@ +help: Name of RAID set to add object to + +allowed: + local -a array ; + array=`cat /proc/partitions | grep md | awk '{ print $4 }'` + echo -n $array diff --git a/templates/format/disk/node.def b/templates/format/disk/node.def new file mode 100644 index 0000000..664804b --- /dev/null +++ b/templates/format/disk/node.def @@ -0,0 +1 @@ +help: Format a disk drive
\ No newline at end of file diff --git a/templates/format/disk/node.tag/like/node.def b/templates/format/disk/node.tag/like/node.def new file mode 100644 index 0000000..99f73b1 --- /dev/null +++ b/templates/format/disk/node.tag/like/node.def @@ -0,0 +1 @@ +help: Format this disk the same as another disk
\ No newline at end of file diff --git a/templates/format/disk/node.tag/like/node.tag/node.def b/templates/format/disk/node.tag/like/node.tag/node.def new file mode 100644 index 0000000..8927dc8 --- /dev/null +++ b/templates/format/disk/node.tag/like/node.tag/node.def @@ -0,0 +1,59 @@ +help: Name of disk drive to partition it like + +allowed: + local -a disks ; + proto_disk=${COMP_WORDS[2]} + disks=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + disks=`echo $disks | sed -e s/$proto_disk//g` + echo -n $disks + +run: + proto_disk=$5 + format_disk=$3 + backup_dir=/var/log/vyatta + eligible_format_disks=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + eligible_proto_disks=`echo $eligible_format_disks | sed -e s/$format_disk//g` + proto_eligible=`echo $eligible_proto_disks | grep $proto_disk` + format_eligible=`echo $eligible_format_disks | grep $format_disk` + busy_check=`sfdisk -R /dev/$format_disk 2>&1` + + if [ $proto_disk = $format_disk ]; then + echo "The two disk drives must be different." + elif [ ! -b /dev/$proto_disk ]; then + echo "Device /dev/$proto_disk does not exist" + elif [ ! -b /dev/$format_disk ]; then + echo "Device /dev/$format_disk does not exist" + elif [ -z "$format_eligible" ]; then + echo "Device $format_disk can not be formatted" + elif [ -z "$proto_eligible" ]; then + echo "Device $proto_disk can not be used as a prototype for $format_disk" + elif [ -n "$busy_check" ]; then + echo "Disk device $format_disk is busy. Can't format it now." + else + echo "This will re-format disk $format_disk so that it has the same disk" + echo "partion sizes and offsets as $proto_disk. This will not copy" + echo "data from $proto_disk to $format_disk. But this will erase all" + echo "data on $format_disk." + echo + echo -n "Do you wish to proceed (yes, NO)? " + read response + if [ "$response" = "yes" ]; then + echo "OK. Re-formating disk drive $format_disk..." + echo "Making backup copy of partitions..." + sfdisk -d /dev/$format_disk > $backup_dir/backup_$format_disk.`date +%F-%R` + sleep 1 + partitions=`cat /proc/partitions | grep $format_disk'[0-9]' | awk '{ print $4 }' | sed 's/[a-z]//g'` + if [ -n "$partitions" ]; then + echo -n "Deleting old partitions..." + for part in $partitions ; do + parted /dev/$format_disk rm $part + done + echo "" + fi + echo "Creating new partitions on $format_disk based on $proto_disk..." + sfdisk -d /dev/$proto_disk | sfdisk --force /dev/$format_disk + echo "Done." + else + echo "OK. Disk drive $format_drive will not be re-formated." + fi + fi
\ No newline at end of file diff --git a/templates/format/disk/node.tag/node.def b/templates/format/disk/node.tag/node.def new file mode 100644 index 0000000..2b77c5b --- /dev/null +++ b/templates/format/disk/node.tag/node.def @@ -0,0 +1,6 @@ +help: Disk drive name + +allowed: + local -a array ; + array=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + echo -n $array diff --git a/templates/format/node.def b/templates/format/node.def new file mode 100644 index 0000000..edb71bd --- /dev/null +++ b/templates/format/node.def @@ -0,0 +1 @@ +help: Format a device
\ No newline at end of file diff --git a/templates/remove/node.def b/templates/remove/node.def new file mode 100644 index 0000000..387e0d2 --- /dev/null +++ b/templates/remove/node.def @@ -0,0 +1 @@ +help: Remove an object from service diff --git a/templates/remove/raid/node.def b/templates/remove/raid/node.def new file mode 100644 index 0000000..2700b93 --- /dev/null +++ b/templates/remove/raid/node.def @@ -0,0 +1 @@ +help: Remove a RAID set element diff --git a/templates/remove/raid/node.tag/member/node.def b/templates/remove/raid/node.tag/member/node.def new file mode 100644 index 0000000..6af665d --- /dev/null +++ b/templates/remove/raid/node.tag/member/node.def @@ -0,0 +1 @@ +help: Remove a member of a RAID set
\ No newline at end of file diff --git a/templates/remove/raid/node.tag/member/node.tag/node.def b/templates/remove/raid/node.tag/member/node.tag/node.def new file mode 100644 index 0000000..d384fd3 --- /dev/null +++ b/templates/remove/raid/node.tag/member/node.tag/node.def @@ -0,0 +1,35 @@ +help: Name of RAID set member to remove + +allowed: + raid_set=${COMP_WORDS[2]} + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + membership=`echo $membership | sed -e 's/(F)//g'` + echo "$membership" + +run: + raid_set=$3 + member_to_remove=$5 + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + num_members=`echo $membership | wc -w` + is_in=`echo $membership | grep $member_to_remove` + + if [ -z "$membership" ]; then + echo "$raid_set is not a RAID set" + elif [ -z "$is_in" ]; then + echo "$member_to_remove is not a member of RAID set $raid_set" + echo "actual members are: $membership" + elif [ "$num_members" -eq "1" ]; then + echo "Can't remove last member of a RAID set" + else + echo "removing member $member from RAID set $raid_set" + mdadm /dev/$raid_set --fail /dev/$member_to_remove + if [ $? -ne 0 ]; then + echo "Unable to mark member as failed" + else + sleep 1 + mdadm /dev/$raid_set --remove /dev/$member_to_remove + if [ $? -ne 0 ]; then + echo "Unable to remove member from RAID set" + fi + fi + fi diff --git a/templates/remove/raid/node.tag/node.def b/templates/remove/raid/node.tag/node.def new file mode 100644 index 0000000..a8d8485 --- /dev/null +++ b/templates/remove/raid/node.tag/node.def @@ -0,0 +1,6 @@ +help: Name of RAID set to remove object from + +allowed: + local -a array ; + array=`cat /proc/partitions | grep md | awk '{ print $4 }'` + echo -n $array diff --git a/templates/show/disk/node.def b/templates/show/disk/node.def new file mode 100644 index 0000000..8572a9f --- /dev/null +++ b/templates/show/disk/node.def @@ -0,0 +1 @@ +help: Show status of disk device diff --git a/templates/show/disk/node.tag/format/node.def b/templates/show/disk/node.tag/format/node.def new file mode 100644 index 0000000..e05b4ad --- /dev/null +++ b/templates/show/disk/node.tag/format/node.def @@ -0,0 +1,12 @@ +help: Show disk drive formatting + +run: + disk_dev=$3 + valid_disks=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + is_a_disk=`echo $valid_disks | grep $disk_dev` + + if [ -z "$is_a_disk" ]; then + echo "$disk_dev is not a disk device" + else + fdisk -l /dev/${disk_dev} + fi diff --git a/templates/show/disk/node.tag/node.def b/templates/show/disk/node.tag/node.def new file mode 100644 index 0000000..7e4fe05 --- /dev/null +++ b/templates/show/disk/node.tag/node.def @@ -0,0 +1,7 @@ +help: Disk device name + +allowed: + local -a array ; + array=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + echo -n $array + diff --git a/templates/show/raid/node.def b/templates/show/raid/node.def new file mode 100644 index 0000000..d0ec96d --- /dev/null +++ b/templates/show/raid/node.def @@ -0,0 +1,2 @@ +help: Show status of RAID set + diff --git a/templates/show/raid/node.tag/node.def b/templates/show/raid/node.tag/node.def new file mode 100644 index 0000000..bc83a73 --- /dev/null +++ b/templates/show/raid/node.tag/node.def @@ -0,0 +1,16 @@ +help: RAID set name + +allowed: + local -a raid_sets ; + raid_sets=`cat /proc/partitions | grep md | awk '{ print $4 }'` + echo -n $raid_sets + +run: + raid_set_name=$3 + raid_sets=`cat /proc/partitions | grep md | awk '{ print $4 }'` + valid_set=`echo $raid_sets | grep $raid_set_name` + if [ -z $valid_set ]; then + echo "$raid_set_name is not a RAID set" + else + mdadm --detail /dev/${raid_set_name} + fi
\ No newline at end of file |