Ejemplo n.º 1
0
def get_vm(num_spot, num_backup):
    spot_list = []
    backup_list = []
    t = []

    for i in range(num_spot):
        new_vm = vm.VM(EC2_AMI,
                       'ec2-sample-key',
                       'ec2-sample-key.pem',
                       'ubuntu',
                       bidding=1,
                       instance_type='c4.xlarge')

        spot_list.append(new_vm)
        t.append(threading.Thread(target=launch_vm, args=(new_vm, )))

    for i in range(num_backup):
        new_vm = vm.VM(EC2_AMI,
                       'ec2-sample-key',
                       'ec2-sample-key.pem',
                       'ubuntu',
                       bidding=1,
                       instance_type='c4.xlarge')

        backup_list.append(new_vm)
        t.append(threading.Thread(target=launch_vm, args=(new_vm, )))

    for thread in t:
        thread.start()

    for thread in t:
        thread.join()

    return spot_list, backup_list
Ejemplo n.º 2
0
    def __init__(self, screen, x, y):
        self.x = x
        self.y = y
        # targeted velocity
        self.vx = 0
        self.vy = 0
        # real velocity
        self.curr_vx = 0
        self.curr_vy = 0
        self.screen = screen

        self.temp = [0, 0]
        self.vec1 = [self.VECTOR_LENGTH, 0]
        self.vec2 = multiply(self.vec1, self.I)
        self.rot = self.Rotation(16)

        self.ai_input = self.Input(self)
        self.allocate_member_functions()
        self.fuzzy_machine = vm.VM(
            {
                'dir-x': self.fdirx,
                'dir-y': self.fdiry,
                'dist': self.fdist
            }, {
                'dx': self.fdx,
                'dy': self.fdy,
                'rot': self.frot
            }, 'rule.scm')
Ejemplo n.º 3
0
    def __init__(self,
                 domid,
                 fd,
                 suspendcb=None,
                 resumecb=None,
                 checkpointcb=None,
                 interval=0,
                 flags=0):
        """Create a Saver object for taking guest checkpoints.
        domid:        name, number or UUID of a running domain
        fd:           a stream to which checkpoint data will be written.
        suspendcb:    callback invoked after guest is suspended
        resumecb:     callback invoked before guest resumes
        checkpointcb: callback invoked when a checkpoint is complete. Return
                      True to take another checkpoint, or False to stop.
        flags:        Remus flags to be passed to xc_domain_save
        """
        self.fd = fd
        self.suspendcb = suspendcb
        self.resumecb = resumecb
        self.checkpointcb = checkpointcb
        self.interval = interval
        self.flags = flags

        self.vm = vm.VM(domid)

        self.checkpointer = None
Ejemplo n.º 4
0
def vm_boot(filename="compile.rotc"):
    print "booting up VM"
    vmstate = vm.VM()
    print "VM loading %s" % filename
    vm_load(vmstate, filename)
    print "VM loading {read,write}-file extensions"
    vmstate.set_global(Symbol('read-file'), read_file)
    vmstate.set_global(Symbol('write-file'), write_file)
    return vmstate
Ejemplo n.º 5
0
    def start_vm(self, node, vmname, console):
        """Start the specified VM on the given node.
		If there is not enough ram on the given node, the VM will be started 
		on the node with the highest free ram and the autostart link will be updated accordingly.

		node - (Node) Selected host
		vmname - (String) VM hostname 
		console - (boolean) Attach console to the domain
		"""

        # Resources checks
        needed_ram = vm.VM(vmname).get_ram()
        free_ram = node.metrics.get_free_ram()
        if needed_ram > free_ram:
            # Not enough ram, switching to another node
            old_node = node

            # Get the node with the highest free ram (first fit increasing algorithm)
            pool = self.get_nodes()
            pool.sort(key=lambda x: x.metrics.get_free_ram(), reverse=True)
            node = pool[0]

            # Last resources checks
            free_ram = node.metrics.get_free_ram()
            if needed_ram > free_ram:
                raise ClusterNodeError(
                    node.get_hostname(), ClusterNodeError.NOT_ENOUGH_RAM,
                    "need " + str(needed_ram) + "M, has " + str(free_ram) +
                    "M.")

            if not core.cfg['QUIET']:
                print " -> Not enough ram, starting it on %s." % node.get_hostname(
                )

        # Start the VM
        self.activate_vm(node, vmname)
        try:
            node.start_vm(vmname)
        except Exception, e:
            node.deactivate_lv(vmname)
            raise e
Ejemplo n.º 6
0
def repl():
    """
    This function defines the debugging monkelang REPL environment. It runs 
    code with the VM class's run_once method.
    """
    machine = vm.VM([])
    duck_compiler = compiler.Compiler([], machine)

    print("DuckLang REPL :D")

    while True:
        command = input("duck> ")

        ast = duck_parser.DuckParser(command).parse()

        duck_compiler.ast = ast

        code, constant_table = duck_compiler.compile()
        
        machine.constant_table = constant_table
        machine.code = code

        machine.run_once(code)
Ejemplo n.º 7
0
if __name__ == '__main__':
    vm.VM.machine_name = sys.argv[1]
    vm.VM.adb_port = sys.argv[2]
    vm.VM.ssh_port = sys.argv[3]
    RunParameters.RUN_PKG = sys.argv[4]
    RunParameters.RUN_TIME = float(sys.argv[5])

    RunParameters.RUN_GUI = str(sys.argv[6])

    APK_FILE_NAME = sys.argv[7]

    RunParameters.OUTPUT_FILE= "../../output/"  +  "data.csv"
    RunParameters.CRASH_FILE= "../../output/" +  "crashes.log"


    machine = vm.VM(RunParameters.RUN_GUI, vm.VM.adb_port)  # headless or gui

    graph = state_graph.StateGraph()
    monkey_controller = fuzzers.MonkeyController()

    strategy = CircularRestoreStrategy(graph, 3)
    executor = Executor(machine, monkey_controller, graph, strategy, RunParameters.RUN_PKG, RunParameters.RUN_TIME)
    executor.prepare_vm()
    executor.set_app_under_test(RunParameters.RUN_PKG)
    time.sleep(3)

    if RunParameters.OPEN_SOURCE:

        os.system('adb -s ' + vm.VM.ip + ':' + vm.VM.adb_port + ' shell am instrument -e coverage true -w ' + RunParameters.RUN_PKG + '/.EmmaInstrument.EmmaInstrumentation &')
        time.sleep(5)
Ejemplo n.º 8
0
                break
            self.disconnect_adb()

        print('adb is connected!')

    def adb_wait_device(self):
        subprocess.check_call('timeout 2 adb -s ' + VM.ip + ':' + VM.adb_port +
                              '  wait-for-device',
                              shell=True)


import fuzzers
import threading
import vm

# test cases
if __name__ == "__main__":

    vm.VM.machine_name = 'Android7'
    vm.VM.tcp_port = str(6600)
    snapshotManager = vm.VM()

    snapshotManager.power_off_VM()

    snapshotManager.launchVM()
    snapshotManager.check_connect_adb()

    snapshotManager.take_snapshot('s3', "", True)

    snapshotManager.restore_snapshot("s3")
Ejemplo n.º 9
0
 def setUp(self) -> None:
     self.vm = vm.VM()