Difference between revisions of "Importing Groups from a File"
IVSWikiBlue (talk | contribs) (Created page with "=Instructions= # Upload the groupimport.py and valt.py to the VALT appliance using WINSCP, scp or another sftp program. # Connect to the VALT appliance using SSH. # Log in #...") |
(No difference)
|
Latest revision as of 15:47, 27 May 2020
Instructions
- Upload the groupimport.py and valt.py to the VALT appliance using WINSCP, scp or another sftp program.
- Connect to the VALT appliance using SSH.
- Log in
- Type the following command and press enter:
-
python groupimport.py -s servername -u username -p password -f pathtofilename
- Be sure to replace all paramenters with the correct values. Also make sure to include --ssl if the server is using https.
-
Script
The following python script will import groups into VALT. The script is written for Python 2.7 which should be installed on all VALT servers by default. It also relies on the VALT python library.
import getopt, sys, valt def main(argv): https = False try: opts, args = getopt.getopt(argv,"hs:u:p:f:",["server=","username=","password=","ssl=","file="]) except getopt.GetoptError: print('groupimport.py -s <Server IP> -u <username> -p <password> -f <filename> --ssl True') sys.exit(2) for opt, arg in opts: if opt == '-h': print('groupimport.py -s <Server IP> -u <username> -p <password> -f <filename> --ssl True') sys.exit() elif opt in ("-s", "--server"): server = arg elif opt in ("-u", "--username"): username = arg elif opt in ("-p", "--password"): password = arg elif opt in ("-f", "--file"): filepath = arg elif opt in ("--ssl"): https = True auth = valt.valtauth(https,server,username,password) print(auth) if auth != 0: try: groupfile = open(filepath,"r") except Exception: pass else: for line in groupfile: splitline = line.split("|") rightslist = splitline[1].split(",") valt.creategroup(https,server,auth,splitline[0],30,71,rights=rightslist) groupfile.close() if __name__ == "__main__": main(sys.argv[1:])
Parameters
There is very limited error handling in this script. It will most likely error out if improper parameters are entered.
Parameter | Value | Required |
---|---|---|
-s,--server | Server FQDN or IP Address | Yes |
-u,--username | VALT username | Yes |
-p,--password | VALT password | Yes |
-f,--file | Path to input file | Yes |
--ssl | True if the server is using https, otherwise omit | No |
File Layout
The input file must be pipe delimited with two fields.
Field | Type | Value |
---|---|---|
Group Name | String | Name for group to be created in VALT. |
Rights | Comma Delimited String with no text qualifiers | Rights that will be granted to the new group in VALT. |
File Example
Import Group 1|general,general--home,general--alert,general--edit-profile,general--password-complexity,general--change-password,general--notifications Import Group 2|general,general--home,general--alert,general--edit-profile,general--password-complexity,general--change-password,general--notifications Import Group 3|general,general--home,general--alert,general--edit-profile,general--password-complexity,general--change-password,general--notifications