def tutorial_cfg_cmd(): """ Configure some command templates. """ master = Master() cmd = Command() cmd.abs_cmd = 'hwinfo' cmd.act_cmd = 'lscpu' master.cfg_cmd('10.65.7.131', cmd) cmd.abs_cmd = 'hwinfo' cmd.act_cmd = 'lscpu' master.cfg_cmd('10.137.59.22', cmd) cmd.abs_cmd = 'networkinfo' cmd.act_cmd = 'ifconfig' master.cfg_cmd('10.65.7.131', cmd) cmd.abs_cmd = 'networkinfo' cmd.act_cmd = 'ifconfig' master.cfg_cmd('10.137.59.22', cmd)
def tutorial_exec_cmd(): """ Configure one command and execute it to show network interface information on device(here we use linux server instead of real device) """ master = Master() cmd = Command() cmd.abs_cmd = 'networkinfo' cmd.act_cmd = 'ifconfig' master.cfg_cmd('10.137.59.22', cmd) para_list = [] identity1 = Identity() identity1.ip = '10.137.59.22' identity1.dev_id = 'tianyi.dty' identity1.dev_pw = 'Mtfbwy626488' telnetPro = ('telnet_server_control', 'TelnetServerControl') para_list.append(('cmd', 'networkinfo', identity1, telnetPro)) result = master.execute(para_list) print 'result:' print result
def __init__(self, master=None, controller_mailbox=None): self.master = master if master else Master.get_master(mailbox=controller_mailbox) self.controller_mailbox = controller_mailbox self.config_handler = ConfigHandler() initialize_storage_db() check_tool_availability() self.access_handler = AccessHandler() acl_parser = ACLConfigHandler() #database access authorization self.table_to_class = dict(workspaces=Workspaces, storages=Storage) self.cls_to_identifier_method = { Workspaces: Workspaces.get_by_full_name, Storage: Storage.get_storage_by_name} self.cls_to_acl = {Workspaces: acl_parser.get_workspaces_setter_acl, Storage: acl_parser.get_storages_setter_acl}
def tutorial_exec_script(): """ Configure two types of comamands, then execute a script to show hardware and network information on device (here we use linux server instead of real device) """ master = Master() cmd = Command() cmd.abs_cmd = 'hwinfo' cmd.act_cmd = 'lscpu' master.cfg_cmd('10.65.7.131', cmd) cmd.abs_cmd = 'hwinfo' cmd.act_cmd = 'lscpu' master.cfg_cmd('10.137.59.22', cmd) cmd.abs_cmd = 'networkinfo' cmd.act_cmd = 'ifconfig' master.cfg_cmd('10.65.7.131', cmd) para_list = [('script', 'script-linux.py')] result = master.execute(para_list) print 'result:' print result
def test_cancel_job(): try: johann = User.get_user_by_username('johann') except UserNotFoundException: johann = User('johann', 'jtoken') job = Job('dmd_home', 'dmd1', 'home/centos/testdata/johann-directory-1', [False, False, False], johann) job_id = job.id master = Master.get_master() master.add_to_queue(job) master.cancel_job(job) worker = master.get_workers()[0] assert worker.name == 'worker1' assert worker.status.name == 'WAITING' assert Job.get_job_by_id(job_id).status.name == 'CANCELED'
def tutorial_exec_script2(): """ Configure two commands which have the same abstract command on different devices. Then execute a script which contains both these commands to show network interface information on device(here we use linux server instead of real device) """ master = Master() cmd = Command() cmd.abs_cmd = 'show' cmd.act_cmd = 'show -hw' master.cfg_cmd('1.1.1.1', cmd) cmd.abs_cmd = 'ps' cmd.act_cmd = 'ps -hw' master.cfg_cmd('1.1.1.1', cmd) cmd.abs_cmd = 'show' cmd.act_cmd = 'show -cisco' master.cfg_cmd('192.168.0.1', cmd) para_list = [('script', 'script-diffdev.py')] result = master.execute(para_list) print 'result:' print result
def test_success_job(env): try: johann = User.get_user_by_username('johann') except UserNotFoundException: johann = User('johann', 'jtoken') job = Job(source_alias = 'dmd_home', target_alias = 'archive1', source_relative_path = 'export/master_data/tests/johann-directory-1', notification = [False, False, False], user = johann) job_id = job.id master = Master.get_master() worker = master.get_workers()[0] assert worker.name == 'worker1' assert worker.status.name == 'WAITING' master.add_to_queue(job) time.sleep(5) while (worker.status.name == 'ACTIVE'): #wait for worker to finish time.sleep(5) assert worker.status.name == 'WAITING' assert Job.get_job_by_id(job_id).status.name == 'DONE' #make sure the file was actually copied assert os.path.exists("/export/archive1/1-johann-directory.tar")
def main(): storage = BasicFileSystemStorage(STORAGE_PARENT, use_datetime=True) with UdpConnection.create(SERVER_PORT, CLIENT_PORT, timeout=SERVER_TIMEOUT) as connection: master = Master(connection, storage) # Let's familiarize ourselves with all the clients: print('Registering clients') master.discover_clients() # Run several times (how many times we want to take pictures). for i in range(RUN_EXPERIMENT_TIMES): print('Taking picture', i) # Notify all clients to take a picture. # The id we will use to identify the image is from i connection.broadcast(CommandType.TAKE_PICTURE, TakePictureParams(i)) # Wait until next time to take a picture time.sleep(WAIT_BETWEEN_PICS_SEC) # Collect results: print('Collecting results') master.collect_pictures() print('Done')
def test_constructor(): master = Master.get_master() assert (type(master) is Master) master2 = Master.get_master() assert (master == master2)
import json from master.master import Master config = "" with open('./configuration.json', 'r') as f: config = json.load(f) master = Master(config) master.start()
def ready(self): Master() # Initialize the singleton
def server(self): return Master()