예제 #1
0
파일: button.py 프로젝트: gre7g/ktane
    def status(self, payload: bytes = b""):
        # def status(self, _source: int, _dest: int, payload: bytes = b"") -> bool:
        # Payload:
        #
        # Field     Length   Notes
        # -------   ------   -----------------------------------------
        # running   1        1 is the game is in play, 0 otherwise
        # strikes   1        Number of strikes
        # time      5        Time as a string, like " 1:12" or "16.92"
        LOG.debug("status", payload)
        _running, _strikes, time = struct.unpack("BB5s", payload)

        # Game logic
        if (self.button_color
                == CONSTANTS.COLORS.BLUE) and (self.button_text
                                               == CONSTANTS.LABELS.ABORT):
            self.check_time(time)
        elif (self.num_batteries > 1) and (self.button_text
                                           == CONSTANTS.LABELS.DETONATE):
            self.disarmed()
        elif ((self.button_color == CONSTANTS.COLORS.WHITE)
              and self.indicator_lit
              and (self.indicator_label == CONSTANTS.LABELS.CAR)):
            self.check_time(time)
        elif (self.num_batteries > 2) and self.indicator_lit and (
                self.indicator_label == CONSTANTS.LABELS.FKR):
            self.disarmed()
        elif self.button_color == CONSTANTS.COLORS.YELLOW:
            self.check_time(time)
        elif (self.button_color
              == CONSTANTS.COLORS.RED) and (self.button_text
                                            == CONSTANTS.LABELS.HOLD):
            self.disarmed()
        else:
            self.check_time(time)
예제 #2
0
    def get_device_path(self, blockdevice_id):
        """
        Return the device path that has been allocated to the block device on
        the host to which it is currently attached.

        :param unicode blockdevice_id: The unique identifier for the block
            device.
        :returns: A ``FilePath`` for the device.
        """

        LOG.debug("Call get_device_path blockdevice_id=%s" % blockdevice_id)

        if not self.rest.is_lun(self.Pool, blockdevice_id):
            raise UnknownVolume(blockdevice_id)

        target_name = '{}{}.{}'.format(self.jovian_target_prefix,
                                        blockdevice_id,
                                        self._compute_instance_id)

        if not self.rest.is_target(self.Pool, target_name):
            raise UnattachedVolume(blockdevice_id)

        path = jcom.get_local_disk_path(target_name)
        if path:
            LOG.debug('device_path was found: {}'.format(path))
            return FilePath('/dev/' + str(path))

        return None
예제 #3
0
    def __add_router_interface(self):

        # and pick the first in the list - the list should be non empty and
        # contain only 1 subnet since it is supposed to be a private network

        # But first check that the router does not already have this subnet
        # so retrieve the list of all ports, then check if there is one port
        # - matches the subnet
        # - and is attached to the router
        # Assumed that both management networks are created together so checking for one of them
        ports = self.neutron_client.list_ports()['ports']
        for port in ports:
            # Skip the check on stale ports
            if port['fixed_ips']:
                port_ip = port['fixed_ips'][0]
                if (port['device_id'] == self.ext_router['id']) and \
                   (port_ip['subnet_id'] == self.vm_int_net[0]['subnets'][0]):
                    LOG.info(
                        'Ext router already associated to the internal network.'
                    )
                    return

        for int_net in self.vm_int_net:
            body = {'subnet_id': int_net['subnets'][0]}
            self.neutron_client.add_interface_router(self.ext_router['id'],
                                                     body)
            LOG.debug('Ext router associated to ' + int_net['name'])
            # If ipv6 is enabled than add second subnet
            if self.ipv6_enabled:
                body = {'subnet_id': int_net['subnets'][1]}
                self.neutron_client.add_interface_router(
                    self.ext_router['id'], body)
예제 #4
0
    def create_volume(self, dataset_id, size):
        """
        Create a new volume.

        When called by ``IDeployer``, the supplied size will be
        rounded up to the nearest ``IBlockDeviceAPI.allocation_unit()``

        :param UUID dataset_id: The Flocker dataset ID of the dataset on this
            volume.
        :param int size: The size of the new volume in bytes.
        :returns: A ``BlockDeviceVolume``.
        """
        LOG.debug("Call create_volume, dataset_id=%s, size=%d"
                 % (dataset_id, size))

        name = str(self._cluster_id) + '.' + str(dataset_id)
        try:
            self.rest.create_lun(self.Pool, name, int(size))
        except jexc.JDSSRESTException as error_message:
            LOG.debug(error_message)
            raise VolumeException(error_message)

        volume = BlockDeviceVolume(
            size=int(size),
            attached_to=None,
            dataset_id=dataset_id,
            blockdevice_id=unicode(name)
        )
        return volume
예제 #5
0
	def commandReceived(self, cmd):
		if cmd.commandid in const.command_names.keys():
			LOG.debug("got command: %d(%s) from company %d: '%s'" % (cmd.cmd, const.command_names[cmd.commandid].__str__(), cmd.company + 1, cmd.text))

		ctime = time.time()
		companystr = self.client.getCompanyString(cmd.company)

		if cmd.company in self.companyIdling and cmd.company != const.PLAYER_SPECTATOR:
			# remove from that list
			idx = self.companyIdling.index(cmd.company)
			del self.companyIdling[idx]
			timediff = ctime - self.companyLastAction[cmd.company]
			if timediff > self.idletime:
				# we were here already, check if we got back from idling
				Broadcast("%s is back from idling after %s" % (companystr, self.timeFormat(timediff)), parentclient=self.client)
			
		self.companyLastAction[cmd.company] = ctime
		
		if cmd.commandid == const.commands['CMD_PLACE_SIGN'] and cmd.text != '':
			Broadcast("%s placed a sign: '%s'" % (companystr, cmd.text), parentclient=self.client)
		elif cmd.commandid == const.commands['CMD_RENAME_SIGN'] and cmd.text != '':
			Broadcast("%s renames a sign: '%s'" % (companystr, cmd.text), parentclient=self.client)
		elif cmd.commandid == const.commands['CMD_SET_COMPANY_COLOUR']:
			Broadcast("%s changed their color" % companystr, parentclient=self.client)
		elif cmd.commandid == const.commands['CMD_RENAME_COMPANY']:
			Broadcast("%s changed their company name to '%s'"%(companystr, cmd.text), parentclient=self.client)
		elif cmd.commandid == const.commands['CMD_SET_COMPANY_MANAGER_FACE']:
			Broadcast("%s changed their company face"%(companystr), parentclient=self.client)
		elif cmd.commandid == const.commands['CMD_RENAME_PRESIDENT']:
			Broadcast("%s changed their presidents name to '%s'"%(companystr, cmd.text), parentclient=self.client)
		elif cmd.commandid == const.commands['CMD_BUILD_INDUSTRY']:
			Broadcast("%s built a new industry"%(companystr), parentclient=self.client)
		elif cmd.commandid == const.commands['CMD_BUILD_COMPANY_HQ']:
			Broadcast("%s built or relocated their HQ"%(companystr), parentclient=self.client)
예제 #6
0
    def reset_irq_affinity(self, uuid, irqs=None, msi_irqs=None):
        """Reset irq affinity for instance

        The instance has already been deleted or
        related PCI not used by it anymore.
        """
        if irqs or msi_irqs:
            # reset irq affinity for specified irqs
            _irqs = irqs
            _msi_irqs = msi_irqs

        elif uuid in self.inst_dict:
            # reset all irq affinity for deleted instance
            _irqs = self.inst_dict[uuid][0]
            _msi_irqs = self.inst_dict[uuid][1]
        else:
            LOG.debug("No pci affinity need to be reset for instance=%s!" %
                      uuid)
            return

        try:
            with open('/proc/irq/default_smp_affinity') as f:
                cpulist = f.readline().strip()
            LOG.debug("default smp affinity bitmap:%s" % cpulist)

            for x in [_irqs, _msi_irqs]:
                if len(x) > 0:
                    pci_utils.set_irq_affinity(True, x, cpulist)

        except Exception as e:
            LOG.error("Failed to reset smp affinity! error=%s" % e)

        LOG.info("Reset smp affinity done for instance=%s!" % uuid)
예제 #7
0
def add_role_permissions(transaction):
    reset_table_sequence_id(RolePermissions, transaction)
    for (role_name, permission_names) in list(ROLE_PERMISSIONS.items()):
        role = transaction.find_one_by_fields(Role, True, {'name': role_name})
        if not role:
            raise ValueError(
                'Could not find role \'{name}\''.format(name=role_name))

        permissions = []

        for permission_name in permission_names:
            permission = transaction.find_one_by_fields(
                Permission,
                True,
                {
                    'permission': permission_name,
                    'resource_type_id': role.resource_type_id,
                },
            )
            if not permission:
                raise ValueError('Could not find permission \'{name}\''.format(
                    name=permission_name))
            permissions.append(permission)

        for permission in permissions:
            role_permission = RolePermissions(role_id=role.id,
                                              permission_id=permission.id)
            transaction.add_or_update(role_permission, flush=True)
    LOG.debug('Added Group, User and Query Policy Role Permissions')
예제 #8
0
    def receiveMsg_TCP(self, datapacket=False):
        if self.socket_tcp is None:
            raise _error.ConnectionError("no tcp socket for receiving")
        raw = ""
        note = ""
        data, readcounter = self.receive_bytes(self.socket_tcp,
                                               const.HEADER.size)
        if readcounter > 1:
            note += "HEADER SEGMENTED INTO %s SEGMENTS!" % readcounter
        raw += data
        size, command = networking.parsePacketHeader(data)
        if not command in (const.PACKET_SERVER_FRAME,
                           const.PACKET_SERVER_SYNC):
            if command in const.packet_names:
                LOG.debug("received size: %d, command: %s (%d)" %
                          (size, const.packet_names[command], command))
            else:
                LOG.debug("received size: %d, command: %d" % (size, command))
        size -= const.HEADER.size  # remove size of the header ...
        data, readcounter = self.receive_bytes(self.socket_tcp, size)
        if readcounter > 1:
            note += "DATA SEGMENTED INTO %s SEGMENTS!" % readcounter
        raw += data
        if not self.running:
            return None
        if len(note) > 0:
            LOG.info(note)
        content = data

        if datapacket:
            return DataPacket(size, command, content)
        else:
            return size, command, content
예제 #9
0
def delete_role_permissions(transaction):
    for (role_name, permission_names) in list(ROLE_PERMISSIONS.items()):
        role = transaction.find_one_by_fields(Role, True, {'name': role_name})
        if not role:
            continue

        permissions = []

        for permission_name in permission_names:
            permission = transaction.find_one_by_fields(
                Permission,
                True,
                {
                    'permission': permission_name,
                    'resource_type_id': role.resource_type_id,
                },
            )
            if not permission:
                continue
            permissions.append(permission)

        for permission in permissions:
            role_permission = transaction.find_one_by_fields(
                RolePermissions,
                True,
                {
                    'role_id': role.id,
                    'permission_id': permission.id
                },
            )

            if role_permission:
                transaction.delete(role_permission)
    LOG.debug('Deleted Group, User and Query Policy Role Permissions')
예제 #10
0
 def throwRandomData(self):
     rsize = 128
     rand = str(random.getrandbits(rsize))
     res = struct.pack("%ds" % rsize, rand)
     LOG.debug(" fuzzing with %d bytes: '%s'" % (rsize, rand))
     for i in range(0, 127):
         self.sendMsg_UDP(i, res)
예제 #11
0
def delete_user_preferences(transaction):
    user_preferences = transaction.find_all_by_fields(UserPreferences, {})

    for preference in user_preferences:
        transaction.delete(preference)

    LOG.debug('Deleted User Preference entries')
예제 #12
0
def add_new_role_permissions(transaction):
    for (role_name, permission_names) in list(NEW_ROLE_PERMISSIONS.items()):
        role = transaction.find_one_by_fields(Role, True, {'name': role_name})
        if not role:
            raise ValueError(
                'Could not find role \'{name}\''.format(name=role_name))

        permissions = []

        for permission_name in permission_names:
            permission = transaction.find_one_by_fields(
                PermissionDefinition,
                True,
                {
                    'permission': permission_name,
                    'resource_type_id': role.resource_type_id,
                },
            )
            if not permission:
                raise ValueError('Could not find permission \'{name}\''.format(
                    name=permission_name))
            permissions.append(permission)

        for permission in permissions:
            role_permission = Permission(role_id=role.id,
                                         definition_id=permission.id)
            transaction.add_or_update(role_permission, flush=True)

    LOG.debug('Added new role permissions')
예제 #13
0
    def run_raw_query(self, query_dict):
        # If requested, log the input query before initiating the request
        # NOTE(stephen): Conditionally checking this so we don't json serialize
        # the druid query every time if it isn't going to be logged..
        if LOG.level <= logging.DEBUG:
            LOG.debug(json.dumps(query_dict, indent=2).replace('\\n', '\n'))

        # Kick off a new druid query
        r = _get_session(self.druid_configuration).post(self.query_url,
                                                        json=query_dict)
        if r.status_code != requests.codes.ok:
            error_msg = 'Server response: %s' % r.content
            try:
                # "raise_for_status" will only throw an HTTPError if the
                # status code is >= 400. We still want to throw an error
                # for non 200 responses.
                r.raise_for_status()
            except requests.exceptions.HTTPError as e:
                error_msg = '%s\n%s' % (e.message, error_msg)

            raise DruidQueryError(error_msg)

        ret = r.json()
        if LOG.level <= logging.DEBUG and os.getenv('LOG_DRUID_RESPONSES'):
            LOG.debug('Received response: %s' % json.dumps(r.json(), indent=2))
        return ret
예제 #14
0
    def get_free_vdev(self, userid):
        """Get a free vdev address in target userid

        Returns:
        :vdev:   virtual device number, string of 4 bit hex
        """
        vdev = CONF.volume_vdev_start
        if os.path.exists(self._zvm_volumes_file):
            volumes = []
            with open(self._zvm_volumes_file, 'r') as f:
                volumes = f.readlines()
            max_vdev = ''
            for volume in volumes:
                volume_info = volume.strip().split(' ')
                attached_userid = volume_info[2]
                curr_vdev = volume_info[3]
                if (attached_userid == userid) and (
                    (max_vdev == '') or
                    (int(curr_vdev, 16) > int(max_vdev, 16))):
                    max_vdev = curr_vdev
            if max_vdev != '':
                vdev = self._generate_vdev(max_vdev)
                LOG.debug(
                    "max_vdev used in volumes file: %s,"
                    " return vdev: %s", max_vdev, vdev)
        else:
            msg = ("Cann't find z/VM volume management file")
            raise zvmutils.ZVMException(msg)
        LOG.debug("Final link address in target VM: %s", vdev)
        return vdev
예제 #15
0
 def throwRandomData(self):
     rsize = 128
     rand = str(random.getrandbits(rsize))
     res = struct.pack("%ds"%rsize, rand)
     LOG.debug(" fuzzing with %d bytes: '%s'" % (rsize, rand))
     for i in range(0,127):
         self.sendMsg_UDP(i, res)
예제 #16
0
파일: wires.py 프로젝트: gre7g/ktane
    def should_cut(self, post_number: int, color=None) -> None:
        LOG.debug("should_cut", post_number, color)

        # Did they specify a color (e.g. "last red" or "first white")?
        if color is None:
            # No all colors, so just skip None
            posts_in_use = [
                index for index, mapping in enumerate(self.mapping)
                if mapping is not None
            ]
        else:
            # Specific color
            posts_in_use = [
                index for index, mapping in enumerate(self.mapping)
                if COLOR_POSITIONS[mapping] == color
            ]
        if post_number < 0:
            # Count from end
            self.right_post = posts_in_use[post_number]
        else:
            # Post number (Warning: post #1 means index 0!)
            self.right_post = posts_in_use[post_number - 1]

        LOG.info("right_post=", self.right_post)

        for post in self.post_pins:
            post.irq(self.on_wrong_post, trigger=Pin.IRQ_RISING)
        self.post_pins[self.right_post].irq(self.on_right_post,
                                            trigger=Pin.IRQ_RISING)
예제 #17
0
    def detach_volume(self, blockdevice_id):
        """
        Detach ``blockdevice_id`` from whatever host it is attached to.

        :param unicode blockdevice_id: The unique identifier for the block
            device being detached.
        """

        LOG.debug("Call detach_volume blockdevice_id=%s" % blockdevice_id)

        if not self.rest.is_lun(self.Pool, blockdevice_id):
            raise UnknownVolume(blockdevice_id)

        target_name = '{}{}.{}'.format(self.jovian_target_prefix,
                                       blockdevice_id,
                                       self._compute_instance_id)

        jcom.iscsiadm_logout_target(target_name, self.host, self.target_port)

        if not self.rest.is_target(self.Pool, target_name):
            raise UnattachedVolume(blockdevice_id)
        elif not self.rest.is_target_lun(self.Pool, target_name,
                                         blockdevice_id):
            self.rest.delete_target(self.Pool, target_name)
            raise UnattachedVolume(blockdevice_id)

        self.rest.detach_target_vol(self.Pool, target_name,
                                    blockdevice_id)
        self.rest.delete_target(self.Pool, target_name)
        jcom.rm_local_dir('/flocker/{}/'.format(blockdevice_id))
예제 #18
0
    def place_block(self, block, pos, ignore_top=True):
        """
        Updates the board by placing `block` at the position `pos`.
        """
        LOG.debug("Placing %s at %s" % (block, pos))

        solid_squares = block.get_solid_squares()
        heighest_columns = [0] * self.width

        for (x,y) in solid_squares:
            final_x, final_y = pos[0]+x, pos[1]+y

            if ignore_top and final_y >= self.height:
                continue

            assert self.valid_position(final_x, final_y, ignore_top), \
                "Trying to place %s outside the board limits! (%s)" % (block, pos)

            if self.board[final_y][final_x] != None:
                LOG.critical("Writing on (%d,%d), a position of the" % (final_x, final_y) + \
                        "board already filled, something wrong happend!")

            self.board[final_y][final_x] = block

            if final_y >= heighest_columns[final_x]:
                heighest_columns[final_x] = final_y + 1

        for (x, _) in solid_squares:
            final_x = pos[0]+x

            if heighest_columns[final_x] > self._column_heights[final_x]:
                self._column_heights[final_x] = heighest_columns[final_x]
예제 #19
0
def get_instance_path(os_node, instance_name):
    instance_folder = os.path.join(_get_instances_path(), os_node,
                                   instance_name)
    if not os.path.exists(instance_folder):
        LOG.debug("Creating the instance path %s", instance_folder)
        os.makedirs(instance_folder)
    return instance_folder
예제 #20
0
파일: cmd.py 프로젝트: setsulla/bantorra
 def run(self):
     L.info("Command Send : %s" % self.command)
     args = self.command.split(" ")
     subproc_args = { 'stdin'        : subprocess.PIPE,
                      'stdout'       : subprocess.PIPE,
                      'stderr'       : subprocess.STDOUT,
     }
     try:
         proc = subprocess.Popen(args, **subproc_args)
     except OSError:
         L.info("Failed to execute command: %s" % args[0])
         sys.exit(1)
     (stdouterr, stdin) = (proc.stdout, proc.stdin)
     Li = []
     result = None
     if stdouterr is None:
         pass
     else:
         while True:
             line = stdouterr.readline()
             if not line:
                 break
             Li.append(line.rstrip())
         result = "".join(Li)
     code = proc.wait()
     time.sleep(2)
     L.debug("Command Resturn Code: %d" % code)
     self.queue.put(result)
예제 #21
0
파일: network.py 프로젝트: sebrandon1/vmtp
    def __add_router_interface(self):

        # and pick the first in the list - the list should be non empty and
        # contain only 1 subnet since it is supposed to be a private network

        # But first check that the router does not already have this subnet
        # so retrieve the list of all ports, then check if there is one port
        # - matches the subnet
        # - and is attached to the router
        # Assumed that both management networks are created together so checking for one of them
        ports = self.neutron_client.list_ports()['ports']
        for port in ports:
            # Skip the check on stale ports
            if port['fixed_ips']:
                port_ip = port['fixed_ips'][0]
                if (port['device_id'] == self.ext_router['id']) and \
                   (port_ip['subnet_id'] == self.vm_int_net[0]['subnets'][0]):
                    LOG.info('Ext router already associated to the internal network.')
                    return

        for int_net in self.vm_int_net:
            body = {
                'subnet_id': int_net['subnets'][0]
            }
            self.neutron_client.add_interface_router(self.ext_router['id'], body)
            LOG.debug('Ext router associated to ' + int_net['name'])
            # If ipv6 is enabled than add second subnet
            if self.ipv6_enabled:
                body = {
                    'subnet_id': int_net['subnets'][1]
                }
                self.neutron_client.add_interface_router(self.ext_router['id'], body)
예제 #22
0
    def create_userid(self, instance_name, cpu, memory, image_name):
        """Create z/VM userid into user directory for a z/VM instance."""
        LOG.debug("Creating the z/VM user entry for instance %s" %
                  instance_name)

        kwprofile = 'profile=%s' % const.ZVM_USER_PROFILE
        body = [
            kwprofile,
            'password=%s' % CONF.zvm_user_default_password,
            'cpu=%i' % cpu,
            'memory=%im' % memory,
            'privilege=%s' % const.ZVM_USER_DEFAULT_PRIVILEGE,
            'ipl=%s' % CONF.zvm_user_root_vdev,
            'imagename=%s' % image_name
        ]

        url = zvmutils.get_xcat_url().mkvm('/' + instance_name)

        try:
            zvmutils.xcat_request("POST", url, body)
            size = CONF.root_disk_units
            # Add root disk and set ipl
            self.add_mdisk(instance_name, CONF.zvm_diskpool,
                           CONF.zvm_user_root_vdev, size)
            self.set_ipl(instance_name, CONF.zvm_user_root_vdev)

        except Exception as err:
            msg = ("Failed to create z/VM userid: %s") % err
            LOG.error(msg)
            raise ZVMException(msg=err)
예제 #23
0
    def update_volume_info(self, volinfo):
        """Update volume info in the z/VM volume management file

        Input parameters:
        a string containing the volume info string: uuid status userid vdev
        """
        if os.path.exists(self._zvm_volumes_file):
            uuid = volinfo.split(' ')[0]
            # Check whether there are multiple lines correspond to this uuid
            cmd = ("grep -i \"^%(uuid)s\" %(file)s") % {
                'uuid': uuid,
                'file': self._zvm_volumes_file
            }
            status_lines = commands.getstatusoutput(cmd)[1].split("\n")
            if len(status_lines) != 1:
                msg = ("Found %(count) line status for volume %(uuid)s.") % {
                    'count': len(status_lines),
                    'uuid': uuid
                }
                raise zvmutils.ZVMException(msg)
            # Write the new status
            cmd = ("sed -i \'s/^%(uuid)s.*/%(new_line)s/g\' %(file)s") % {
                'uuid': uuid,
                'new_line': volinfo,
                'file': self._zvm_volumes_file
            }
            LOG.debug("Updating volume status, cmd: %s" % cmd)
            commands.getstatusoutput(cmd)
        else:
            msg = ("Cann't find z/VM volume management file")
            raise zvmutils.ZVMException(msg)
예제 #24
0
파일: cmd.py 프로젝트: setsulla/bantorra
 def run(self):
     L.info("Command Send : %s" % self.command)
     args = self.command.split(" ")
     subproc_args = { 'stdin'        : subprocess.PIPE,
                      'stdout'       : subprocess.PIPE,
                      'stderr'       : subprocess.STDOUT,
     }
     try:
         proc = subprocess.Popen(args, **subproc_args)
     except OSError:
         L.info("Failed to execute command: %s" % args[0])
         sys.exit(1)
     (stdouterr, stdin) = (proc.stdout, proc.stdin)
     if stdouterr is None:
         pass
     else:
         with open(self.filepath, "w") as f:
             while True:
                 line = stdouterr.readline()
                 if not line:
                     break
                 f.write(line)
     code = proc.wait()
     time.sleep(2)
     L.debug("Command Resturn Code: %d" % code)
예제 #25
0
    def delete_volume_info(self, uuid):
        """Delete the volume from the z/VM volume management file

        Input parameters:
        :uuid: uuid of the volume to be deleted
        """
        if os.path.exists(self._zvm_volumes_file):
            cmd = ("grep -i \"^%(uuid)s\" %(file)s") % {
                'uuid': uuid,
                'file': self._zvm_volumes_file
            }
            status_lines = commands.getstatusoutput(cmd)[1].split("\n")
            if len(status_lines) != 1:
                msg = ("Found %(count) line status for volume %(uuid)s.") % {
                    'count': len(status_lines),
                    'uuid': uuid
                }
                raise zvmutils.ZVMException(msg)
            # Delete the volume status line
            cmd = ("sed -i \'/^%(uuid)s.*/d\' %(file)s") % {
                'uuid': uuid,
                'file': self._zvm_volumes_file
            }
            LOG.debug("Deleting volume status, cmd: %s" % cmd)
            commands.getstatusoutput(cmd)
        else:
            msg = ("Cann't find z/VM volume management file")
            raise zvmutils.ZVMException(msg)
예제 #26
0
 def receiveMsg_TCP(self, datapacket = False):
     if self.socket_tcp is None:
         raise _error.ConnectionError("no tcp socket for receiving")
     raw = ""
     note = ""
     data, readcounter = self.receive_bytes(self.socket_tcp, const.HEADER.size)
     if readcounter > 1:
         note += "HEADER SEGMENTED INTO %s SEGMENTS!" % readcounter
     raw += data
     size, command = networking.parsePacketHeader(data)
     if not command in (const.PACKET_SERVER_FRAME, const.PACKET_SERVER_SYNC):
         if command in const.packet_names:
             LOG.debug("received size: %d, command: %s (%d)"% (size, const.packet_names[command], command))
         else:
             LOG.debug("received size: %d, command: %d"% (size, command))
     size -= const.HEADER.size # remove size of the header ...
     data, readcounter = self.receive_bytes(self.socket_tcp, size)
     if readcounter > 1:
         note += "DATA SEGMENTED INTO %s SEGMENTS!" % readcounter
     raw += data
     if not self.running:
         return None
     if len(note) > 0:
         LOG.info(note)
     content = data
     
     if datapacket:
         return DataPacket(size, command, content)
     else:
         return size, command, content
     #content = struct.unpack(str(size) + 's', data)
     #content = content[0]
예제 #27
0
    def delete_userid(self, instance_name, zhcp_node):
        """Delete z/VM userid for the instance.This will remove xCAT node
        at same time.
        """
        # Versions of xCAT that do not understand the instance ID and
        # request ID will silently ignore them.
        url = get_xcat_url().rmvm('/' + instance_name)

        try:
            self._delete_userid(url)
        except Exception as err:
            emsg = err.format_message()
            if (emsg.__contains__("Return Code: 400")
                    and (emsg.__contains__("Reason Code: 16")
                         or emsg.__contains__("Reason Code: 12"))):
                self._delete_userid(url)
            else:
                LOG.debug(
                    "exception not able to handle in delete_userid "
                    "%s", self._name)
                raise err
        except Exception as err:
            emsg = err.format_message()
            if (emsg.__contains__("Invalid nodes and/or groups")
                    and emsg.__contains__("Forbidden")):
                # Assume neither zVM userid nor xCAT node exist in this case
                return
            else:
                raise err
예제 #28
0
 def fetch_dimension_metadata(self, dimensions, interval):
     # NOTE(stephen): Right now we only care about the cardinality of each
     # dimension.
     LOG.info('Fetching dimension metadata for %s dimensions',
              len(dimensions))
     output = {}
     for dimension in dimensions:
         query = create_dimension_metadata_query(self._datasource.name,
                                                 dimension, [interval])
         result = self._query_client.run_raw_query(query)
         sketch_size = 0
         if result:
             # The sketch size is represented as powers of 2. The sketch size
             # must be larger than the true column cardinality to ensure that
             # we produce an exact distinct count (otherwise we will produce
             # an approximate).
             # Use the number of bits it takes to represent the approximate
             # distinct count as a shorthand for computing the sketch size.
             bits = int(result[0]['event'][dimension]).bit_length()
             sketch_size = 2**bits
             output[dimension] = sketch_size
         LOG.debug('Sketch size %s for dimension %s', sketch_size,
                   dimension)
     LOG.info('Finished fetching dimension metadata')
     return output
예제 #29
0
 def stopWebserver(self, event, command):
     if self.webserverthread is None or (config.getboolean("main", "productive") and not event.isByOp()):
         return
     LOG.debug("stopping webserver ...")
     self.webserverthread.stop()
     self.webserverthread = None
     Broadcast("webserver stopped", parentclient=self.client, parent=event)
예제 #30
0
    def create_server(self,
                      vmname,
                      image,
                      flavor,
                      key_name,
                      nic,
                      sec_group,
                      avail_zone=None,
                      user_data=None,
                      config_drive=None,
                      files=None,
                      retry_count=10,
                      volume=None):

        if sec_group:
            security_groups = [sec_group["name"]]
        else:
            security_groups = None
        # Also attach the created security group for the test
        vol_map = None
        if volume:
            vol_map = [{
                "source_type": "volume",
                "boot_index": "0",
                "uuid": volume.id,
                "destination_type": "volume"
            }]
            image = None
        instance = self.novaclient.servers.create(
            name=vmname,
            image=image,
            block_device_mapping_v2=vol_map,
            flavor=flavor,
            key_name=key_name,
            nics=nic,
            availability_zone=avail_zone,
            userdata=user_data,
            config_drive=config_drive,
            files=files,
            security_groups=security_groups)
        if not instance:
            return None
        # Verify that the instance gets into the ACTIVE state
        for retry_attempt in range(retry_count):
            instance = self.novaclient.servers.get(instance.id)
            if instance.status == 'ACTIVE':
                return instance
            if instance.status == 'ERROR':
                LOG.error('Instance creation error: %s',
                          instance.fault['message'])
                break
            LOG.debug("[%s] VM status=%s, retrying %s of %s...", vmname,
                      instance.status, (retry_attempt + 1), retry_count)
            time.sleep(2)

        # instance not in ACTIVE state
        LOG.error('Instance failed status=%s', instance.status)
        self.delete_server(instance)
        return None
예제 #31
0
def set_irqs_affinity_by_pci_address(pci_addr,
                                     extra_spec=None,
                                     numa_topology=None):
    """Set cpu affinity for list of PCI IRQs with a VF's pci address,

    Restrict cpuset to the numa node of the PCI.
    Return list
    Raises PciDeviceNotFoundById in case the pci device is not found,
    or when there is an underlying problem getting associated irqs.
    :param pci_addr: PCI address
    :param extra_spec: extra_spec
    :param numa_topology: instance numa topology
    :return: irqs, msi_irqs, numa_node, cpulist
    """
    irqs = set()
    msi_irqs = set()
    numa_node = None
    cpulist = ''

    if numa_topology is None:
        return (irqs, msi_irqs, numa_node, cpulist)

    # Get the irqs associated with pci addr
    _irqs, _msi_irqs = get_irqs_by_pci_address(pci_addr)
    LOG.debug("pci: %s, irqs: %s, msi_irqs: %s" % (pci_addr, _irqs, _msi_irqs))

    # Obtain physical numa_node for this pci addr
    numa_path = "/sys/bus/pci/devices/%s/numa_node" % (pci_addr)
    try:
        with open(numa_path) as f:
            numa_node = [int(x) for x in f.readline().split()][0]
    except Exception as e:
        LOG.error(
            'set_irqs_affinity_by_pci_address: '
            'pci_addr=%(A)s: numa_path=%(P)s; error=%(E)s', {
                'A': pci_addr,
                'P': numa_path,
                'E': e
            })
        raise Exception("PciDeviceNotFoundById id = %r" % pci_addr)
    # Skip irq configuration if there is no associated numa node
    if numa_node is None or numa_node < 0:
        return (irqs, msi_irqs, numa_node, cpulist)

    # Determine the pinned cpuset where irqs are to be affined
    cpuset, cpulist = get_pci_irqs_pinned_cpuset(extra_spec, numa_topology,
                                                 numa_node)

    LOG.debug("cpuset where irqs are to be affined:%s or %s" %
              (cpuset, cpulist))

    # Skip irq configuration if there are no pinned cpus
    if not cpuset:
        return (irqs, msi_irqs, numa_node, cpulist)

    # Set IRQ affinity, but do not treat errors as fatal.
    irqs = set_irq_affinity(False, _irqs, cpulist)
    msi_irqs = set_irq_affinity(False, _msi_irqs, cpulist)
    return (irqs, msi_irqs, numa_node, cpulist)
예제 #32
0
파일: main.py 프로젝트: turbofish/mcverify
def parse_config(filename):
    """
    Fnord
    """
    # {{{
    filename = expanduser(expandvars(filename))
    LOG.debug("Parsing configuration in file '%s'",filename)
    CONFIG.read(filename)
예제 #33
0
 def clearStats(self):
     if not config.getboolean('stats', 'enable'): return
     fn = config.get("stats", "cachefilename")
     try:
         os.remove(fn)
         LOG.debug("stats cleared")
     except:
         pass
예제 #34
0
 def delete_port(self, port):
     LOG.debug('Deleting port ' + port['id'])
     for _ in range(1, 5):
         try:
             self.neutron_client.delete_port(port['id'])
             break
         except PortInUseClient:
             time.sleep(1)
예제 #35
0
 def clearStats(self):
     if not config.getboolean('stats', 'enable'): return
     fn = config.get("stats", "cachefilename")
     try:
         os.remove(fn)
         LOG.debug("stats cleared")
     except:
         pass
예제 #36
0
 def check_config_updated(self, generator_config):
     existing_config = self.__load_config(filename='/etc/trex_cfg.yaml')
     new_config = yaml.safe_load(self.__prepare_config(generator_config))
     LOG.debug("Existing config: %s", existing_config)
     LOG.debug("New config: %s", new_config)
     if existing_config == new_config:
         return False
     return True
예제 #37
0
def delete_resource_types(transaction):
    entity = transaction.find_by_id(ResourceType,
                                    ResourceTypeEnum.QUERY_POLICY.value)

    if entity:
        transaction.delete(entity)

    LOG.debug('Deleted Query Policy resource type')
예제 #38
0
def add_user_preferences(transaction):
    users = transaction.find_all_by_fields(User, {})

    for user in users:
        user_preference = UserPreferences(user_id=user.id, preferences={})
        transaction.add_or_update(user_preference)

    LOG.debug('Added User Preference entries')
예제 #39
0
파일: cmd.py 프로젝트: setsulla/bantorra
    def __exec_light(self, cmd, timeout=TIMEOUT):
        proc = BantorraLightProcess(cmd, self.queue)
        proc.start()
        proc.join(timeout)

        if proc.is_alive():
            proc.kill()
            time.sleep(1)
            L.debug("proc.terminate. %s" % proc.is_alive())
예제 #40
0
 def startWebserver(self, event, command):
     if config.getboolean("main", "productive") and not event.isByOp():
         return
     if not config.getboolean("webserver", "enable") or not self.webserverthread is None:
         return
     LOG.debug("starting webserver ...")
     self.webserverthread = WebserverThread(self.client)
     self.webserverthread.start()
     Broadcast("webserver started on port %d"% self.webserverthread.port, parentclient=self.client, parent=event)
예제 #41
0
	def init(self):
		LOG.debug("PlayerInfoPlugin started")
		self.updateConfig()
		self.enabled  = config.getboolean('playerinfos', 'enable')
		self.idletime = config.getint    ('playerinfos', 'idletime')
		self.registerCallback("on_receive_command", self.commandReceived)
		self.registerCallback("on_mainloop", self.onMainLoop)
		self.registerChatCommand("stopinfo", self.stopInfo)
		self.registerChatCommand("idleinfo", self.idleInfo)
예제 #42
0
    def move_down(self):
        LOG.debug("ENGINE - move down")
        self._restart_timeout = True
        if self.game_state.drop_block_is_stuck():
            done_lines = self.game_state.move_block_down()
            self.game_state.start_new_drop()
            return done_lines

        self.game_state.move_block_down()
        return 0
예제 #43
0
 def disconnect(self, mode=M_BOTH):
     if not self.socket_tcp is None and mode & M_TCP:
         LOG.debug('closing TCP socket')
         self.socket_tcp.close()
         self.socket_tcp = None
     if not self.socket_udp is None and mode & M_UDP:
         LOG.debug('closing UDP socket')
         self.socket_udp.close()
         self.socket_udp = None
     self.connectionmode &= ~mode
     if self.connectionmode == M_NONE:
         self.running = False
예제 #44
0
 def get_tags(self):
     LOG.info("Getting tags from openttd finger server")
     LOG.debug("HTTP GET %s" % const.OPENTTD_FINGER_TAGS_URL)
     self.request("GET", const.OPENTTD_FINGER_TAGS_URL)
     r1 = self.getresponse()
     LOG.debug("%d %s" % (r1.status, r1.reason))
     if r1.status != 200:
         raise Exception("Couldn't request tags list")
     data1 = r1.read()
     data2 = [i.strip().split() for i in data1.split('\n') if i]
     data2 = [(int(i[0]), dateutil.parser.parse(i[1]).date(), i[2].strip()) for i in data2]
     self.tags = data2
예제 #45
0
파일: network.py 프로젝트: sebrandon1/vmtp
 def create_port(self, net_id, sec_group_list, vnic_type):
     body = {
         "port": {
             "network_id": net_id,
             "security_groups": sec_group_list
         }
     }
     if vnic_type:
         body['port']['binding:vnic_type'] = vnic_type
     port = self.neutron_client.create_port(body)
     if self.config.debug:
         LOG.debug('Created port ' + port['port']['id'])
     return port['port']
예제 #46
0
파일: cmd.py 프로젝트: setsulla/bantorra
    def __exec(self, cmd, timeout=TIMEOUT):
        proc = BantorraProcess(cmd, self.queue)
        proc.start()
        proc.join(timeout)

        if proc.is_alive():
            proc.kill()
            time.sleep(3)
            L.debug("proc.terminate. %s" % proc.is_alive())

        if self.queue.empty():
            return None
        return self.queue.get()
예제 #47
0
    def _get_path(self, end_node):
        #LOG.debug("End node: %s" % end_node)
        path = []

        node = end_node
        while node.previous_node:
            for a in node.previous_actions:
                path.insert(0, a)

            node = node.previous_node

        LOG.debug("PATH: %s" % path)
        LOG.debug("Start node: %s" % node)
        return path
예제 #48
0
파일: cmd.py 프로젝트: setsulla/bantorra
    def run(self):
        L.info("Light Command Send : %s" % self.command)
        args = self.command.split(" ")
        subproc_args = { 'stdin'        : subprocess.PIPE,
                         'stdout'       : subprocess.PIPE,
                         'stderr'       : subprocess.STDOUT,
        }

        try:
            proc = subprocess.call(args, **subproc_args)
        except OSError:
            L.info("Failed to execute command: %s" % args[0])
            sys.exit(1)
        L.debug("Command Resturn Code: %d" % proc)
예제 #49
0
    def check(self, directory, files):
        """
        The check method does the actual checking. It takes a directory
        (full path) and a list of files in the bottom directory. This
        constraints how the music collection can be organized but can be
        changed here.

        :param directory: The full bottom directory of the files.
        :type directory: String
        :param files: A list of files in the directory
        :type files: A list of Strings
        :returns: True if check succeeded, otherwise False
        """
        # {{{
        LOG.debug("Running '%s' ..." % self.name)
예제 #50
0
def http_retriable_request(verb, url, headers={}, authenticate=False, params={}):
    """
    Sends an HTTP request, with automatic retrying in case of HTTP Errors 500 or ConnectionErrors
    _http_retriable_request('POST', 'http://cc.cloudcomplab.ch:8888/app/', headers={'Content-Type': 'text/occi', [...]}
                            , authenticate=True)
    :param verb: [POST|PUT|GET|DELETE] HTTP keyword
    :param url: The URL to use.
    :param headers: Headers of the request
    :param kwargs: May contain authenticate=True parameter, which is used to make requests requiring authentication,
                    e.g. CC requests
    :return: result of the request
    """
    LOG.debug(verb + ' on ' + url + ' with headers ' + headers.__repr__())

    auth = ()
    if authenticate:
        user = CONFIG.get('cloud_controller', 'user')
        pwd = CONFIG.get('cloud_controller', 'pwd')
        auth = (user, pwd)

    if verb in ['POST', 'DELETE', 'GET', 'PUT']:
        try:
            r = None
            if verb == 'POST':
                if authenticate:
                    r = requests.post(url, headers=headers, auth=auth, params=params)
                else:
                    r = requests.post(url, headers=headers, params=params)
            elif verb == 'DELETE':
                if authenticate:
                    r = requests.delete(url, headers=headers, auth=auth, params=params)
                else:
                    r = requests.delete(url, headers=headers, params=params)
            elif verb == 'GET':
                if authenticate:
                    r = requests.get(url, headers=headers, auth=auth, params=params)
                else:
                    r = requests.get(url, headers=headers, params=params)
            elif verb == 'PUT':
                if authenticate:
                    r = requests.put(url, headers=headers, auth=auth, params=params)
                else:
                    r = requests.put(url, headers=headers, params=params)
            r.raise_for_status()
            return r
        except requests.HTTPError as err:
            LOG.error('HTTP Error: should do something more here!' + err.message)
            raise err
예제 #51
0
파일: main.py 프로젝트: turbofish/mcverify
def parse_arguments():
    """
    Fnord
    """
    # {{{
    LOG.debug("Parsing arguments...")
    parser = argparse.ArgumentParser()

    parser.add_argument("directory", type=str,
            help="Directory to be scanned")
    parser.add_argument("-c", "--config", type=str,
            help="Configuration file")

    args = parser.parse_args()

    return args
예제 #52
0
 def __wrapper(*args, **kwargs):
     timer = 0
     while(True):
         try:
             if timer <= times:
                 result = f(*args, **kwargs)
                 return result
         except Exception, e:
             LOG.debug('Do DB action Exception: %s' % traceback.format_exc())
             if timer < times:
                 timer += 1
                 time.sleep(interval)
                 LOG.error('Start to retry to do db action, TIME: %s' % timer)
                 continue
             else:
                 LOG.error('Do DB Exception: %s' % traceback.format_exc())
                 raise e
예제 #53
0
 def getServerList(self, addr=(const.NETWORK_MASTER_SERVER_HOST, const.NETWORK_MASTER_SERVER_PORT)):
     payload = struct.pack("B", const.NETWORK_MASTER_SERVER_VERSION)
     self.sendMsg_UDP(const.PACKET_UDP_CLIENT_GET_LIST, payload, addr=addr)
     p = self.receiveMsg_UDP(datapacket=True)
     if p.command == const.PACKET_UDP_MASTER_RESPONSE_LIST:
         protocol_version = p.recv_uint8()
         
         if protocol_version == 1:
             number = p.recv_uint16()
             servers = []
             LOG.debug("got response from master server with %d servers:" % number)
             for i in range(0, number):
                 [ip, port] = p.recv_something('4sH')
                 ip = socket.inet_ntoa(ip)
                 servers.append((ip, port))
                 LOG.debug(" %s:%d" % (ip, port))
             return servers
         else:
             raise _error.WrongVersion("master server list request", protocol_version, const.NETWORK_MASTER_SERVER_VERSION)
예제 #54
0
    def check(self, directory, files):
        # {{{
        super(CheckerPath, self).check(directory, files)

        # Get the correct path from the configuration file
        pattern_str = get_param('patterns', 'path')

        pat = re.compile(pattern_str)

        LOG.debug("matching %s with %s",directory,pattern_str)
        mat = pat.match(directory)

        if mat:
            result = True
        else:
            LOG.warn("Path '%s' does not match pattern '%s'")
            result = False

        return result
예제 #55
0
    def clear_completed_lines(self):
        lines_done = 0
        # we must start from the top so the clearing
        # doesn't affect this loop
        for y in reversed(range(self.board.height)):
            is_done = True
            for x in range(self.board.width):
                block = self.board.block_at(x, y)
                if not block:
                    is_done = False
                    break

            if is_done:
                LOG.debug("Clearing line %d" % y)
                self.board.clear_line(y)
                lines_done += 1

        self.completed_lines += lines_done

        return lines_done
예제 #56
0
 def receiveMsg_UDP(self, datapacket = False, useaddr = False):
     if self.socket_udp is None:
         raise _error.ConnectionError("no udp socket for receiving")
     if useaddr:
         data, addr = self.socket_udp.recvfrom(4096)
     else:
         data = self.socket_udp.recv(4096)
         addr = None
     #print data
     size, command = networking.parsePacketHeader(data)
     LOG.debug("received size: %d, command: %d"% (size, command))
     content = data[const.HEADER.size:]
     if datapacket:
         ret = DataPacket(size, command, content)
         ret.addr = addr
     else:
         if useaddr:
             ret = addr, size, command, content
         else:
             ret = size, command, content
     return ret
예제 #57
0
    def _run_thread(self):
        LOG.debug("Started game engine thread")
        self._running = True

        try:
            self.game_state.start_new_drop()
            self.print_game()

            while not self._exiting:
                a = time.time()
                while time.time()-a < DROPPING_TIMEOUT \
                        and not self._exiting and not self._restart_timeout \
                        and not self.game_state.game_is_over():
                    time.sleep(0.1)

                if not self._exiting and not self._restart_timeout \
                    and not self.game_state.game_is_over():
                    self._drop_timeout_update()

                if self.game_state.game_is_over():
                    self._exiting = True

                self._restart_timeout = False

            LOG.debug("Engine thread terminated")

        except Exception:
            LOG.debug("Engine thread just crashed!", exc_info=True)

        self._running = False
예제 #58
0
    def getGRFInfo(self, grfs, addr=None):
        p = DataPacket(0, const.PACKET_UDP_CLIENT_GET_NEWGRFS)
        p.send_uint8(len(grfs))
        for grf in grfs:
            p.send_something('4s16s', grf)
        self.sendMsg_UDP(p.command, p.data, addr=addr)
        p = self.receiveMsg_UDP(True, useaddr=not addr is None)
        if p is None:
            LOG.debug("unable to receive UDP packet")
            return None
        newgrfs = []
        if p.command == const.PACKET_UDP_SERVER_NEWGRFS:
            reply_count = p.recv_uint8()
            for i in range(0, reply_count):
                [grfid, md5sum] = p.recv_something('4s16s')
                grfname = p.recv_str()
                newgrfs.append([grfid, md5sum, grfname])

            LOG.debug("Got reply to grf request with %d grfs:" % reply_count)
            for grf in newgrfs:
                LOG.debug(" %s - %s - %s" % (grf[0].encode("hex"), grf[1].encode("hex"), grf[2]))
            
            if not addr is None:
                return p.addr, newgrfs
            else:
                return newgrfs
        else:
            raise _error.UnexpectedResponse("PACKET_UDP_CLIENT_GET_NEWGRFS", str(p.command))