コード例 #1
0
def run_xspark(current_cluster, num_instance=c.NUM_INSTANCE, num_run=c.NUM_RUN, cluster_id=c.CLUSTER_ID, terminate=c.TERMINATE,
               run=c.RUN, reboot=c.REBOOT, assume_yes=False):
    """ Main function;
    * Launch NUMINSTANCE virtual machines
    * Run DagSymb Application
    * Download Log
    * Plot data from log
    """
    print(header('run_xspark(num_instance={}, num_run={}, cluster_id={},terminate={}, run={}, reboot={})'
          .format(num_instance, num_run, cluster_id, terminate, run, reboot)))
    ''' get cfg_file and initialize main settings'''
    with utils.open_cfg(mode='w') as cfg:
        if 'main' not in cfg:
            cfg['main'] = {}
        cfg.set('main', 'current_cluster', current_cluster)
        if 'tool_on_master' not in cfg['main']:
            cfg.set('main', 'tool_on_master', 'false')

    bench_instance = BenchInstanceFactory.get_bench_instance(c.PROVIDER, cluster_id)
    setup_ok = True

    if num_instance > 0:
        setup_ok = bench_instance.setup(num_instance, assume_yes)

    if reboot:
        bench_instance.reboot()

    if setup_ok and run:
        bench_instance.run(num_run)

    if terminate:
        bench_instance.terminate()
コード例 #2
0
def run_xspark_disabled(current_cluster,
                        num_instance=c.NUM_INSTANCE,
                        num_run=c.NUM_RUN,
                        cluster_id=c.CLUSTER_ID,
                        terminate=c.TERMINATE,
                        run=c.RUN,
                        reboot=c.REBOOT,
                        assume_yes=False):
    """ Main function;
    * Launch spot request of NUMINSTANCE
    * Run Benchmark
    * Download Log
    * Plot data from log
    """
    print(
        header(
            'run_xspark(num_instance={}, num_run={}, cluster_id={},terminate={}, run={}, reboot={})'
            .format(num_instance, num_run, cluster_id, terminate, run,
                    reboot)))
    # get cfg_file and initialize main settings
    with utils.open_cfg(mode='w') as cfg:
        if 'main' not in cfg:
            cfg['main'] = {}
        cfg.set('main', 'current_cluster', current_cluster)

    bench_instance = BenchInstanceFactory.get_bench_instance(
        c.PROVIDER, cluster_id)
    setup_ok = True

    if num_instance > 0:
        println("setup_ok = bench_instance.setup(num_instance, assume_yes)")

    if reboot:
        println("bench_instance.reboot()")

    if setup_ok and run:
        bench_instance.run(num_run)

    if terminate:
        println("bench_instance.terminate()")
コード例 #3
0
ファイル: main.py プロジェクト: DavideB/xSpark-dagsymb
def run_xspark(current_cluster,
               num_instance=NUM_INSTANCE,
               num_run=NUM_RUN,
               cluster_id=CLUSTER_ID,
               terminate=TERMINATE,
               run=RUN,
               reboot=REBOOT,
               assume_yes=False):
    """ Main function;
    * Launch spot request of NUMINSTANCE
    * Run Benchmark
    * Download Log
    * Plot data from log
    """
    print(
        header(
            'run_xspark(num_instance={}, num_run={}, cluster_id={},terminate={}, run={}, reboot={})'
            .format(num_instance, num_run, cluster_id, terminate, run,
                    reboot)))
    cfg = utils.get_cfg()
    cfg['main'] = {}
    cfg.set('main', 'current_cluster', current_cluster)
    utils.write_cfg(cfg)

    if PROVIDER == "AWS_SPOT":
        set_spot_drivers()
        cls = get_driver("ec2_spot_" + REGION.replace('-', '_'))
        driver = cls(AWS_ACCESS_ID, AWS_SECRET_KEY)
    elif PROVIDER == "AZURE":
        set_azurearm_driver()
        cls = get_driver("CustomAzureArm")
        driver = cls(tenant_id=AZ_TENANT_ID,
                     subscription_id=AZ_SUBSCRIPTION_ID,
                     key=AZ_APPLICATION_ID,
                     secret=AZ_SECRET,
                     region=CONFIG_DICT["Azure"]["Location"])

    else:
        print("Unsupported provider", PROVIDER)
        return

    if num_instance > 0:

        # Create nodes
        if PROVIDER == "AWS_SPOT":
            nodes, spot_requests = launch.launch_libcloud(
                driver, num_instance, CONFIG_DICT, cluster_id, assume_yes)

        if PROVIDER == "AZURE":
            nodes = launch.launch_libcloud(driver, num_instance, CONFIG_DICT,
                                           cluster_id, assume_yes)

        # nodes is a list of "libcloud.compute.base.Node"

        print("CHECK SECURITY GROUP ALLOWED IP SETTINGS!!!")

        # Tag nodes
        if PROVIDER == "AWS_SPOT":
            for node in nodes:
                driver.ex_create_tags(node, TAG[0])
        elif PROVIDER == "AZURE":
            for node in nodes:
                driver.ex_create_tags(
                    node, {"ClusterId": cluster_id
                           })  # was CONFIG_DICT["Azure"]["ClusterId"]

        instance_ids = [n.id for n in nodes]

        # Wait for all the nodes to become RUNNNING
        print("Waiting for nodes to run")
        launch.wait_for_running_libcloud(driver, instance_ids,
                                         copy.deepcopy(instance_ids))

        time.sleep(15)

        # Wait for all the nodes to be pingable
        print("Waiting for nodes to be pingable")
        launch.wait_ping_libcloud(driver, instance_ids,
                                  copy.deepcopy(instance_ids))

    if reboot:
        print("Rebooting instances...")

        # Retrieve running nodes
        if PROVIDER == "AWS_SPOT":
            nodes = driver.list_nodes(
                ex_filters={'instance-state-name': ['running']})
            nodes = [
                n for n in nodes
                if driver.ex_describe_tags(node)['Value'] == cluster_id
            ]
        elif PROVIDER == "AZURE":
            nodes = driver.list_nodes(
                ex_resource_group=CONFIG_DICT["Azure"]["ResourceGroup"])
            nodes = [
                n for n in nodes if n.extra["tags"]["ClusterId"] == cluster_id
            ]

        # Reboot nodes
        for node in nodes:
            driver.reboot_node(node)

        # Wait for all the nodes to be pingable
        instance_ids = [n.id for n in nodes]
        launch.wait_ping_libcloud(driver, instance_ids,
                                  copy.deepcopy(instance_ids))

    if run:
        for i in range(num_run):
            if PROVIDER == "AWS_SPOT":
                nodes = driver.list_nodes(
                    ex_filters={'instance-state-name': ['running']})
                nodes = [
                    n for n in nodes
                    if driver.ex_describe_tags(n)['Value'] == cluster_id
                ]
            elif PROVIDER == "AZURE":
                nodes = driver.list_nodes(
                    ex_resource_group=CONFIG_DICT["Azure"]["ResourceGroup"])
                nodes = [
                    n for n in nodes
                    if n.extra["tags"]["ClusterId"] == cluster_id
                ]

            # nodes is a list of "libcloud.compute.base.Node"
            print("Found {} nodes".format(len(nodes)))

            x_run.run_benchmark(nodes)

    if terminate:
        print("Begin termination of instances and cleaning")

        # Cancel Spot Request
        if PROVIDER == "AWS_SPOT" and num_instance > 0:
            for s in spot_requests:
                driver.ex_cancel_spot_instance_request(s)
            print("Spot requests cancelled")

        ###################################################

        # Retrieve running nodes
        if PROVIDER == "AWS_SPOT":
            nodes = driver.list_nodes(
                ex_filters={'instance-state-name': ['running']})
            nodes = [
                n for n in nodes
                if driver.ex_describe_tags(n)['Value'] == cluster_id
            ]
        elif PROVIDER == "AZURE":
            nodes = driver.list_nodes(
                ex_resource_group=CONFIG_DICT["Azure"]["ResourceGroup"])
            nodes = [
                n for n in nodes if n.extra["tags"]["ClusterId"] == cluster_id
            ]
        print("Found {} nodes".format(len(nodes)))

        # nodes is a list of "libcloud.compute.base.Node"

        # Destroy all nodes
        print("Destroying nodes")
        for node in nodes:
            driver.destroy_node(node)

        print(okgreen("All nodes destroyed"))
コード例 #4
0
ファイル: __init__.py プロジェクト: kursion/py_console
__all__ = ["colors"]
if __name__ == "__main__":
    import colors as console
    console.warning("Warning example")
    console.error("Error example")
    console.log("Log example")
    console.success("Success example")
    console.header("Header example")
    console.title("Title example")
コード例 #5
0
def run_cli_loop() -> None:
    '''
    This function runs the CLI input loop.
    '''
    print_cli_help()
    while True:
        colors.header()
        command = input('Enter Command: ')
        colors.endc()
        if command == 'a' or command == 'attack':
            colors.okblue()
            attacking_armies = get_int_in_bounds('Input Attacking Armies: ', 2,
                                                 1000)
            defending_armies = get_int_in_bounds('Input Defending Armies: ', 1,
                                                 1000)
            uppr = min(3, attacking_armies - 1)
            attacking_dice = 0
            if uppr > 1:
                attacking_dice = get_int_in_bounds(
                    'Input Attacking Dice [1, %d]: ' % uppr, 1, uppr)
            else:
                attacking_dice = 1
                print('Input Attacking Dice [1, %d]: 1' % uppr)
            uppr = min(2, defending_armies)
            if uppr > 1:
                defending_dice = get_int_in_bounds(
                    'Input Defending Dice [1, %d]: ' % uppr, 1, uppr)
            else:
                defending_dice = 1
                print('Input Defending Dice [1, %d]: 1' % uppr)
            colors.endc()
            while attacking_armies > 1 and defending_armies > 0:
                if attacking_armies == 3 and attacking_dice > 2:
                    attacking_dice = 2
                elif attacking_armies == 2 and attacking_dice > 1:
                    attacking_dice = 1
                if defending_armies == 1 and defending_dice > 1:
                    defending_dice = 1
                colors.warning()
                print('Attacking With %d Dice' % attacking_dice)
                print('Defending With %d Dice' % defending_dice)
                result = get_casualties(attacking_dice, defending_dice)
                attacking_armies -= result[0]
                defending_armies -= result[1]
                print('Attacker Lost: %d' % result[0])
                print('Defender Lost: %d' % result[1])
                print('Attacker Armies Remaining: %d' % attacking_armies)
                print('Defender Armies Remaining: %d' % defending_armies)
                colors.endc()
                if attacking_armies > 1 and defending_armies > 0:
                    colors.header()
                    cont = input('Continue Attacking? (Y/n): ')
                    colors.endc()
                    if cont == 'no' or cont == 'n':
                        break
            colors.okgreen()
            if defending_armies == 0:
                print('Attackers Won!')
            elif attacking_armies == 1:
                print('Attackers Repulsed!')
                savout1 = os.dup(1)
                savout2 = os.dup(2)
                os.close(1)
                os.close(2)
                try:
                    webbrowser.open('https://www.youtube.'
                                    'com/watch?v=dQw4w9WgXcQ')
                finally:
                    os.dup2(savout1, 1)
                    os.dup2(savout2, 2)
            colors.endc()
        elif command == 'q' or command == 'quit':
            break
        elif command == 'h' or command == 'help':
            print_cli_help()
        else:
            print('Unknown Command: %s' % command)
            print_cli_help()
コード例 #6
0
 def log(self, code, username):
   icon = self.LOG_ICONS.get(code, '❓')
   code = colors.header(code)
   msg = " ".join([icon, username, code, "\n"])
   for out in self.outputs:
     out.write(msg)