IT3110 - System Automation

IT3110 @ utahtech

Week 3 Assignment

Description

You are an instructor at a local University. You are tasked with creating virtual machines for students so that they can utilize them for an exam. All that you know is the students identifier. You also have a range of IP addresses that you will assign to these virtual machines. Your task is to prepare the virtual machines for each student in a given list.

The only manual thing that you are allowed to do, prior to writing your script is to put the correct DHCP range entries on your DHCP server for the 10.150.100.0/24 network. (Read further to find out why). You can also manually tell it to include a file at /etc/dhcp/myassignment.dhcp

Your script should receive as command-line arguments: the name of the student file , the starting ip address that will be assigned to each student, and the user that you will ssh to the vm server as, and the optional word remove. Your script should be runnable from the ssh server and use passwordless authentication.

A sample run of your assignment could be like this: ./assignment.sh http://it3110.cs.utahtech.edu/week3/students.txt 10 jfrancom remove or this ./assignment.sh http://it3110.cs.utahtech.edu/week3/students.txt 10 jfrancom

You should validate that each of the first 3 command-line arguments are present, the fourth is optional. If any of the first 3 args are missing, call a function called usage, which displays to the user how to use the script, then exits with a status of 1 (one).

No other functions are required unless you want to use them.

The list of students is found in this. Remember, you cannot manually modify anything. Your script must do it.

The vm should be created like this (after ssh’ing to vm.cs.utahtech.edu): /qemu/bin/citv clonevm f23_jammy_partitioned_dhcp firstname-lastname-222 256 2004. firstname-lastname should be replaced by the students first and last name. The number 222 should be replaced by the last octet that you are assigning them. THe number 2004 should be replaced with a vlan under your control. These machines will only have 256M ram for now (We won’t turn them on).

After you create the vm, you should be able to harvest the mac address.

Your script must generate a fixed dhcp entry of the following format:

    host firstname-lastname {
      hardware ethernet 00:1b:63:99:59:4f;
      fixed-address 10.50.100.x;
    }

Note that the firstname-lastname should be replaced by the students actual firstname and lastname from the list.

For the fixed address, we will all use the 10.50.100.x/24 network. The x will be replaced by the calculated ip address. Remember that the script is expecting to receive a starting ip address. If you pass in a 2, the first users ip address would be 10.50.100.2, the next user would be .3 and so on.

Generate all the fixed entries, save them to a file named dhcp.txt. If this file exists when your script first executes, you should delete it.

Your script should now scp the dhcp.txt file to your dhcp server, put it in the correct location(/etc/dhcp/myassignment.dhcp), restart the dhcp service. (Note: this must be done as the root user on the remote machine, i.e. scp root@ip. The correct way to scp as root, is to copy your .ssh/id_rsa.pub from the local machine to /home/root/.ssh/authorized_keys on the remote machine. Copy/Paste would likely be the best way to do this)

You should manually verify that the dhcp service is running correctly and has loaded the file.

To pass off

I will probably ask you to demo your script. Upload your script to the week3/assignment.sh in the git repo.