コード例 #1
0
ファイル: cluster.py プロジェクト: mx739150/ambari-app
    def load_from_json(cluster_name):
        """
        load the cluster information from json file
        :param cluster_name: the name of the cluster
        :return: a Cluster instance or None if no such cluster
        """
        data = Data()
        json_data = data.read_cluster_json(cluster_name)
        if json_data is None:
            return None

        ambari_server_vm = []
        service_server_vm_list = []
        ambari_agent_vm_list = []

        for vm_json in json_data["ambari_server_vm"]:
            ambari_server_vm.append(VM.load_from_json(vm_json))

        for vm_json in json_data["service_server_vm_list"]:
            service_server_vm_list.append(VM.load_from_json(vm_json))

        for vm_json in json_data["ambari_agent_vm_list"]:
            ambari_agent_vm_list.append(VM.load_from_json(vm_json))

        cluster = Cluster()
        cluster.cluster_name = cluster_name
        cluster.state = json_data["state"]
        cluster.create_time = json_data["create_time"]
        cluster.ambari_server_vm = ambari_server_vm
        cluster.service_server_vm_list = service_server_vm_list
        cluster.ambari_agent_vm_list = ambari_agent_vm_list
        return cluster
コード例 #2
0
ファイル: cluster.py プロジェクト: prelongs/ambari
    def generate_cluster_info(self, VM_IP_list, cluster_name, docker_num):
        config = Config()
        config.load()
        Docker_IP_base = config.ATTRIBUTES["Docker_IP_base"].split(".")
        Docker_IP_mask = config.ATTRIBUTES["Docker_IP_mask"]

        VM_index = 0
        for VM_IP in VM_IP_list:
            vm = VM(VM_IP)

            for Docker_index in range(0, docker_num):
                total_Docker_index = VM_index * docker_num + Docker_index
                docker_IP = self.__increase_IP__(Docker_IP_base,
                                                 total_Docker_index)
                docker_IP_str = str(docker_IP[0]) + "." + str(docker_IP[1]) + "." + \
                                str(docker_IP[2]) + "." + str(docker_IP[3])
                docker_hostname = cluster_name + "-" + str(
                    VM_index) + "-" + str(Docker_index)
                docker = Docker(docker_IP_str, str(Docker_IP_mask),
                                docker_hostname)
                # print docker
                vm.add_docker(docker)
            VM_index = VM_index + 1
            self.VM_list.append(vm)

        self.VMs_num = len(VM_IP_list)
        self.cluster_name = cluster_name
コード例 #3
0
ファイル: main.py プロジェクト: henrique/DistEvo
 def put(self):
  
   logging.info('put all vms received')
  
   data_string = self.request.body
   decoded = json.loads(data_string)
   decoded2 = json.dumps(decoded, indent=2)
   
   logging.info(decoded2)
  
   if decoded.has_key('vms'):
       count_vms = len(decoded['vms'])
       logging.info('count vms: '+str(count_vms))
       vms = []
       for vm in decoded['vms']:
           temp = VM(key_name=vm['ip'])
           temp.set(vm)
           temp.ip = vm['ip']
           vms.append(temp)
       
       for vm in vms:
           vm.put()
           logging.info('put vm['+vm.ip+'] into datastore')
   
   else:
       logging.info('no key vms defined')
       self.error(500)
       return
コード例 #4
0
ファイル: main.py プロジェクト: henrique/DistEvo
 def put(self):
     
     logging.info('put single vm received')
     
     data_string = self.request.body
     decoded = json.loads(data_string)
     decoded2 = json.dumps(decoded, indent=2)
     
     logging.info(decoded2)
    
     if decoded.has_key('vms'):
         count_vms = len(decoded['vms'])
         logging.info('count vms: '+str(count_vms))
         if count_vms > 1:
             logging.info("more than 1 vm, abort")
             self.error(500)
             return
         vms = []
         for vm in decoded['vms']:
             ip = self.request.remote_addr
             temp = VM(key_name=ip)
             temp.set(vm)
             temp.ip = ip
             vms.append(temp)
         
         for vm in vms:
             vm.put()
             logging.info('put vm['+vm.ip+'] into datastore')
     
     else:
         logging.info('no key vms defined')
         self.error(500)
         return                  
コード例 #5
0
ファイル: main.py プロジェクト: jbarber69/aver
def run(fp):
    program_contents = ""
    while True:
        read = os.read(fp, 4096)
        if len(read) == 0:
            break
        program_contents += read
    os.close(fp)
    program = parse(program_contents)

    i = 0
    functions = [None] * 1024
    while i < len(program):
        ops = program[i]
        opcode = int(ops[0])
        if opcode == OpCode.MAKE_FUNCTION:
            name = int(ops[1])
            params = int(ops[2])
            func, bytecodes_length = make_function(name, params, program,
                                                   i + 1)
            functions[name] = func
            i += bytecodes_length
        i += 1

    functions = [func for func in functions if func is not None]

    main_func = functions[0]
    init_frame = Frame(None, main_func, main_func.num_locals,
                       main_func.literals, main_func.stack_size)
    vm = VM(functions)
    vm.run(init_frame)
コード例 #6
0
ファイル: verify.py プロジェクト: mitra-labs/mitra-lab
def verify_tx(tx: Tx) -> None:
    compiler = Compiler()

    input_sum = sum(
        sum(outpoint.amount for outpoint in tx_input.outpoints)
        for tx_input in tx.inputs)
    output_sum = sum(output.amount for output in tx.outputs)

    if output_sum > input_sum:
        raise ValueError('Output amounts exceeds input amounts')

    for input_idx, tx_input in enumerate(tx.inputs):
        witness = tx.witnesses[input_idx]
        loop_trees = parse_loop_trees(io.BytesIO(witness.loop_trees))
        loop_stack = LoopStack(loop_trees)
        src = tx_input.bytecode.decode('ascii')
        compile_result = compiler.compile(src)
        vm = VM(loop_stack, compile_result.num_locals, witness.ram_size)
        instructions = Block(compile_result.instructions)
        instructions.run(vm)

    for preamble_idx, preamble in enumerate(tx.preambles):
        witness = tx.witnesses[len(tx.inputs) + preamble_idx]
        loop_trees = parse_loop_trees(io.BytesIO(witness.loop_trees))
        loop_stack = LoopStack(loop_trees)
        src = preamble.decode('ascii')
        compile_result = compiler.compile(src)
        vm = VM(loop_stack, compile_result.num_locals, witness.ram_size)
        instructions = Block(compile_result.instructions)
        instructions.run(vm)
コード例 #7
0
 def get_vm(self, vmid=None, **kwargs):
     '''Retrieve specific vm or all'''
     if vmid is not None:
         req = self.get_request('v1/vms/{0}'.format(vmid))
         return VM(**req.json())
     req = self.get_request('v1/vms', params=(kwargs or None))
     return list([VM(**res) for res in req.json()])
コード例 #8
0
def test_nested_loop():
    vm = VM(
        LoopStack([
            LoopTree.CARTESIAN(3, [
                LoopTree.LEAF(3),
                LoopTree.LEAF(5),
            ]),
        ]),
        num_locals=0,
        ram_size=0,
    )
    ins = InsLoopSpecified(
        Block([
            InsLoopSpecified(
                Block([
                    InsArith([0], True, ArithMode.CHECKED, lambda n: n - 1),
                ])),
            InsLoopSpecified(
                Block([
                    InsArith([0], True, ArithMode.CHECKED, lambda n: n + 1),
                ])),
            InsArith([0], True, ArithMode.CHECKED, lambda n: n * 2),
        ]))
    ins.run(vm)
    result = vm.belt().get_num(0).value.expect_int()
    assert result == 28
コード例 #9
0
ファイル: parser.py プロジェクト: bastiak/labtool
def validateBuild(args):

    available_build_actions = ("branch", "patch", "origin")

    action = args.build[0]

    if args.install and (args.install[1] == "repo" or args.install[1] == "develrepo"):
        raise Exception(
            "First building IPA from sources and then " "installing it from repo makes no sense. " "Think about it."
        )

    if action not in available_build_actions:
        raise ValueError("Unknown build action: {s}. Choose either branch " "or patch.".format(s=action))

    if action == "patch":
        show("Checking whether all given patches exist.")
        vm = VM(locals.NFS_VM, locals.DOMAIN, None, None)

        patches_exist = True

        for patch_id in args.build[1:]:
            num = vm.cmd("bash labtool/ipa-fun-get-patch-name.sh %s" % patch_id, allow_failure=True, silent=True)

            if num != 0:
                show("Inappropriate number of patches matching %s" % patch_id)
                patches_exist = False

            if not patches_exist:
                raise ValueError("One of the given patches could not be " "determined.")

        show("Patch check successful.")
        vm.close()

    elif action == "branch":
        pass  # check that such branch indeed exists
コード例 #10
0
def vm_addons():
    data = {}
    payload = request.get_json()
    logging.debug(payload)

    field = {'Address', 'Username', 'Passwd', 'Port', 'Addons'}
    if field - set(payload.keys()):
        error_msg = "Input json missing some field! " + "It must include " + str(
            field)
        logging.error(error_msg)
        return jsonify({"error": error_msg}), 400
    else:
        try:
            vm = VM(payload['Address'],
                    payload['Username'],
                    payload['Passwd'],
                    "",
                    port=payload['Port'],
                    addons=payload['Addons'])
            logging.info("VM install addons " + str(vm.addons))
            vm.install_addons()
            logging.info("VM install addons done")
        except Exception as e:
            logging.error(str(e))
            return jsonify({"error": str(e)}), 500

    return jsonify(data), 200
コード例 #11
0
 def test_input(self):
     ops =[9, 32768, 32769, 4, 19, 32768]
 #   - Store into register 0 the sum of 4 and the value contained in register 1.
 #   - Output to the terminal the character with the ascii code contained in register 0.
     vm = VM(ops)
     vm.r[1] = 65
     vm.run()
     self.assertEqual(vm.r[0], vm.r[1] + 4)
コード例 #12
0
ファイル: __init__.py プロジェクト: kwrobert/pyzerto
 def get_vm(self, vmid=None, **kwargs):
     '''Retrieve specific vm or all'''
     if vmid is not None:
         req = self.get_request('v1/vms/{0}'.format(vmid))
         return VM(**req.json())
     # Get protected VMs
     prot_vms = self.get_request('v1/vms', params=(kwargs or None))
     return [VM(**vm_resp) for vm_resp in prot_vms.json()]
コード例 #13
0
def _api_call(sm: VM):
    _b = get_next_byte(sm)
    _args = get_next_byte(sm, 2)
    args = [sm.pop() for _ in range(_args)]
    fun = sm.get_data_at(_b)
    f = FUNCTIONS[fun]
    f(*args)
    [sm.push(i) for i in args]
コード例 #14
0
def do_pt1():
    with open('input') as f:
        intcode = f.read()
    intcode = VM.sanitise_memory(intcode)
    intcode[1] = 12
    intcode[2] = 2
    vm = VM()
    print(vm.compute(intcode))
コード例 #15
0
 def __init__(self, sql_string):
     self.sql_string_array = sql_string.split()
     self.statement_type = self.sql_string_array[0]
     self.command_executions = {
         'insert': self.handle_insert_command,
         'select': self.handle_select_command
     }
     self.vm = VM()
コード例 #16
0
ファイル: cluster.py プロジェクト: mx739150/ambari-app
    def generate_cluster_info(self, cluster_name, ambari_server_fqdn_ip_pairs, service_server_fqdn_ip_pairs,
                              ambari_agent_fqdn_ip_pairs, docker_num):
        """
        generate VM and docker info for this cluster
        set up parameter of the class instance as this info
        :param cluster_name: the name of the cluster
        :param ambari_server_fqdn_ip_pairs: the domain name and IP pairs for Ambari-server
        :param service_server_fqdn_ip_pairs: the domain name and IP pairs for VMs with Ambari-agent installed
        :param ambari_agent_fqdn_ip_pairs: the domain name and IP pairs for VM with Docker containers
        :param docker_num: the number of Dockers inside each VMs
        :return: None
        """
        weave_ip_base = Config.ATTRIBUTES["weave_ip_base"]
        weave_ip_mask = Config.ATTRIBUTES["weave_ip_mask"]
        current_ip = weave_ip_base

        for vm_domain_name, vm_ip in ambari_server_fqdn_ip_pairs:
            current_ip = self._increase_ip(current_ip, 1)
            weave_dns_ip = current_ip
            vm = VM(vm_ip, vm_domain_name, weave_dns_ip, weave_ip_mask)
            current_ip = self._increase_ip(current_ip, 1)
            vm.weave_internal_ip = current_ip
            self.ambari_server_vm.append(vm)

        for vm_domain_name, vm_ip in service_server_fqdn_ip_pairs:
            current_ip = self._increase_ip(current_ip, 1)
            weave_dns_ip = current_ip
            vm = VM(vm_ip, vm_domain_name, weave_dns_ip, weave_ip_mask)
            current_ip = self._increase_ip(current_ip, 1)
            vm.weave_internal_ip = current_ip
            self.service_server_vm_list.append(vm)

        vm_index = 0
        for vm_domain_name, vm_ip in ambari_agent_fqdn_ip_pairs:
            current_ip = self._increase_ip(current_ip, 1)
            weave_dns_ip = current_ip
            vm = VM(vm_ip, vm_domain_name, weave_dns_ip, weave_ip_mask)

            for docker_index in range(0, docker_num):
                current_ip = self._increase_ip(current_ip, 1)
                docker_ip_str = current_ip

                total_docker_index = vm_index * docker_num + docker_index
                docker_domain_name = Docker.get_weave_domain_name(cluster_name, total_docker_index)

                docker = Docker(docker_ip_str, str(weave_ip_mask), docker_domain_name)
                vm.add_docker(docker)

            vm_index += 1
            self.ambari_agent_vm_list.append(vm)

        self.cluster_name = cluster_name
        self.create_time = str(datetime.datetime.now())
        self.state = Cluster.STATE_FREE

        # update config file.
        # This step makes the user avoid reconfiguring the IP for next cluster creation
        Config.update("weave", "weave_ip_base", current_ip)
コード例 #17
0
ファイル: interrupt.py プロジェクト: lunacik/os
    def run(self):
        #wrong operation
        if(RM.PI == 1):
            print("wrong operation in ", RM.current_vm.PAGE)
            Interrupt.kill_vm()   
        #division by zero
        elif(RM.PI == 2):
            print("division by zero in ", RM.current_vm.PAGE)
            Interrupt.kill_vm()
        #error while loading user's program
        elif(RM.PI == 3):
            print("error while trying to load ", Load.filename)
        #success loading user's program
        elif(RM.PI == 4):
            Process.find_by_name("Main").state = State.READY
        #test
        elif(RM.PI == 5):
            Process.find_by_name("Load").state = State.READY
        #perhaps those two will be optional
        if(RM.SI == 1):
            pass
        #read
        elif(RM.SI == 2):
            pass
        #halt
        elif(RM.SI == 3):
            RM.current_vm.state = State.FINISHED
            RM.current_vm = None
            RM.TI = 0
        #watchdog
        elif(RM.SI == 4):
            Interrupt.kill_vm()
        #timer
        if(RM.TI == 0):
            #get all active vms
            vms = VM.get_active()
            #for vm in vms:
            #    print(vm, "   ", vm.PAGE)
            if vms != []:
                #this vm already worked
                vms[0].state = State.BLOCKED
                #rotate vms list
                VM.rotate()
                #make first ready
                vms[0].state = State.READY
                #set timer for vm
                RM.TI = TIMER_PERIOD
                #turn on watchdog
                Process.find_by_name("Watchdog").state = State.READY
            else:
                #no need to use watchdog if there is no user's programs
                Process.find_by_name("Watchdog").state = State.BLOCKED

        #clear
        RM.PI = 0
        RM.SI = 0
        self.state = State.READY
コード例 #18
0
 def run(self, vm: VM) -> Optional[Break]:
     for _ in range(self._num_loops):
         br = self._block.run(vm)
         if br is not None:
             if br.depth == 0 and br.is_continue:
                 vm.loop_stack().continue_loop()
                 continue
             vm.loop_stack().break_loop()
             return br
コード例 #19
0
ファイル: node.py プロジェクト: nagius/cxm
	def get_vm(self, vmname):
		"""Return the VM instance corresponding to the given vmname."""
		try:
			uuid=self.server.xenapi.VM.get_by_name_label(vmname)[0]
		except IndexError:
			raise NotRunningVmError(self.get_hostname(),vmname)
		vm_rec=self.server.xenapi.VM.get_record(uuid)
		vm=VM(vm_rec['name_label'],vm_rec['domid'])
		vm.metrics=self.server.xenapi.VM_metrics.get_record(vm_rec['metrics'])
		return vm
コード例 #20
0
class Eval:
    def __init__(self):
        self.vm = VM()

    def eval(self, expr):
        compiled_expr = compile(expr)
        print("compiled_expr:", compiled_expr)
        self.vm.reg.x = compiled_expr
        self.vm.run()
        return self.vm.reg.a
コード例 #21
0
 def run(self, vm: VM) -> Optional['Break']:
     a_num = vm.belt().get_num(self._a_idx)
     b_num = vm.belt().get_num(self._b_idx)
     a = a_num.to_signed(self._is_signed).to_int()
     b = b_num.to_signed(self._is_signed).to_int()
     if a is None or b is None:
         vm.belt().push(BeltNum(DataType.I8, Integer(None)))
     else:
         result = self._op(a, b)
         vm.belt().push(BeltNum(DataType.I8, Integer(int(result))))
     return None
コード例 #22
0
ファイル: node.py プロジェクト: sorinros/cxm
 def get_vm(self, vmname):
     """Return the VM instance corresponding to the given vmname."""
     try:
         uuid = self.server.xenapi.VM.get_by_name_label(vmname)[0]
     except IndexError:
         raise NotRunningVmError(self.get_hostname(), vmname)
     vm_rec = self.server.xenapi.VM.get_record(uuid)
     vm = VM(vm_rec['name_label'], vm_rec['domid'])
     vm.metrics = self.server.xenapi.VM_metrics.get_record(
         vm_rec['metrics'])
     return vm
コード例 #23
0
ファイル: test_vm.py プロジェクト: koder-ua/vm_ut
def test_vm_starts():
    """
    starts vm
    creates folder on it with ssh
    and checks
    """
    vm = VM("oneiric")
    with vm.start():
        cmd = SSHCMDExecutor(vm.ip, vmuser, vmpass)
        cmd.exec_simple("mkdir /%s" % some_dir)
        tdirname = os.path.join(vm.fs.mpoint, some_dir)
        ok_(os.path.exists(tdirname))
コード例 #24
0
ファイル: __main__.py プロジェクト: ggm/vm-for-transfer
def main():
    vm = VM()

    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "c:i:o:gh", ["codefile=", "inputfile=", "outputfile=", "debug", "help"]
        )
    except getopt.GetoptError as error:
        print(error)
        exit()
    # Go through the options, initializing and configuring the vm.
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            exit()
        elif opt in ("-c", "--codefile"):
            try:
                codeFile = open(arg, mode="rt", encoding="utf-8")
                header = codeFile.readline()
                if not vm.setLoader(header, codeFile):
                    print("The header of the file {} is not recognized:".format(arg))
                    print(header)
                    sys.exit(2)

                transferHeader = codeFile.readline()
                vm.setTransferStage(transferHeader)
            except IOError as ioe:
                print(ioe)
                sys.exit(2)
        elif opt in ("-i", "--inputfile"):
            try:
                vm.input = open(arg, mode="rt", encoding="utf-8")
            except IOError as ioe:
                print(ioe)
                sys.exit(2)
        elif opt in ("-o", "--outputfile"):
            try:
                vm.output = open(arg, mode="wb")
            except IOError as ioe:
                print(ioe)
                sys.exit(2)
        elif opt in ("-g", "--debug"):
            vm.setDebugMode()

    # If a code file isn't supplied, there won't be any loader so we end.
    if vm.loader is None:
        exit()

    vm.run()

    sys.exit(0)
コード例 #25
0
def test_simple_loop():
    vm = VM(
        LoopStack([
            LoopTree.LEAF(8),
        ]),
        num_locals=0,
        ram_size=0,
    )
    ins = InsLoopSpecified(
        Block([
            InsArith([0], False, ArithMode.CHECKED, lambda n: n + 1),
        ]))
    ins.run(vm)
    result = vm.belt().get_num(0).value.expect_int()
    assert result == 8
コード例 #26
0
ファイル: compile.py プロジェクト: TheAnosmic/cheetahs_byte
def compile_from_string(string,
                        allowed_opcodes=None):
    """
    :param allowed_opcodes: from opcode_pack
    """
    allowed_opcodes = allowed_opcodes or \
                      OPCode.get_all_opcodes()
    vm = VM()
    print_opcodes = filter(lambda op:
                           issubclass(op, PrintOPCode),
                           allowed_opcodes)
    jump_opcodes = filter(lambda op:
                          issubclass(op, JumpOPCodes),
                          allowed_opcodes)
    nc = string_to_prt_opcodes(string, print_opcodes, vm)
    atoms = break_to_atoms(nc)
    if NOP in allowed_opcodes:
        add_random_nops(atoms)
    atoms.append(NodeChain(HLT()))
    if jump_opcodes:
        atoms = add_jmp_opcodes(atoms, jmp_opcode_classes=jump_opcodes)
        atoms = shuffle(atoms)
    nc = make_chain_from_atoms(atoms)
    link_to_real_address(nc)
    return nc
コード例 #27
0
ファイル: node.py プロジェクト: sorinros/cxm
    def check_missing_lvs(self):
        """
		Perform a check on logicals volumes used by VMs. 
		Return False if some are missing.
		"""
        log.info("Checking for missing LV...")
        safe = True

        # Get all LVs used by VMs
        used_lvs = list()
        for vm in self.get_possible_vm_names():
            used_lvs.extend(VM(vm).get_lvs())

        # Get all existent LVs
        existent_lvs = list()
        for line in self.run("lvs -o vg_name,name --noheading").readlines():
            (vg, lv) = line.strip().split()
            existent_lvs.append("/dev/" + vg + "/" + lv)

        # Compute missing LVs
        missing_lvs = list(Set(used_lvs) - Set(existent_lvs))
        if len(missing_lvs):
            log.info(" ** WARNING : Found missing LV :\n\t",
                     "\n\t".join(missing_lvs))
            safe = False

        return safe
コード例 #28
0
def do_pt2():
    with open('input') as f:
        clean_intcode_str = f.read()
    # intcode = VM.sanitise_memory(intcode)
    vm = VM()
    for i in range(0, 100):  # noun
        # print('trying noun = {0}, verb = '.format(i), end='')
        for j in range(0, 100):  # verb
            # print("{0}, ".format(j), end='')
            intcode = VM.sanitise_memory(clean_intcode_str)
            intcode[1] = i
            intcode[2] = j
            if vm.compute(intcode) == 19690720:
                print('found! noun: {0}, verb: {1}'.format(i, j))
                print('answer: 100 * noun + verb = {0}'.format(100 * i + j))
                break
コード例 #29
0
ファイル: random.py プロジェクト: aspiers/migrationpaths
def identical_hosts(num_hosts=10, max_vms=None,
                    min_vm_ram=None, max_vm_ram=None):
    VM.reset()
    VMhost.reset()

    stateA = VMPoolState()
    vmhosts = testcases.utils.create_vmhosts(num_hosts, 'x86_64', 4096, 280)
    for vmhost in vmhosts:
        stateA.init_vmhost(vmhost.name)

    randomly_populate_hosts(stateA, max_vms,
                            min_vm_ram=min_vm_ram,
                            max_vm_ram=max_vm_ram)
    stateB = randomly_shuffle(copy.copy(stateA))

    return (stateA, stateB, "no idea what path to expect!")
コード例 #30
0
def info(user, password, machine, mongo, dt_string):
    server= machine["name"]
    owner = machine["owner"]
    print("working on server " + server)
    
    resource = Resources(server, owner, dt_string)
    conn = Connection(server, user, password)
    try:
        pythoncom.CoInitialize()
        conn.register_physical()
    except Exception as e:
        print("connection issues with physical namespace " + server)
        print(e)
        mongo.update("systems", {"server": server}, json.loads(str(resource)))
        return

    resource.physical_properties = PhysicalProperties(conn.physical_connection, get_login=True)
    print("got physical info of " + server)
    
    try: 
        conn.register_virtual()
        resource.virtual_properties = VirtualProperties(conn.virtual_connection)
        for vm in resource.virtual_properties.vms_list:
            v = VM(conn.virtual_connection, vm)
            resource.virtual_properties.register_vm(v)     
        print("got virtual info of " + server)   
        resource.physical_properties.virtualization =  resource.virtual_properties.virtualization
    except Exception as e:
        resource.physical_properties.virtualization = "disabled"
        print("Did not find virtual namespace on " + server)
        print(e)
    #print(resource)
    mongo.update("systems", {"server": server}, json.loads(str(resource)))
コード例 #31
0
def solve():
    prev_first_x = 0
    rows = []
    for y in count(500):
        first_x = None
        if prev_first_x == None:
            prev_first_x = 0
        x = prev_first_x
        while True:
            inputs = deque([x, y])
            vm = VM(ns, inputs)
            output = next(vm)
            if output:
                if first_x == None:
                    first_x = x
                    if rows:
                        x = rows[-1][1] - 1
            else:
                if first_x != None:
                    rows.append((first_x, x))
                    if len(rows) > 100:
                        smallest_x = rows[-1][0]
                        biggest_x = rows[-100][1]
                        if biggest_x - smallest_x >= 100:
                            return smallest_x * 10000 + y - 100 + 1
                    break
            x += 1
        prev_first_x = first_x
コード例 #32
0
ファイル: backend.py プロジェクト: tbabej/labtool
    def load_vm(self, name):

        show('Loading VM %s' % name)
        self.get_domain(name)  # this fails if VM does not exist

        # TODO: check that it started, if not, wait
        self.start(name)

        # TODO: need a proper retry function
        ip = None
        timeout = 0

        while ip is None:
            ip = self.get_ip(name)
            sleep(2)
            timeout += 2

            if timeout > 20:
                raise RuntimeError("Could not determine IP of VM %s" % name)

        hostname = util.normalize_hostname(ip)
        show('IP determined: %s' % ip)

        return VM(name=name, backend=self, hostname=hostname,
                  domain=locals.DOMAIN, ip=ip)
コード例 #33
0
class Interpreter:
    def __init__(self):
        #The VM is the only thing that persists throughout running chunks of code
        #The lexer and parser are better off refershing line numbers and such when
        #made to run on a new chunk of code
        self.vm = VM()

    def run(self, code):
        #First we scan for tokens
        scanner = lexer.Scanner(code.upper())
        tokens = scanner.scanTokens()
        #We use None as a way to return Errors
        if (tokens == None):
            print("Lexical error encountered. Not executing")
            return

        #Next we parse the tokens we've generated into trees
        parser = parsing.Parser(tokens)
        trees = parser.parse()
        if (trees == None):
            print("Parsing error encountered. Not executing")
            return

        #The next section forms a middle end, that changes the not so assembly code so far
        #into proper assembly code that the actual transputer would be able to handle

        #We should check for any prefix errors that may come up and be undetecable
        #at run time after we expand out illegal operands in the expansion step

        prefixChanger = prefixChecking.PrefixPreparer(trees)
        trees = prefixChanger.prepare()
        if (trees == None):
            print("Illegal prefix sequence encountered. Not executing")
            return

        #Then we use an expander to expand out double length instructions
        #And operands longer than 4 bits
        #We also check if there is any overflow when expanding out jumps

        expander = expanding.Expander(trees)
        trees = expander.expand()
        if (trees == None):
            print("Ran into a problem while correcting Jumps. Not executing")
            return

        #After this we're ready to interpret!
        self.vm.run(trees)
コード例 #34
0
ファイル: node.py プロジェクト: maddingue/cxm
	def get_vm(self, vmname):
		"""Return the VM instance corresponding to the given vmname."""
		if core.cfg['USESSH']:
			line=self.run("xm list | grep " + vmname + " | awk '{print $1,$2,$3,$4;}'").read()
			if len(line)<1:
				raise ClusterNodeError(self.get_hostname(),ClusterNodeError.VM_NOT_RUNNING,vmname)
			(name, id, ram, vcpu)=line.strip().split()
			return VM(name, id, ram, vcpu)
		else:
			try:
				uuid=self.server.xenapi.VM.get_by_name_label(vmname)[0]
			except IndexError:
				raise ClusterNodeError(self.get_hostname(),ClusterNodeError.VM_NOT_RUNNING,vmname)
			vm_rec=self.server.xenapi.VM.get_record(uuid)
			vm=VM(vm_rec['name_label'],vm_rec['domid'])
			vm.metrics=self.server.xenapi.VM_metrics.get_record(vm_rec['metrics'])
			return vm
コード例 #35
0
 def run(self, vm: VM) -> Optional['Break']:
     param_nums = [vm.belt().get_num(idx) for idx in self._param_indices]
     params = [
         num.to_signed(self._is_signed).to_int() for num in param_nums
     ]
     data_type = functools.reduce(DataType.promote,
                                  (param.data_type for param in param_nums))
     if any(param is None for param in params):
         vm.belt().push(BeltNum(data_type, Integer(None)))
     else:
         results = self._op(data_type, *params)
         for result in reversed(results):
             vm.belt().push(
                 BeltNum.from_signed(Integer(result),
                                     data_type,
                                     is_signed=self._is_signed))
     return None
コード例 #36
0
 def run(self, vm: VM) -> Optional['Break']:
     a_num = vm.belt().get_num(self._a_idx)
     b_num = vm.belt().get_num(self._b_idx)
     a = a_num.to_signed(self._is_signed).to_int()
     b = b_num.to_signed(self._is_signed).to_int()
     if a is None or b is None or not self._op(a, b):
         raise ValueError('Verify failed')
     return None
コード例 #37
0
ファイル: wspace.py プロジェクト: 0x55aa/python-whitespace
def execute(filename):
    try:
        f = open(filename)
    except:
        print_msg("open file error\n", abort=True)
    text = f.read()
    f.close()
    token = tokenizer(text)
    parser = Parser(token)
    instruction = parser.parse()
    #print repr(text)
    #print instruction

    vm = VM(instruction)
    vm.run()

    return text
コード例 #38
0
 def __init__(self, _id, _label, _isHost=False):
     Component.__init__(self, _id, _label)
     self.compType = CompType.DEVICE
     self.isHost = _isHost
     self.VMs = []
     if _isHost:
         self.VMs = [VM(self.id) for x in range(cfg.VMsInHost)]
     self.links = []
コード例 #39
0
def test_simple_loop_break():
    vm = VM(
        LoopStack([
            LoopTree.LEAF(8),
        ]),
        num_locals=0,
        ram_size=0,
    )
    ins = InsLoopSpecified(
        Block([
            InsBrIf(condition_idx=0, br_depth=1),
            InsArith([2], False, ArithMode.CHECKED, lambda n: n + 1),
            InsConst(BeltNum(DataType.I8, Integer(3))),
            InsRel(a_idx=0, b_idx=1, is_signed=False, op=lambda a, b: a < b),
        ]))
    ins.run(vm)
    belt = [vm.belt().get_num(i).value.expect_int() for i in range(Belt.SIZE)]
    assert belt == [1, 3, 4, 0, 3, 3, 0, 3, 2, 0, 3, 1, 0, 0, 0, 0]
コード例 #40
0
 def run(self, vm: VM) -> Optional['Break']:
     if vm.belt().get_num(self._condition_idx).value.expect_int():
         block = self._then_block
     else:
         block = self._else_block
     br = block.run(vm)
     if br is not None and br.depth == 0 and br.is_continue:
         raise ValueError('Cannot continue if/else/end block')
     return br
コード例 #41
0
ファイル: node.py プロジェクト: maddingue/cxm
	def get_vms(self):
		"""Return the list of VM instance for each running vm."""
		vms=list()
		if core.cfg['USESSH']:
			for line in self.run("xm list | awk '{print $1,$2,$3,$4;}' | tail -n +3").readlines():
				(name, id, ram, vcpu)=line.strip().split()
				vms.append(VM(name, id, ram, vcpu))
		else:
			dom_recs = self.server.xenapi.VM.get_all_records()
			dom_metrics_recs = self.server.xenapi.VM_metrics.get_all_records()
			if core.cfg['DEBUG']: print "DEBUG Xen-Api: ", dom_recs

			for dom_rec in dom_recs.values():
				if dom_rec['name_label'] != "Domain-0":
					vm=VM(dom_rec['name_label'],dom_rec['domid'])
					vm.metrics=dom_metrics_recs[dom_rec['metrics']]
					vms.append(vm)

		return vms
コード例 #42
0
ファイル: node.py プロジェクト: nagius/cxm
		def _get_vms():
			vms=list()
			dom_recs = self.server.xenapi.VM.get_all_records()
			dom_metrics_recs = self.server.xenapi.VM_metrics.get_all_records()
			log.debug("[API]", self.hostname, "dom_recs=", dom_recs)
			log.debug("[API]", self.hostname, "dom_metrics_recs=", dom_metrics_recs)

			for dom_rec in dom_recs.values():
				if dom_rec['name_label'] == "Domain-0":
					continue # Discard Dom0
				if dom_rec['name_label'].startswith("migrating-"):
					continue # Discard migration temporary vm
				if dom_rec['power_state'] == "Halted":
					# power_state could be: Halted, Paused, Running, Suspended, Crashed, Unknown
					continue # Discard non instantiated vm

				vm=VM(dom_rec['name_label'],dom_rec['domid'])
				vm.metrics=dom_metrics_recs[dom_rec['metrics']]
				vms.append(vm)

			return vms
コード例 #43
0
ファイル: interpreter.py プロジェクト: MrHamdulay/myjvm
class Interpreter:
    def __init__(self, initial_class, classpath):
        self.initial_class_name = initial_class
        self.vm = VM(classpath)

    def start(self):
        self.vm.class_loader.load_jar('klasses/rt.jar')
        self.vm.warmup()
        # initialise klass
        klass = self.vm.load_class(self.initial_class_name)
        self.vm.frame_stack[0].push('java')

        # run initial method
        self.vm.run_method(klass, klass.get_method('main', '([Ljava/lang/String;)V')[1])
        self.vm.run_bytecode()
コード例 #44
0
ファイル: main.py プロジェクト: henrique/DistEvo
    def get(self):
        self.response.headers['Content-Type'] = 'application/json'
        logging.info("get single vm received")
        
        # GET VM with same request.remote_addr
        q = VM.all()
        q.filter("ip =", self.request.remote_addr)

        vm = q.get()
        if vm == None:
            logging.info('no vm found for this ip: '+str(self.request.remote_addr)+', abort')
            self.error(204)
            return
        
        l = { 'vms': [vm.getJSON()]}
        content = json.dumps(l, indent=2)
        # logging.info(content)
        self.response.out.write(content)
コード例 #45
0
ファイル: tests.py プロジェクト: gnulnx/vagabond
    def test_halt_after_poweroff(self):
        # Bring up a VM and test power off by call poweroff on instance
        self.vm = self._vm_factory('halt_test')
        self.vm.poweroff()

        # test that you can't halt a powered off machine
        self.vm.halt()  
        
        #clean up the machine
        self.vm.unregistervm()

        # Bring up a VM and test poweroff with command line parameters
        self.vm = self._vm_factory('halt_test')
        kwargs = {
            'subparser_name': 'destroy',
            'force': False,
            'TEST': self.TEST
        }
        self.vm = VM(**kwargs)
コード例 #46
0
ファイル: tests.py プロジェクト: gnulnx/vagabond
    def test_barebones_init(self):
        project_name='virtual_machine_1'
        self.kwargs.update({
            'subparser_name':'init', 
            'force':True, 
            'project-name':project_name, 
        })

        vm = VM(**self.kwargs)
        self.assertEqual(vm.RET['STATUS'], 'SUCCESS')
        
        self.assertTrue(os.path.isdir(project_name))

        # Check that we have to be in correct directory
        self.assertRaises(IOError, vm.readVagabond)

        hold_dir = os.getcwd()
        os.chdir(project_name)
        vm.readVagabond() 
        config = vm.config
        self.assertEqual(vm.config_version, API_VERSION)
        
        # confirm that that config has a vm section
        self.assertTrue(config.get('vm'))

        # Confirm that the defaults are correct
        vm = config.get('vm')
        self.assertEqual('hashicopy/precise64',  vm.get('box'))
        self.assertEqual(None,  vm.get('iso'))

        self.assertEqual(project_name, vm.get('hostname'))
        
        # Now go back to parent directory and try again to see errors
        os.chdir(hold_dir)

        # Now test that trying to create the project again without --force throws errors
        self.kwargs.update({'force':False})
        self.assertRaises(VagabondError, VM, **self.kwargs)
        
        self.kwargs.update({'force':True})
        vm = VM(**self.kwargs)

        project_path=os.path.abspath(project_name)
        shutil.rmtree(project_path)
        self.assertFalse(os.path.isdir(project_path))
コード例 #47
0
ファイル: tests.py プロジェクト: gnulnx/vagabond
    def test_halt(self):
        # Test halt by calling the halt() method on an instantiated vm
        self.vm = self._vm_factory('halt_test')
        self.vm.halt()

        # Test calling halt on a halted vm.
        self.vm.halt()

        # Test that you can't poweroff a halted machine
        self.vm.poweroff()

        # Bring the vm back up.
        # and call halt with command line parameters
        self.vm.up()
        kwargs = {
            'subparser_name': 'halt',
            'force': False,
            'TEST': self.TEST
        }
        self.vm = VM(**kwargs)
コード例 #48
0
ファイル: run.py プロジェクト: noriok/pdp11
def run(bytes, mode):
    data = Data(bytes[16:])

    isdump = mode == MODE_DUMP
    offset = 0
    text_bytes = bytes[16:] # テキストデータ
    vm = VM(text_bytes)
    # TODO:dumpとrunは分ける。
    while data.has_more_elements():
        pc = vm.pc()
        op = (text_bytes[pc+1] << 8) | text_bytes[pc]
        print("pc:", pc, hex(pc), "op:", op, oct(op), hex(op))

        # ダンプ用
        d = opcode.dispatch(op, data, MODE_DUMP, vm)
        print("dump:", d)
        # ダンプするとpcが書き換わるので、元に戻す
        vm.set_pc(pc)
        
        d = opcode.dispatch(op, data, mode, vm)


        vm.dump_reg()
コード例 #49
0
    reference = None
    cpu = CY16()
    data = [[0x1e,0x7a],[0xfe,0x146],[0x8a8,0xa6e]]

    for opt,param in opts[0]:
        if opt in ("-h","--help"):
            usage(0)
        elif opt in ("-t","--test"):
            test = True
        elif opt in ("-c","--cpu"):
            if param == "cy16":
                cpu = CY16()
                # information that should be considered as data and not opcode
                data = [[0x1e,0x7a],[0xfe,0x146],[0x8a8,0xa6e]]
            elif param == "vm":
                cpu = VM()
                data = []
            else:
                print "Unknown cpu"
                usage(1)
        elif opt in ("-g","--graphic"):
            graphic = param
        elif opt in ("-b","--graphic-bloc"):
            block_graphic = param
        elif opt in ("-o","--offset"):
            offset = int(param)
        elif opt in ("-x","--disassemble"):
            disassemble = True
        elif opt in ("-d","--debuguer"):
            debugguer = True
        elif opt in ("-r","--reference"):
コード例 #50
0
ファイル: test_vm.py プロジェクト: koder-ua/vm_ut
def test_vm_rollbacks_after_test1():
    vm = VM("oneiric")
    with vm.start():
        tdirname = os.path.join(vm.fs.mpoint, some_dir)
        SSHCMDExecutor(vm.ip, vmuser, vmpass)
        ok_(not os.path.exists(tdirname))
コード例 #51
0
ファイル: tests.py プロジェクト: gnulnx/vagabond
 def test_show_valid_os_types(self):
     ostypes = VM.show_valid_os_types()      
     self.assertEqual(ostypes, OSTYPES)
コード例 #52
0
ファイル: tests.py プロジェクト: gnulnx/vagabond
class TestVMActions(unittest.TestCase):

    def setUp(self):
        self.TEST=True
        
        self.kwargs = {
            'TEST': self.TEST,
        }

        # Make sure the previous test directory is removed
        if os.path.isdir(TEST_ROOT):
            shutil.rmtree(TEST_ROOT)

        # Create a new test directory
        os.mkdir(TEST_ROOT)

        self.vm = None

    def tearDown(self):     
        print "\n** tearDown ** "
        if self.vm:
            self.vm.halt()
            self.vm.unregistervm()

        # Now remove the root testing directory
        shutil.rmtree(TEST_ROOT)

    def _vm_factory(self, project_name):
        # Return to the root test directory
        os.chdir(TEST_ROOT)
        self.kwargs.update({
            'subparser_name':'init',
            'force':True,
            'project-name':project_name,
            'iso':os.path.expanduser('~/Downloads/ubuntu-14.04.1-server-i386.iso')
        })
        VM(**self.kwargs)

        os.chdir(project_name)
        kwargs = {
            'subparser_name': 'up',
            'force': True,
            'hard_force': False,
            'TEST': self.TEST
        }
        vm = VM(**kwargs)
        time.sleep(3)
    
        return vm
    

    def test_startvm(self): 
        self.vm = self._vm_factory('start_test')
        #Should be warning
        self.vm.up()

    def test_halt(self):
        # Test halt by calling the halt() method on an instantiated vm
        self.vm = self._vm_factory('halt_test')
        self.vm.halt()

        # Test calling halt on a halted vm.
        self.vm.halt()

        # Test that you can't poweroff a halted machine
        self.vm.poweroff()

        # Bring the vm back up.
        # and call halt with command line parameters
        self.vm.up()
        kwargs = {
            'subparser_name': 'halt',
            'force': False,
            'TEST': self.TEST
        }
        self.vm = VM(**kwargs)

    def test_barebones_init(self):
        project_name='virtual_machine_1'
        self.kwargs.update({
            'subparser_name':'init', 
            'force':True, 
            'project-name':project_name, 
        })

        vm = VM(**self.kwargs)
        self.assertEqual(vm.RET['STATUS'], 'SUCCESS')
        
        self.assertTrue(os.path.isdir(project_name))

        # Check that we have to be in correct directory
        self.assertRaises(IOError, vm.readVagabond)

        hold_dir = os.getcwd()
        os.chdir(project_name)
        vm.readVagabond() 
        config = vm.config
        self.assertEqual(vm.config_version, API_VERSION)
        
        # confirm that that config has a vm section
        self.assertTrue(config.get('vm'))

        # Confirm that the defaults are correct
        vm = config.get('vm')
        self.assertEqual('hashicopy/precise64',  vm.get('box'))
        self.assertEqual(None,  vm.get('iso'))

        self.assertEqual(project_name, vm.get('hostname'))
        
        # Now go back to parent directory and try again to see errors
        os.chdir(hold_dir)

        # Now test that trying to create the project again without --force throws errors
        self.kwargs.update({'force':False})
        self.assertRaises(VagabondError, VM, **self.kwargs)
        
        self.kwargs.update({'force':True})
        vm = VM(**self.kwargs)

        project_path=os.path.abspath(project_name)
        shutil.rmtree(project_path)
        self.assertFalse(os.path.isdir(project_path))

    unittest.skip("showing class skipping")
    def test_iso_box(self): 
        print "ENTERING test_iso_box"
        self.vm = self._vm_factory('Ubuntu_1404')

        self.vm.halt() 

        self.vm.up()

        self.vm.halt()

        self.vm.unregistervm()

    def test_halt_after_poweroff(self):
        # Bring up a VM and test power off by call poweroff on instance
        self.vm = self._vm_factory('halt_test')
        self.vm.poweroff()

        # test that you can't halt a powered off machine
        self.vm.halt()  
        
        #clean up the machine
        self.vm.unregistervm()

        # Bring up a VM and test poweroff with command line parameters
        self.vm = self._vm_factory('halt_test')
        kwargs = {
            'subparser_name': 'destroy',
            'force': False,
            'TEST': self.TEST
        }
        self.vm = VM(**kwargs)

       
    def test_action_not_defined(self):
        kwargs = {
            'subparser_name': 'noaction',
            'force': False,
            'TEST': self.TEST
        }        

        self.assertRaises(VagabondActionUndefined, VM, **self.kwargs)
   
    def test_box_subaction_not_defined(self):
        self.kwargs.update({
            'subparser_name': 'box',
            'box_subparser_name': 'noaction',
            'name': 'ubuntu_1404',
            'loc': 'http://hashicorp-files.vagrantup.com/precise32.box',
        })
        self.assertRaises(VagabondError, VM, **self.kwargs)     
    

    unittest.skip("showing class skipping")
    def test_add_vagrant_box(self):
        self.kwargs.update({
            'subparser_name': 'box', 
            'box_subparser_name': 'add',
            'name': 'ubuntu_1404', 
            'loc': 'http://hashicorp-files.vagrantup.com/precise32.box', 
        })

        vm = VM(**self.kwargs)

        self.assertEqual(vm.RET['STATUS'], 'SUCCESS')

        # Test that all the typicaly vagrant files are there.
        VAGABOND_PROJECT_ROOT = vm.RET['VAGABOND_PROJECT_ROOT']
        for _file in ['box-disk1.vmdk', 'box.ovf', 'Vagrantfile']:
            vfile = os.path.join(VAGABOND_PROJECT_ROOT, _file)
            self.assertTrue(os.path.isfile(vfile))

        """
        x box-disk1.vmdk
        x box.ovf
        x Vagrantfile
        """

    def test_show_valid_os_types(self):
        ostypes = VM.show_valid_os_types()      
        self.assertEqual(ostypes, OSTYPES)
コード例 #53
0
ファイル: test.py プロジェクト: jarrodb/ipcloud
from vdi import VDI
from vm import VM
from pif import get_network, get_public_pif

XENAPI_URL = 'http://65.183.54.10'

IMAGE_PATH = '/Users/jarrod/Dev/ipcloud/ubuntu.10-04.x86-64.20100927.img.gz'

import XenAPI
session = XenAPI.Session('https://65.183.54.10/')
session.login_with_password('root','')
xenapi = session.xenapi

i = Instance(name='Ubuntu 10.04', instance_type='level2')

v = VM(session)
vm_ref = v.create(i, '', '')
print "vm_ref - %s" % vm_ref

di = VDI(session)
vdi_ref = di.create('%s-vdi' % i._name, i._storage_gb)
print "vdi_ref - %s" % vdi_ref
# This is where the img should be attached to disk?
c = pycurl.Curl()
c.setopt(c.POST, True)
c.setopt(c.ENCODING, 'gzip')
c.setopt(c.HTTPAUTH, c.HTTPAUTH_BASIC)
c.setopt(c.USERPWD, "%s:%s" % ('root', ''))
c.setopt(c.URL, "%s/import_raw_vdi?vdi=%s" % (XENAPI_URL, vdi_ref))
c.setopt(c.HTTPPOST, [
    ("filename", (c.FORM_FILE, IMAGE_PATH)),
コード例 #54
0
ファイル: test.py プロジェクト: temoto/vm-001
def main():
    print "---"
    print "Simple test"
    print
    vm = VM(code_test)
    vm.run()

    print "---"
    print "GCD"
    print
    vm = VM(code_gcd)
    vm.greg[0] = 9
    vm.greg[1] = 12
    vm.run()

    print "---"
    print "Concurrent fibonacci"
    print
    vm = VM(code_fib_concurrent, 4)
    vm.greg[0] = 17
    vm.run()
コード例 #55
0
ファイル: test.py プロジェクト: aspiers/migrationpaths
 def setUp(self):
     VM.reset()
     VMhost.reset()
コード例 #56
0
ファイル: main.py プロジェクト: Vlad-Shcherbina/icfpc2009-tbd
import sys
import os

from vm import VM                
                
if __name__ == '__main__':
    assert len(sys.argv) == 2
    print os.getcwd()
    with open(sys.argv[1],"rb") as fin:
        data = fin.read()
        
    vm = VM(data)
    vm.inPort[0x3E80] = 1001.0
    while vm.outPort[0] == 0.0:
        vm.printStats()
        print 'step'
        vm.execute()
        vm.memDump()
        break
        vm.printStats()
    
    
    
    print 'ok'
コード例 #57
0
from __future__ import with_statement

import sys
import os

from vm import VM                
                
if __name__ == '__main__':
    assert len(sys.argv) == 2, "specify .obf file"
    with open(sys.argv[1],"rb") as fin:
        data = fin.read()
    vm = VM(data)
    vm.setScenario(1001)
    while vm.stats.score == 0.0:
        print 'step'
        vm.execute()
        vm.changeSpeed(10,12)
        vm.changeSpeed(10,12) # overwrite previous
        #vm.memDump()
        vm.printStats()
        if True:
            vm.execute()
            break # to finish after first iteration
    
    
    with open('solution','wb') as fout:
        fout.write(vm.getSolution())
    
    print 'finished'
コード例 #58
0
ファイル: interpreter.py プロジェクト: MrHamdulay/myjvm
 def __init__(self, initial_class, classpath):
     self.initial_class_name = initial_class
     self.vm = VM(classpath)