Difference between revisions of "OPS435 Online Assignment 2S"

From CDOT Wiki
Jump to: navigation, search
(Add collaborator to your ops435-a2r private repository)
(identify and select appropriate fabric API for each task)
 
(9 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
* Has access to matrix.senecacollege.ca
 
* Has access to matrix.senecacollege.ca
  
'''Due Date:''' Please follow the three stages of submission schedule:
+
'''Due Date:''' complete the testing and debugging using your VM in myvmlab, submit your test results, and the fabric file (a2s_[Seneca_name].py) to Blackboard by April 12, 2021.
* Check point 1: complete the detail algorithm for each task in this assignment by November 25, 2020. Name it as a2s_algorithm.txt and upload it to your github repository
 
* Check point 2: complete the coding of your fabric commands file from the algorithm for each task by Dec 2, 2020. Name it as a2s_[Seneca_name].py (replace [Seneca_name] with your Seneca email user name) and upload it to your github repo by Dec 2, 2020.
 
* Check point 3: complete the testing and debugging using your VM in myvmlab by Dec 4, and also submit your algorithm file (a2s_algorithm.txt), test results, and the fabric file (a2s_[Seneca_name].py) to Blackboard.
 
  
 
'''Late Penalty:''' 20% per school day, and note that in order to pass this course, this assignment must be completed satisfactorily, i.e. a grade of 50% or more.
 
'''Late Penalty:''' 20% per school day, and note that in order to pass this course, this assignment must be completed satisfactorily, i.e. a grade of 50% or more.
  
 
== Overview ==
 
== Overview ==
: Study the Fabric API run(), sudo(), local(), and put() and utilize them to create a new Fabric task called userAdmin()
+
: Study the Fabric API run(), sudo(), local(), and put() and utilize them to create four new Fabric tasks called:
: The userAdmin() task should perform the following activities on a remote machine to:
+
:* addUser(username)
:* create a new user when necessary information is provided
+
:* findUser(username)
:* delete an existing user when it is safe to do so.
+
:* listUser()
 +
:* listSysUser()
 +
: The addUser(username) task should perform the following operations on a remote system:
 +
:* create a new user when necessary information is provided, and if the user name is already exist, the operation should fail.
 +
: The findUser(username) task should perform the following operations on a remote system:
 +
:* scan the appropriate file(s) on the remote system and determine whether the named user exist or not and report accordingly.
 +
: The listUser() task should perform the following operations on a remote system:
 +
:* scan the appropriate file(s) on the remote system and produce a list of shell user names on the system. Shell users are those users who can login to the remote system and get a bash shell.
 +
: The listSysUser() task should perform the following operations on a remote system:
 +
:* scan the appropriate file(s) on the remote system and produce a list of system user (non-shell) name on the system. System users are those users who will not get a bash shell.
  
 
== Tasks for this assignment ==
 
== Tasks for this assignment ==
Line 114: Line 120:
 
* Populate your private repository with appropriate files.
 
* Populate your private repository with appropriate files.
  
=== Add collaborator to your ops435-a2r private repository ===
+
=== Add collaborator to your ops435-a2s private repository ===
 
* Add your professor's github account as one of the collaborators to your ops435-a2s private repository. This will allow your professor to pull the contents of your ops435-a2s repository and also to review and suggest changes and fixes to your algorithm and/or your fabric file.
 
* Add your professor's github account as one of the collaborators to your ops435-a2s private repository. This will allow your professor to pull the contents of your ops435-a2s repository and also to review and suggest changes and fixes to your algorithm and/or your fabric file.
 
* <b><font color='blue'>Make sure that your professor accepted your invitation from github.com.</font></b>
 
* <b><font color='blue'>Make sure that your professor accepted your invitation from github.com.</font></b>
Line 121: Line 127:
 
Follow the standard computation procedure: input - process - ouput when creating the algorithm document for this assignment.
 
Follow the standard computation procedure: input - process - ouput when creating the algorithm document for this assignment.
 
==== input ====
 
==== input ====
* get data (command line arguments/options) from the user using the functions provided by the argparse module
+
* what data do you need for each system administration operation
* according to the arguments/options given at the command line, take appropriate processing action.
 
 
==== processing ====
 
==== processing ====
* based on the file(s) specified, read the contents of each file and use appropriate objects to store it
+
* what commands and in what order they should be executed
* based on the command line arguments/options, process the data accordingly, which includes
 
** data preprocessing (split a multi-day record into single day record)
 
** record processing (preform required computation)
 
 
==== output ====
 
==== output ====
* output the required report based on the processed data
+
* what information should be display or return
==== identify and select appropriate python objects and functions ====
 
The following python functions (to be created, you may have more) are useful in handling the following sub-tasks:
 
* reads login records from files and filters out unwanted records
 
* convert login records into proper python object type so that it can be processed using as much built-in functions as possible
 
* create function which generates daily usage reports by user and/or by remote host
 
* create function which generates weekly usage reports by user and/or by remote host
 
  
To  help you with this assignment, you can use the ur_template.py in the sample ops435-a2 repository as a starting point in designing your own Python Usage Report script.
+
==== identify and select appropriate fabric API for each task ====
<font color='blue'><b>If you don't have enough time to create all the functions for the data processing steps, you should study the functions in the ur_funcs.py (provided by your teacher), pick and use the one that may help. </b></font>
+
You can use the following as the template for your fabric file:
 +
<pre>
 +
from fabric.api import *
 +
'''
 +
OPS435 Assignment 2S - Winter 2021
 +
Program: a2r_[seneca_id].py
 +
Author: Student Name"
 +
The python code in this file a2s_[seneca_id].py is original work written by
 +
[Student Name]. No code in this file is copied from any other source
 +
including any person, textbook, or on-line resource except those provided
 +
by the course instructor. I have not shared this python file with anyone
 +
or anything except for submission for grading. 
 +
I understand that the Academic Honesty Policy will be enforced and violators
 +
will be reported and appropriate action will be taken.
 +
'''
 +
 
 +
env.user = "student"
 +
 
 +
def addUser(name):
 +
    '''add a user with given user name to remote system'''
 +
    ...
 +
 +
def listUser():
 +
    '''return a list of shell user on a remote system'''
 +
    ...
  
=== Python script coding and debugging ===
+
def listSysUser():
For each function, identify what type of objects should be passed to the function, and what type of objects should be returned to the caller.
+
    '''return a list of system (non-shell) user'''
Once you have finished coding a function, you should start a Python3 interactive shell, import your functions and manually test each function and verify its correctness.
+
    ...
 +
 
 +
def findUser(name):
 +
    '''find user with a given user name'''
 +
    ...
 +
 
 +
</pre>
 +
 
 +
=== fabric file coding and debugging ===
 +
Once you have finished coding a task, you should test run it on matrix and verify its correctness.
 
=== Final Test===
 
=== Final Test===
Once you have all the individual function tested and that each is working properly, perform the final test with test data provided by your professor and verify that your script produces the correct results before submitting your python program on Blackboard. Upload all the files for this assignment 2 to your vm in myvmlab and perform the final test.
+
Once you have all the individual task tested and that each is working properly, perform the final test and compare with the sample tests and verify that your fabric tasks produce the correct results before submitting it on Blackboard.
 
 
== Sample login/logout records file and sample test run results==
 
* can be found from the sample repository github.com/rayfreeping/ops435-a2
 
  
 
== Rubric ==
 
== Rubric ==
Line 154: Line 180:
 
! Task !!  Maximum mark !! Actual mark
 
! Task !!  Maximum mark !! Actual mark
 
|-
 
|-
| User Requirement Document||20 ||
+
| addUser || 25 ||
|-
 
| Program usage and Options || 20 ||
 
|-
 
| Generate user name list || 10 ||
 
|-
 
| Generate remote host IP list|| 10 ||
 
 
|-
 
|-
| Daily Usage Report by User || 10 ||
+
| findUSer || 25 ||
 
|-
 
|-
| Daily Usage Report by Remote Host || 10 ||
+
| listUser|| 25 ||
 
|-
 
|-
| Weekly Usage Report by User || 10 ||
+
| listSysUser|| 25 ||
 
|-
 
|-
| Weekly Usage Report by Remote Host || 10 ||
 
|-
 
 
 
| '''Total''' || 100 ||  
 
| '''Total''' || 100 ||  
  
Line 176: Line 193:
  
 
== Submission ==
 
== Submission ==
* Stage 1: upload your algorithm document file to your ops435-a2r repository in github.com by November 25, 2020
+
After fully tested and debugged your fabric file for this assignment, submit your fabric file and final test result to blackboard by April 12, 2021.
* Stage 2: upload your python script for this assignment to your ops435-a2r repository in github.com and to your vm in myvmlab by Dec 2, 2020
 
* Stage 3: After fully tested and debugged your python script for this assignment, update your algorithm, your python script, and your est results to your ops435-a2r repository in github.com. Also submit the algorithm document, the python script and final test result to blackboard by Dec 4, 2020
 

Latest revision as of 22:38, 4 April 2021

Assignment 2 S - Create Fabric tasks for remote User Management

Weight: 15% of the overall grade

What you need

  • A github account with a private repository named ops435-a2s
  • Complete Lab 8
  • A VM assigned to you on myvmlab.senecacollege.ca by Seneca ITS.
  • Has access to matrix.senecacollege.ca

Due Date: complete the testing and debugging using your VM in myvmlab, submit your test results, and the fabric file (a2s_[Seneca_name].py) to Blackboard by April 12, 2021.

Late Penalty: 20% per school day, and note that in order to pass this course, this assignment must be completed satisfactorily, i.e. a grade of 50% or more.

Overview

Study the Fabric API run(), sudo(), local(), and put() and utilize them to create four new Fabric tasks called:
  • addUser(username)
  • findUser(username)
  • listUser()
  • listSysUser()
The addUser(username) task should perform the following operations on a remote system:
  • create a new user when necessary information is provided, and if the user name is already exist, the operation should fail.
The findUser(username) task should perform the following operations on a remote system:
  • scan the appropriate file(s) on the remote system and determine whether the named user exist or not and report accordingly.
The listUser() task should perform the following operations on a remote system:
  • scan the appropriate file(s) on the remote system and produce a list of shell user names on the system. Shell users are those users who can login to the remote system and get a bash shell.
The listSysUser() task should perform the following operations on a remote system:
  • scan the appropriate file(s) on the remote system and produce a list of system user (non-shell) name on the system. System users are those users who will not get a bash shell.

Tasks for this assignment

In this assignment, you should perform the following activities:

  1. Complete a detail algorithm for the following FOUR system administrator operations:
    1. add a user account to a Linux system (task name addUser)
    2. determine whether a given user name exist on a Linux system (task name findUser)
    3. get a list of user account name with a command shell on a Linux system (listUser)
    4. get a list of system account name without a command shell on a Linux system (listSysUser)
  2. Create a corresponding fabric task using the fabric API to automate the above four system administrator operations.
  3. Test and debug your fabric file using your assigned VM in myvmlab.senecacollege.ca

Sample outputs from running your Fabric task file

Name of fabric file: a2s_rchan.py

list of fabric commands

[raymond.chan@mtrx-node05pd lab8]$ fab -f a2s_rchan.py -l
Available commands:

    addUser      add a user with given user name to remote system
    findUser     find user with a given user name
    listSysUser  return a list of system (non-shell) user
    listUser     return a list of shell user on a remote system

Test run the addUser task

[raymond.chan@mtrx-node05pd lab8]$ fab -f faba2.py --host=myvmlab.senecacollege.ca --port=7598 addUser:ops435
[myvmlab.senecacollege.ca] Executing task 'addUser'
[myvmlab.senecacollege.ca] ...

Done.
Disconnecting from myvmlab.senecacollege.ca:7598... done.

Test run the findUser task

[raymond.chan@mtrx-node05pd lab8]$ fab -f faba2.py --host=myvmlab.senecacollege.ca --port=7598 findUser:ops435
[myvmlab.senecacollege.ca] Executing task 'findUser'
...
...

[myvmlab.senecacollege.ca] out: 

Found user ops435 on the system.

Done.
Disconnecting from myvmlab.senecacollege.ca:7598... done.

Another test run:

[raymond.chan@mtrx-node05pd lab8]$ fab -f faba2.py --host=myvmlab.senecacollege.ca --port=7598 findUser:seneca
[myvmlab.senecacollege.ca] Executing task 'findUser'
...
...
[myvmlab.senecacollege.ca] out: 

User seneca is not on the system.

Done.
Disconnecting from myvmlab.senecacollege.ca:7598... done.

Test run the listUser task

[raymond.chan@mtrx-node05pd lab8]$ fab -f faba2.py --host=myvmlab.senecacollege.ca --port=7598 listUser
[myvmlab.senecacollege.ca] Executing task 'listUser'
...
...

['root', 'raymond', 'chan', 'ops435']

Done.
Disconnecting from myvmlab.senecacollege.ca:7598... done.

Test run the listSysUser task

[raymond.chan@mtrx-node05pd lab8]$ fab -f faba2.py --host=myvmlab.senecacollege.ca --port=7598 listSysUser
[myvmlab.senecacollege.ca] Executing task 'listSysUser'
...
...
[myvmlab.senecacollege.ca] out: 

['bin', 'daemon', ... 'postfix', 'chrony', 'ntp']

Done.
Disconnecting from myvmlab.senecacollege.ca:7598... done.

Suggested work-flow for this assignment

create a private repository on github

  • Use the same github account you have used for your assignment 1 repository.
  • Create a private repository named "ops435-a2s" for this assignment.
  • Populate your private repository with appropriate files.

Add collaborator to your ops435-a2s private repository

  • Add your professor's github account as one of the collaborators to your ops435-a2s private repository. This will allow your professor to pull the contents of your ops435-a2s repository and also to review and suggest changes and fixes to your algorithm and/or your fabric file.
  • Make sure that your professor accepted your invitation from github.com.

Detail Algorithm Document

Follow the standard computation procedure: input - process - ouput when creating the algorithm document for this assignment.

input

  • what data do you need for each system administration operation

processing

  • what commands and in what order they should be executed

output

  • what information should be display or return

identify and select appropriate fabric API for each task

You can use the following as the template for your fabric file:

from fabric.api import *
'''
OPS435 Assignment 2S - Winter 2021
Program: a2r_[seneca_id].py
Author: Student Name"
The python code in this file a2s_[seneca_id].py is original work written by
[Student Name]. No code in this file is copied from any other source 
including any person, textbook, or on-line resource except those provided
by the course instructor. I have not shared this python file with anyone
or anything except for submission for grading.  
I understand that the Academic Honesty Policy will be enforced and violators 
will be reported and appropriate action will be taken.
'''

env.user = "student"

def addUser(name):
    '''add a user with given user name to remote system'''
    ...
 
def listUser():
    '''return a list of shell user on a remote system'''
    ...

def listSysUser():
    '''return a list of system (non-shell) user'''
    ...

def findUser(name):
    '''find user with a given user name'''
    ...

fabric file coding and debugging

Once you have finished coding a task, you should test run it on matrix and verify its correctness.

Final Test

Once you have all the individual task tested and that each is working properly, perform the final test and compare with the sample tests and verify that your fabric tasks produce the correct results before submitting it on Blackboard.

Rubric

Task Maximum mark Actual mark
addUser 25
findUSer 25
listUser 25
listSysUser 25
Total 100

Submission

After fully tested and debugged your fabric file for this assignment, submit your fabric file and final test result to blackboard by April 12, 2021.