rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
rth = None def __init__(self, domid): | def __init__(self, vif): | def commit(self): msg = os.read(self.msgfd.fileno(), 4) if msg != 'done': print 'Unknown message: %s' % msg |
if not self.rth: self.rth = netlink.rtnl() self.devname = self._startimq(domid) dev = self.rth.getlink(self.devname) if not dev: raise BufferedNICException('could not find device %s' % self.devname) self.dev = dev['index'] self.handle = qdisc.TC_H_ROOT self.q = qdisc.QueueQdisc() | self.vif = vif self.pool = Netbufpool(selectnetbuf()) self.rth = getrth() self.setup() | def __init__(self, domid): self.installed = False |
self._setup() | self.install() | def postsuspend(self): if not self.installed: self._setup() |
req = qdisc.changerequest(self.dev, self.handle, self.q) | req = qdisc.changerequest(self.bufdevno, self.handle, self.q) | def _sendqmsg(self, action): self.q.action = action req = qdisc.changerequest(self.dev, self.handle, self.q) self.rth.talk(req.pack()) |
def _setup(self): q = self.rth.getqdisc(self.dev) | return True def setup(self): """install Remus queue on VIF outbound traffic""" self.bufdev = self.pool.get() devname = self.bufdev.devname bufdev = self.rth.getlink(devname) if not bufdev: raise BufferedNICException('could not find device %s' % devname) self.bufdev.install(self.vif) self.bufdevno = bufdev['index'] ... | def _sendqmsg(self, action): self.q.action = action req = qdisc.changerequest(self.dev, self.handle, self.q) self.rth.talk(req.pack()) |
'discipline on %s' % self.devname) print 'installing buffer on %s' % self.devname req = qdisc.addrequest(self.dev, self.handle, self.q) | 'discipline on %s' % devname) print ('installing buffer on %s... ' % devname), req = qdisc.addrequest(self.bufdevno, self.handle, self.q) | def _setup(self): q = self.rth.getqdisc(self.dev) if q: if q['kind'] == 'queue': self.installed = True return if q['kind'] != 'pfifo_fast': raise BufferedNICException('there is already a queueing ' 'discipline on %s' % self.devname) |
req = qdisc.delrequest(self.dev, self.handle) | req = qdisc.delrequest(self.bufdevno, self.handle) | def uninstall(self): if self.installed: req = qdisc.delrequest(self.dev, self.handle) self.rth.talk(req.pack()) self.installed = False |
def _startimq(self, domid): imqebt = '/usr/lib/xen/bin/imqebt' imqdev = 'imq0' vid = 'vif%d.0' % domid for mod in ['sch_queue', 'imq', 'ebt_imq']: util.runcmd(['modprobe', mod]) util.runcmd("ip link set %s up" % (imqdev)) util.runcmd("%s -F FORWARD" % (imqebt)) util.runcmd("%s -A FORWARD -i %s -j imq --todev %s" % (im... | self.bufdev.uninstall() self.pool.put(self.bufdev) | def _startimq(self, domid): # stopgap hack to set up IMQ for an interface. Wrong in many ways. imqebt = '/usr/lib/xen/bin/imqebt' imqdev = 'imq0' vid = 'vif%d.0' % domid for mod in ['sch_queue', 'imq', 'ebt_imq']: util.runcmd(['modprobe', mod]) util.runcmd("ip link set %s up" % (imqdev)) util.runcmd("%s -F FORWARD" % (... |
return 'VM %d (%s), MACs: [%s], disks: [%s]' % \ (self.domid, self.name, self.epoch, ', '.join(self.macs), | return 'VM %d (%s), vifs: [%s], disks: [%s]' % \ (self.domid, self.name, ', '.join([str(v) for v in self.vifs]), | def __str__(self): return 'VM %d (%s), MACs: [%s], disks: [%s]' % \ (self.domid, self.name, self.epoch, ', '.join(self.macs), ', '.join([str(d) for d in self.disks])) |
(pci_list, cfg_list) = save_pci_conf_space([self.name]) pos = self.find_cap_offset(PCI_CAP_ID_AF) self.pci_conf_write8(pos + PCI_AF_CTL, PCI_AF_CTL_FLR) time.sleep(0.100) restore_pci_conf_space((pci_list, cfg_list)) | af_pos = self.find_cap_offset(PCI_CAP_ID_AF) self.do_AF_FLR(af_pos) | def do_FLR(self, is_hvm, strict_check): """ Perform FLR (Functional Level Reset) for the device. """ if self.dev_type == DEV_TYPE_PCIe_ENDPOINT: # If PCIe device supports FLR, we use it. if self.pcie_flr: (pci_list, cfg_list) = save_pci_conf_space([self.name]) pos = self.find_cap_offset(PCI_CAP_ID_EXP) self.pci_conf_wr... |
self.do_FLR_for_integrated_device() | if self.slot == 0x02 and self.func == 0x0: vendor_id = self.pci_conf_read16(PCI_VENDOR_ID) if vendor_id != VENDOR_INTEL: return class_id = self.pci_conf_read16(PCI_CLASS_DEVICE) if class_id != PCI_CLASS_ID_VGA: return device_id = self.pci_conf_read16(PCI_DEVICE_ID) if device_id == PCI_DEVICE_ID_IGFX_GM45: self.do_FLR_... | def do_FLR(self, is_hvm, strict_check): """ Perform FLR (Functional Level Reset) for the device. """ if self.dev_type == DEV_TYPE_PCIe_ENDPOINT: # If PCIe device supports FLR, we use it. if self.pcie_flr: (pci_list, cfg_list) = save_pci_conf_space([self.name]) pos = self.find_cap_offset(PCI_CAP_ID_EXP) self.pci_conf_wr... |
t = xstransact("%s/device" % self.vmpath) | def _releaseDevices(self, suspend = False): """Release all domain's devices. Nothrow guarantee.""" t = xstransact("%s/device" % self.vmpath) if self.image: try: for dev in t.list('tap'): log.debug("Early removing %s", dev); self.getDeviceController('tap').destroyDevice(dev, True) time.sleep(0.1) log.debug("Destroying ... | |
for dev in t.list('tap'): log.debug("Early removing %s", dev); self.getDeviceController('tap').destroyDevice(dev, True) time.sleep(0.1) | def _releaseDevices(self, suspend = False): """Release all domain's devices. Nothrow guarantee.""" t = xstransact("%s/device" % self.vmpath) if self.image: try: for dev in t.list('tap'): log.debug("Early removing %s", dev); self.getDeviceController('tap').destroyDevice(dev, True) time.sleep(0.1) log.debug("Destroying ... | |
if devclass is 'tap': continue | def _releaseDevices(self, suspend = False): """Release all domain's devices. Nothrow guarantee.""" t = xstransact("%s/device" % self.vmpath) if self.image: try: for dev in t.list('tap'): log.debug("Early removing %s", dev); self.getDeviceController('tap').destroyDevice(dev, True) time.sleep(0.1) log.debug("Destroying ... | |
return XEN_API_ON_CRASH_BEHAVIOUR_LEGACY[v] \ if v in XEN_API_ON_CRASH_BEHAVIOUR else v | if v in XEN_API_ON_CRASH_BEHAVIOUR: return XEN_API_ON_CRASH_BEHAVIOUR_LEGACY[v] else: return v | def convert_on_crash(v): v = str(v) return XEN_API_ON_CRASH_BEHAVIOUR_LEGACY[v] \ if v in XEN_API_ON_CRASH_BEHAVIOUR else v |
'name': str, | def scrub_password(data): if type(data) == dict or type(data) == XendConfig: scrubbed = {} for key in data.keys(): if key == "vncpasswd": scrubbed[key] = "XXXXXXXX" else: scrubbed[key] = scrub_password(data[key]) return scrubbed elif type(data) == list: if len(data) == 2 and type(data[0]) == str and data[0] == 'vncpass... | |
'name', | def scrub_password(data): if type(data) == dict or type(data) == XendConfig: scrubbed = {} for key in data.keys(): if key == "vncpasswd": scrubbed[key] = "XXXXXXXX" else: scrubbed[key] = scrub_password(data[key]) return scrubbed elif type(data) == list: if len(data) == 2 and type(data[0]) == str and data[0] == 'vncpass... | |
self.rta_len = align(self.fmtlen + len(self.body)) | self.rta_len = self.fmtlen + align(len(self.body), 2) | def pack(self): self.rta_len = align(self.fmtlen + len(self.body)) s = struct.pack(self.fmt, self.rta_len, self.rta_type) + self.body pad = self.rta_len - len(s) if pad: s += '\0' * pad return s |
self.body = msg[align(self.fmtlen):self.rta_len] | self.body = msg[self.fmtlen:self.rta_len] | def unpack(self, msg): args = struct.unpack(self.fmt, msg[:self.fmtlen]) self.rta_len, self.rta_type = args |
t = xstransact("%s/device" % self.vmpath) | def _releaseDevices(self, suspend = False): """Release all domain's devices. Nothrow guarantee.""" if self.image: try: log.debug("Destroying device model") self.image.destroyDeviceModel() except Exception, e: log.exception("Device model destroy failed %s" % str(e)) else: log.debug("No device model") | |
s = scsiinfo.split() | s = scsiinfo.replace(']', '] ').split() | def _vscsi_get_scsidevices_by_lsscsi(option = ""): """ get all scsi devices information by lsscsi """ devices = [] for scsiinfo in os.popen('{ lsscsi -g %s; } 2>/dev/null' % option).readlines(): s = scsiinfo.split() hctl = s[0][1:-1] try: devname = s[-2].split('/dev/')[1] except IndexError: devname = None try: sg = s... |
dtd = xmldtd.load_dtd(self.dtd) parser = xmlproc.XMLProcessor() parser.set_application(xmlval.ValidatingApp(dtd, parser)) parser.dtd = dtd parser.ent = dtd parser.parse_resource(file) | try: dtd = etree.DTD(open(self.dtd, 'r')) except IOError: warnings.warn('DTD file %s not found.' % (self.dtd), UserWarning) return tree = etree.parse(file) root = tree.getroot() if not dtd.validate(root): self.handle_dtd_errors(dtd) | def check_dtd(self, file): """ Check file against DTD. Use this if possible as it gives nice error messages """ dtd = xmldtd.load_dtd(self.dtd) parser = xmlproc.XMLProcessor() parser.set_application(xmlval.ValidatingApp(dtd, parser)) parser.dtd = dtd parser.ent = dtd parser.parse_resource(file) |
dtd = xmldtd.load_dtd(self.dtd) app = xmlval.ValidatingApp(dtd, self) app.set_locator(self) self.dom2sax(dom, app) def report_error(self, number, args=None): self.errors = xmlproc.errors.english | def check_dom_against_dtd(self, dom): """ Check DOM again DTD. Doesn't give as nice error messages. (no location info) """ dtd = xmldtd.load_dtd(self.dtd) app = xmlval.ValidatingApp(dtd, self) app.set_locator(self) self.dom2sax(dom, app) | |
msg = self.errors[number] if args != None: msg = msg % args except KeyError: msg = self.errors[4002] % number print msg | dtd = etree.DTD(open(self.dtd, 'r')) except IOError: warnings.warn('DTD file %s not found.' % (self.dtd), UserWarning) return root = etree.XML(dom.toxml()) if not dtd.validate(root): self.handle_dtd_errors(dtd) def handle_dtd_errors(self, dtd): for err in dtd.error_log: err_str = 'ERROR: %s\n' % (str(err)... | def report_error(self, number, args=None): self.errors = xmlproc.errors.english try: msg = self.errors[number] if args != None: msg = msg % args except KeyError: msg = self.errors[4002] % number # Unknown err msg :-) print msg sys.exit(-1) |
def get_line(self): return -1 def get_column(self): return -1 def dom2sax(self, dom, app): """ Take a dom tree and tarverse it, issuing SAX calls to app. """ for child in dom.childNodes: if child.nodeType == child.TEXT_NODE: data = child.nodeValue app.handle_data(data, 0, len(data)) else: app.handle_start_tag( child.... | def report_error(self, number, args=None): self.errors = xmlproc.errors.english try: msg = self.errors[number] if args != None: msg = msg % args except KeyError: msg = self.errors[4002] % number # Unknown err msg :-) print msg sys.exit(-1) | |
try: return (devname, os.stat(n).st_rdev) except Exception, ex: pass | def blkdev_name_to_number(name): """Take the given textual block-device name (e.g., '/dev/sda1', 'hda') and return the device number used by the OS. """ n = expand_dev_name(name) devname = 'virtual-device' devnum = None try: return (devname, os.stat(n).st_rdev) except Exception, ex: pass scsi_major = [ 8, 65, 66, 6... | |
if count < 100: continue | if count > 100: break | def createDeviceModel(self, restore = False): if self.device_model is None: return if self.pid: return # Execute device model. #todo: Error handling args = self.getDeviceModelArgs(restore) env = dict(os.environ) if self.display: env['DISPLAY'] = self.display if self.xauthority: env['XAUTHORITY'] = self.xauthority uniqu... |
nodeload[i] = int(nodeload[i] * 16 / len(info['node_to_cpu'][i])) if len(info['node_to_cpu'][i]) == 0 or i not in node_list: | if len(info['node_to_cpu'][i]) == 0: | def find_relaxed_node(node_list): import sys nr_nodes = info['nr_nodes'] if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = dom.ge... |
cores_per_node = info['nr_cpus'] / info['nr_nodes'] nodes_required = (self.info['VCPUs_max'] + cores_per_node - 1) / cores_per_node if nodes_required > 1: log.debug("allocating %d NUMA nodes", nodes_required) best_nodes = find_relaxed_node(filter(lambda x: x != best_node, range(0,info['nr_nodes']))) for i in best_nodes... | best_nodes = find_relaxed_node(filter(lambda x: x != best_node, range(0,info['nr_nodes']))) for node_idx in best_nodes: if len(cpumask) >= self.info['VCPUs_max']: break cpumask = cpumask + info['node_to_cpu'][node_idx] log.debug("allocating additional NUMA node %d", node_idx) | def find_relaxed_node(node_list): import sys nr_nodes = info['nr_nodes'] if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = dom.ge... |
dev_type = sxp.name(dev_config) | def device_create(self, dev_config): """Create a new device. | |
if os.path.dirname(file) == "": | if file and os.path.dirname(file) == "": | def get_xend_tcp_xmlrpc_server_ssl_key_file(self): name = 'xend-tcp-xmlrpc-server-ssl-key-file' file = self.get_config_string(name) if os.path.dirname(file) == "": file = auxbin.xen_configdir() + '/' + file; if not os.path.exists(file): raise XendError("invalid xend config %s: directory '%s' does not exist" % (name, fi... |
if not os.path.exists(file): | if file and not os.path.exists(file): | def get_xend_tcp_xmlrpc_server_ssl_key_file(self): name = 'xend-tcp-xmlrpc-server-ssl-key-file' file = self.get_config_string(name) if os.path.dirname(file) == "": file = auxbin.xen_configdir() + '/' + file; if not os.path.exists(file): raise XendError("invalid xend config %s: directory '%s' does not exist" % (name, fi... |
if os.path.dirname(file) == "": | if file and os.path.dirname(file) == "": | def get_xend_tcp_xmlrpc_server_ssl_cert_file(self): name = 'xend-tcp-xmlrpc-server-ssl-cert-file' file = self.get_config_string(name) if os.path.dirname(file) == "": file = auxbin.xen_configdir() + '/' + file; if not os.path.exists(file): raise XendError("invalid xend config %s: directory '%s' does not exist" % (name, ... |
if not os.path.exists(file): | if file and not os.path.exists(file): | def get_xend_tcp_xmlrpc_server_ssl_cert_file(self): name = 'xend-tcp-xmlrpc-server-ssl-cert-file' file = self.get_config_string(name) if os.path.dirname(file) == "": file = auxbin.xen_configdir() + '/' + file; if not os.path.exists(file): raise XendError("invalid xend config %s: directory '%s' does not exist" % (name, ... |
vif_properties = \ map(server.xenapi.VIF.get_runtime_properties, vif_refs) | vif_properties = [] for vif_ref in vif_refs: vif_property = server.xenapi.VIF.get_runtime_properties(vif_ref) vif_property['mac'] = server.xenapi.VIF.get_MAC(vif_ref) vif_properties.append(vif_property) | def xm_network_list(args): (use_long, params) = arg_check_for_resource_list(args, "network-list") dom = params[0] if serverType == SERVER_XEN_API: vif_refs = server.xenapi.VM.get_VIFs(get_single_vm(dom)) vif_properties = \ map(server.xenapi.VIF.get_runtime_properties, vif_refs) devs = map(lambda (handle, properties):... |
balloon.free(memory + shadow, dominfo) | vtd_mem = 0 info = xc.physinfo() if 'hvm_directio' in info['virt_caps']: vtd_mem = 4 * (dominfo.info['memory_static_max'] / 1024 / 1024) vtd_mem = ((vtd_mem + 1023) / 1024) * 1024 balloon.free(memory + shadow + vtd_mem, dominfo) | def restore(xd, fd, dominfo = None, paused = False, relocating = False): try: if not os.path.isdir("/var/lib/xen"): os.makedirs("/var/lib/xen") except Exception, exn: log.exception("Can't create directory '/var/lib/xen'") raise XendError("Can't create directory '/var/lib/xen'") signature = read_exact(fd, len(SIGNATURE... |
return "d%d" %(self,disk,) | return "d%d" %(self.disk,) | def __repr__(self): if self.part is not None: return "d%dp%d" %(self.disk, self.part) else: return "d%d" %(self,disk,) |
if target is not None and int(target) is self.domid : | if target is not None and int(target) == self.domid: | def getStubdomDomid(self): dom_list = xstransact.List('/local/domain') for d in dom_list: target = xstransact.Read('/local/domain/' + d + '/target') if target is not None and int(target) is self.domid : return int(d) return None |
ret = ret + ['-vcpu_avail', str(self.vm.getVCpuAvail())] | ret = ret + ['-vcpu_avail', hex(self.vm.getVCpuAvail())] | def parseDeviceModelArgs(self, vmConfig): ret = ImageHandler.parseDeviceModelArgs(self, vmConfig) ret = ret + ['-vcpus', str(self.vm.getVCpuCount())] ret = ret + ['-vcpu_avail', str(self.vm.getVCpuAvail())] |
def format_comment(level, comment): indent = reduce(lambda x,y: x + " ", range(level), "") s = "%s/*\n" % indent s += "%s * " % indent comment = comment.replace("\n", "\n%s * " % indent) x = re.compile(r'^%s \* $' % indent, re.MULTILINE) comment = x.sub("%s *" % indent, comment) s += comment s += "\n" s += "%s */" % i... | class Builtin(Type): """Builtin type""" def __init__(self, typename, **kwargs): Type.__init__(self, typename, **kwargs) | def format_comment(level, comment): indent = reduce(lambda x,y: x + " ", range(level), "") s = "%s/*\n" % indent s += "%s * " % indent comment = comment.replace("\n", "\n%s * " % indent) x = re.compile(r'^%s \* $' % indent, re.MULTILINE) comment = x.sub("%s *" % indent, comment) s += comment s += "\n" s += "%s */" % i... |
def libxl_C_type_of(ty): return ty.typename | class UInt(Type): def __init__(self, w, **kwargs): kwargs.setdefault('namespace', None) Type.__init__(self, "uint%d_t" % w, **kwargs) | def libxl_C_type_of(ty): return ty.typename |
def libxl_C_instance_of(ty, instancename): if isinstance(ty, libxltypes.BitField): return libxl_C_type_of(ty) + " " + instancename + ":%d" % ty.width elif isinstance(ty, libxltypes.Aggregate) and ty.typename is None: if instancename is None: return libxl_C_type_define(ty) else: return libxl_C_type_define(ty) + " " + in... | self.width = w | def libxl_C_instance_of(ty, instancename): if isinstance(ty, libxltypes.BitField): return libxl_C_type_of(ty) + " " + instancename + ":%d" % ty.width elif isinstance(ty, libxltypes.Aggregate) and ty.typename is None: if instancename is None: return libxl_C_type_define(ty) else: return libxl_C_type_define(ty) + " " + in... |
def libxl_C_type_define(ty, indent = ""): s = "" if isinstance(ty, libxltypes.Aggregate): if ty.comment is not None: s += format_comment(0, ty.comment) | class BitField(Type): def __init__(self, ty, w, **kwargs): kwargs.setdefault('namespace', None) Type.__init__(self, ty.typename, **kwargs) | def libxl_C_type_define(ty, indent = ""): s = "" if isinstance(ty, libxltypes.Aggregate): if ty.comment is not None: s += format_comment(0, ty.comment) if ty.typename is None: s += "%s {\n" % ty.kind else: s += "typedef %s {\n" % ty.kind for f in ty.fields: if f.comment is not None: s += format_comment(4, f.comment) ... |
if ty.typename is None: s += "%s {\n" % ty.kind else: s += "typedef %s {\n" % ty.kind | self.width = w | def libxl_C_type_define(ty, indent = ""): s = "" if isinstance(ty, libxltypes.Aggregate): if ty.comment is not None: s += format_comment(0, ty.comment) if ty.typename is None: s += "%s {\n" % ty.kind else: s += "typedef %s {\n" % ty.kind for f in ty.fields: if f.comment is not None: s += format_comment(4, f.comment) ... |
for f in ty.fields: if f.comment is not None: s += format_comment(4, f.comment) x = libxl_C_instance_of(f.type, f.name) if f.const: x = "const " + x x = x.replace("\n", "\n ") s += " " + x + ";\n" if ty.typename is None: s += "}" else: s += "} %s" % ty.typename else: raise NotImplementedError("%s" % type(ty)) ret... | class Field(object): """An element of an Aggregate type""" def __init__(self, type, name, **kwargs): self.type = type self.name = name self.const = kwargs.setdefault('const', False) self.comment = kwargs.setdefault('comment', None) self.keyvar_expr = kwargs.setdefault('keyvar_expr', None) | s += "typedef %s {\n" % ty.kind |
if __name__ == '__main__': if len(sys.argv) < 3: print >>sys.stderr, "Usage: gentypes.py <idl> <header>" sys.exit(1) | class Aggregate(Type): """A type containing a collection of other types""" def __init__(self, kind, typename, fields, **kwargs): Type.__init__(self, typename, **kwargs) | s += "typedef %s {\n" % ty.kind |
idl = sys.argv[1] (_,types) = libxltypes.parse(idl) header = sys.argv[2] print "outputting libxl types to %s" % header | self.kind = kind | s += "typedef %s {\n" % ty.kind |
f = open(header, "w") f.write(""" | self.fields = [] for f in fields: if len(f) == 2: n,t = f const = False comment = None elif len(f) == 3: n,t,const = f comment = None else: n,t,const,comment = f self.fields.append(Field(t,n,const=const,comment=comment)) | s += "typedef %s {\n" % ty.kind |
/* * DO NOT EDIT. * * This file is autogenerated by * "%s" */ """ % " ".join(sys.argv)) for t in types: f.write(libxl_C_type_define(t) + ";\n") f.write("\n") | class Struct(Aggregate): def __init__(self, name, fields, **kwargs): Aggregate.__init__(self, "struct", name, fields, **kwargs) | f.write("""#ifndef __LIBXL_TYPES_H |
f.write(""" | class Union(Aggregate): def __init__(self, name, fields, **kwargs): Aggregate.__init__(self, "union", name, fields, **kwargs) class KeyedUnion(Aggregate): """A union which is keyed of another variable in the parent structure""" def __init__(self, name, keyvar_name, fields, **kwargs): Aggregate.__init__(self, "union", ... | f.write("""#ifndef __LIBXL_TYPES_H |
for ty in [t for t in types if t.autogenerate_destructor]: | for ty in [t for t in types if t.destructor_fn is not None and t.autogenerate_destructor]: | f.write("""#ifndef __LIBXL_TYPES_H |
if vmConfig['platform'].get('localtime', 0): | if int(vmConfig['platform'].get('localtime', 0)): | def configure(self, vmConfig): """Config actions common to all unix-like domains.""" if '_temp_using_bootloader' in vmConfig: self.bootloader = True self.kernel = vmConfig['_temp_kernel'] self.cmdline = vmConfig['_temp_args'] self.ramdisk = vmConfig['_temp_ramdisk'] else: self.kernel = vmConfig['PV_kernel'] self.cmdlin... |
dpci_uuid = pci_dev_info.get('uuid', uuid.createString()) pci_dev_info['uuid'] = dpci_uuid | pci_dev_info['uuid'] = uuid.createString() if not pci_dev_info.has_key('key'): pci_dev_info['key'] = "%02x:%02x.%x" % \ (int(pci_dev_info['bus'], 16), int(pci_dev_info['slot'], 16), int(pci_dev_info['func'], 16)) if not pci_dev_info.has_key('vdevfn'): pci_dev_info['vdevfn'] = "0x%02x" % AUTO_PHP_SLOT | def pci_convert_sxp_to_dict(dev_sxp): """Convert pci device sxp to dict @param dev_sxp: device configuration @type dev_sxp: SXP object (parsed config) @return: dev_config @rtype: dictionary """ # Parsing the device SXP's. In most cases, the SXP looks # like this: # # [device, [vif, [mac, xx:xx:xx:xx:xx:xx], [ip 1.3.4.... |
title_match = re.match('^menuentry "(.*)" (.*){', l) | title_match = re.match('^menuentry ["\'](.*)["\'] (.*){', l) | def parse(self, buf = None): if buf is None: if self.filename is None: raise ValueError, "No config file defined to parse!" |
dom0._waitForDeviceUUID(dom0.create_vbd(vbd, disk)) | mounted_vbd_uuid = dom0.create_vbd(vbd, disk); dom0._waitForDeviceUUID(mounted_vbd_uuid) | def _configureBootloader(self): """Run the bootloader if we're configured to do so.""" |
dom0.destroyDevice('tap', BOOTLOADER_LOOPBACK_DEVICE) | _, vbd_info = dom0.info['devices'][mounted_vbd_uuid] dom0.destroyDevice(dom0.getBlockDeviceClass(vbd_info['devid']), BOOTLOADER_LOOPBACK_DEVICE, force = True) | def _configureBootloader(self): """Run the bootloader if we're configured to do so.""" |
self.domains_lock.acquire() try: self._refresh(refresh_shutdown = False) | resu = False count = 0 while True: resu = self.domains_lock.acquire(0) if resu or count < 20: break count += 1 try: if resu: self._refresh(refresh_shutdown = False) | def list(self, state = DOM_STATE_RUNNING): """Get list of domain objects. |
self.domains_lock.release() | if resu: self.domains_lock.release() | def list(self, state = DOM_STATE_RUNNING): """Get list of domain objects. |
nr_nodes = info['max_node_id']+1 | nr_nodes = info['max_node_index'] + 1 | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
node_cpumask = info['node_to_cpu'][i] | node_cpumask = node_to_cpu[i] | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
if len(info['node_to_cpu'][i]) == 0: | if len(node_to_cpu[i]) == 0: | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
nodeload[i] = int(nodeload[i] * 16 / len(info['node_to_cpu'][i])) | nodeload[i] = int(nodeload[i] * 16 / len(node_to_cpu[i])) | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
info = xc.physinfo() if info['nr_nodes'] > 1: node_memory_list = info['node_to_memory'] | info = xc.numainfo() if info['max_node_index'] > 0: node_memory_list = info['node_memfree'] node_to_cpu = [] for i in range(0, info['max_node_index'] + 1): node_to_cpu.append([]) for cpu, node in enumerate(xc.topologyinfo()['cpu_to_node']): node_to_cpu[node].append(cpu) | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
for i in range(0, info['max_node_id']+1): if node_memory_list[i] >= needmem and len(info['node_to_cpu'][i]) > 0: | for i in range(0, info['max_node_index'] + 1): if node_memory_list[i] >= needmem and len(node_to_cpu[i]) > 0: | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
cpumask = info['node_to_cpu'][best_node] best_nodes = find_relaxed_node(filter(lambda x: x != best_node, range(0,info['max_node_id']+1))) | cpumask = node_to_cpu[best_node] best_nodes = find_relaxed_node(filter(lambda x: x != best_node, range(0,info['max_node_index']+1))) | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
cpumask = cpumask + info['node_to_cpu'][node_idx] | cpumask = cpumask + node_to_cpu[node_idx] | def find_relaxed_node(node_list): import sys nr_nodes = info['max_node_id']+1 if node_list is None: node_list = range(0, nr_nodes) nodeload = [0] nodeload = nodeload * nr_nodes from xen.xend import XendDomain doms = XendDomain.instance().list('all') for dom in filter (lambda d: d.domid != self.domid, doms): cpuinfo = d... |
sys.exit(1) | usage(name) | def arg_check_for_resource_list(args, name): use_long = 0 try: (options, params) = getopt.gnu_getopt(args, 'l', ['long']) except getopt.GetoptError, opterr: err(opterr) sys.exit(1) for (k, v) in options: if k in ['-l', '--long']: use_long = 1 if len(params) == 0: print 'No domain parameter given' usage(name) if len(p... |
self.pci_perm_dev_config = pci_perm_dev_config | def __devIsUnconstrained( self ): if os.path.exists(PERMISSIVE_CONFIG_FILE): try: fin = file(PERMISSIVE_CONFIG_FILE, 'rb') try: pci_perm_dev_config = parse(fin) finally: fin.close() if pci_perm_dev_config is None: pci_perm_dev_config = [''] else: pci_perm_dev_config.insert(0, '') self.pci_perm_dev_config = pci_perm_dev... | |
self.pci_perm_dev_config = ['xend-pci-perm-devs'] | pci_perm_dev_config = ['xend-pci-perm-devs'] | def __devIsUnconstrained( self ): if os.path.exists(PERMISSIVE_CONFIG_FILE): try: fin = file(PERMISSIVE_CONFIG_FILE, 'rb') try: pci_perm_dev_config = parse(fin) finally: fin.close() if pci_perm_dev_config is None: pci_perm_dev_config = [''] else: pci_perm_dev_config.insert(0, '') self.pci_perm_dev_config = pci_perm_dev... |
cfg["vcpus_params"]["weight"] = \ int(sxp.child_value(sxp_cfg, "cpu_weight", 256)) cfg["vcpus_params"]["cap"] = \ int(sxp.child_value(sxp_cfg, "cpu_cap", 0)) | if not cfg["vcpus_params"].has_key("weight"): cfg["vcpus_params"]["weight"] = \ int(sxp.child_value(sxp_cfg, "cpu_weight", 256)) if not cfg["vcpus_params"].has_key("cap"): cfg["vcpus_params"]["cap"] = \ int(sxp.child_value(sxp_cfg, "cpu_cap", 0)) | def _parse_sxp(self, sxp_cfg): """ Populate this XendConfig using the parsed SXP. |
fake_token = encode_token(str(self.test_user.id), str('asdf;ljasdf'), reverse('urlcrypt_test_view')) | fake_token = encode_token([str(self.test_user.id), reverse('urlcrypt_test_view'), str(int(time.time()))], secret_key_f) | def test_login_token_failed_hax0r(self): fake_token = 'asdf;lhasdfdso' response = self.client.get(reverse('urlcrypt_redirect', args=(fake_token,))) self.assertRedirects(response, URLCRYPT_LOGIN_URL) fake_token = encode_token(str(self.test_user.id), str('asdf;ljasdf'), reverse('urlcrypt_test_view')) response = self.cli... |
Only data starting from July 1st, 14:29 UTC is processed, since that is when our detector was turned on. | def process_events(filename, table, start=None, stop=None): """Do the actual data processing. This function starts a subprocess to unzip the data file, reads the data line by line and stores it in a pytables table, row by row. Only data starting from July 1st, 14:29 UTC is processed, since that is when our detector w... | |
Hmu0, He1, Hmu1, He2, Hmu2, He3, Hmu3, P200, T200 = data | Hmu0, He1, Hmu1, He2, Hmu2, He3, Hmu3, T200, P200 = data | def process_events(filename, table, start=None, stop=None): """Do the actual data processing. This function starts a subprocess to unzip the data file, reads the data line by line and stores it in a pytables table, row by row. Only data starting from July 1st, 14:29 UTC is processed, since that is when our detector w... |
pylab.hist(dt, bins=100, range=(-1, 1), histtype='step', label="Shift %+g s" % shift) | try: pylab.hist(dt, bins=100, range=(-1, 1), histtype='step', label="Shift %+g s" % shift) except NameError: pass | def do_timeshifts(hevents, kevents, shifts, dtlimit=None, limit=None, h=None, k=None): """Search for coincidences using multiple time shifts This function enables you to search for coincidences multiple times, using a list of time shifts. Given a data file, the events are read into arrays and passed on to the search_c... |
pylab.legend() pylab.xlabel("Time difference (s)") pylab.ylabel("Counts") pylab.title("Nearest neighbour events for HiSPARC / KASCADE") pylab.gca().axis('auto') pylab.gcf().show() | try: pylab.legend() pylab.xlabel("Time difference (s)") pylab.ylabel("Counts") pylab.title("Nearest neighbour events for HiSPARC / KASCADE") pylab.gca().axis('auto') pylab.gcf().show() except NameError: print "Unfortunately, the pylab interface was not available." print "No graphs at this point." | def finish_graph(): """Finish the histogram This function places a legend, axes titles and the like on the current figure. """ pylab.legend() pylab.xlabel("Time difference (s)") pylab.ylabel("Counts") pylab.title("Nearest neighbour events for HiSPARC / KASCADE") pylab.gca().axis('auto') pylab.gcf().show() |
cond = '%d <= timestamp <= %d' % \ | cond = '(%d <= timestamp) & (timestamp <= %d)' % \ | def store_data(dst_file, dst_group, src_filename, t0, t1): """Copy data from a temporary file to the destination file This function takes a file containing downloaded data and copies it to the destination file, based on start and end timestamps. This can be further optimized at the expense of spaghetti code. """ # O... |
def deg_to_rad(*args): """Take an optional amount of degree values and replace with radians. INPUT *args: Any number of arguments of ints, floats, and arrays OUTPUT new_values: Original inputs converted to radians """ | def deg_rad(conversion, *args): """Take an optional amount of values and convert between degrees/radians. INPUT conversion: (str) desired output, either 'degrees' or 'radians' *args: Will accept ints, floats, and ndarrrays (from NumPy) OUTPUT results: Original inputs converted to radians or degrees """ if conversion... | def deg_to_rad(*args): """Take an optional amount of degree values and replace with radians. INPUT *args: Any number of arguments of ints, floats, and arrays OUTPUT new_values: Original inputs converted to radians """ results = [] ## Iterate through each variable for arg in args: try: iterable = iter(arg) except Type... |
arg = float(arg) * (numpy.pi / 180.) | arg = float(arg) * factor | def deg_to_rad(*args): """Take an optional amount of degree values and replace with radians. INPUT *args: Any number of arguments of ints, floats, and arrays OUTPUT new_values: Original inputs converted to radians """ results = [] ## Iterate through each variable for arg in args: try: iterable = iter(arg) except Type... |
arg.flat[index] = float(arg.flat[index]) * (numpy.pi / 180.) | arg.flat[index] = float(arg.flat[index]) * factor | def deg_to_rad(*args): """Take an optional amount of degree values and replace with radians. INPUT *args: Any number of arguments of ints, floats, and arrays OUTPUT new_values: Original inputs converted to radians """ results = [] ## Iterate through each variable for arg in args: try: iterable = iter(arg) except Type... |
pitch_0, rct_matrix[:,2] = deg_rad("degrees", pitch_0, rct_matrix[:,2]) | def rotor_analysis(rct_matrix, tip_speed_ratio, number_blades, pitch_0, blade_radius, hub_radius, lift_curve, drag_curve, method): """Returns performance statistics of a rotor. INPUT tip_speed_ratio: (float) The tip speed ratio number_blades: (int) the number of blades pitch_0 : (float) initial pitch angle re... | |
print "Joystick OK!", pygame.joystick.get_count(); | def __init__(self,width,height): resolution=width,height | |
self.keymap=(3,7,1,5,6,8,0,2) | def __init__(self,width,height): resolution=width,height | |
self.keymap=(7,5,3,1,0,2,6,8) | def __init__(self,width,height): resolution=width,height | |
print "Button pressed", key, p.cell | def move_player(self,p): | |
self.screen=pygame.display.set_mode(resolution,pygame.FULLSCREEN) | self.screen=pygame.display.set_mode(resolution) | def __init__(self,width,height): resolution=width,height |
return self.get("interface", None) | interf = self.get("interface", None) if isinstance(interf, str): return TypeNameInterfaceMap()[interf] else: return interf | def get_interface(self): """Gets the interface """ return self.get("interface", None) |
if actor.block: status = True n = actor.get_nb_output() outputs = [i for i in range(n) if actor.get_output(i) is not None ] if not outputs: status = False return status | try: if actor.block: status = True n = actor.get_nb_output() outputs = [i for i in range(n) if actor.get_output(i) is not None ] if not outputs: status = False return status except: pass | def is_stopped(self, vid, actor): """ Return True if evaluation must be stop at this vertex """ if vid in self._evaluated: return True |
return actor.block or vid in self._evaluated | stopped = False try: stopped = actor.block or vid in self._evaluated except: pass return stopped | def is_stopped(self, vid, actor): """ Return True if evaluation must be stop at this vertex """ return actor.block or vid in self._evaluated |
Annotation.extend_ad_hoc_slots("htmlText", str, None) | Annotation.extend_ad_hoc_slots("textColor", list, None) | def initialise_standard_metadata(): """Declares the standard keys used by the Node structures. Called at the end of this file""" #we declare what are the node model ad hoc data we require: AbstractNode.extend_ad_hoc_slots("position", list, [0,0], "posx", "posy") Node.extend_ad_hoc_slots("userColor", list, None, "user_c... |
except IndexError : e = None self.__eventQueue = None | except IndexError , ex: e = None self.__eventQueue = None | def call_notify(self, sender, event=None): """ Basic implementation call directly notify function Sub class can override this method to implement different call strategy (like signal slot) """ if sender == self and event == "PROCESS_QUEUE": if self.__deaf : self.__eventQueue = None elif len(self.__eventQueue) > 0 : e =... |
Annotation.extend_ad_hoc_slots("visualStyle", int, 0) | Annotation.extend_ad_hoc_slots("visualStyle", int, None) | def initialise_standard_metadata(): """Declares the standard keys used by the Node structures. Called at the end of this file""" #we declare what are the node model ad hoc data we require: AbstractNode.extend_ad_hoc_slots("position", list, [0,0], "posx", "posy") Node.extend_ad_hoc_slots("userColor", list, None, "user_c... |
self._metas = {} | self._metaValues = {} self._metaTypes = {} | def __init__(self, slots=None): observer.Observed.__init__(self) self._metas = {} |
self._metas = slots._metas.copy() | self._metaValues = slots._metaValues.copy() self._metaTypes = slots._metaTypes.copy() | def __init__(self, slots=None): observer.Observed.__init__(self) self._metas = {} |
for name, v in slots.iteritems(): _type, _value = v self.add_metadata(name, _type ) self.set_metadata(name, _value) | for name, value in slots.iteritems(): if (isinstance(value, tuple) or isinstance(value, list)) and \ len(value) == 2 and isinstance(value[0],type): typ, val = value else: typ = type(value) if value is not None else None val = value self.add_metadata(name, typ ) self.set_metadata(name, val) | def __init__(self, slots=None): observer.Observed.__init__(self) self._metas = {} |
if(not len(self._metas)): return "{}" stri = "{" for key, val in self._metas.iteritems(): stri = stri+ "\"" + key + "\" : [" + val[0].__name__ + ", " + repr(val[1]) + "]," stri = stri[:-1] + "}" return stri | if(not len(self._metaValues)): return "{}" keys = set(self._metaTypes)-set(self._metaValues) d = self._metaValues.copy() for k in keys: d[k] = None return repr(d) | def __repr__(self): if(not len(self._metas)): return "{}" stri = "{" for key, val in self._metas.iteritems(): stri = stri+ "\"" + key + "\" : [" + val[0].__name__ + ", " + repr(val[1]) + "]," stri = stri[:-1] + "}" return stri |
return len(self._metas) | return len(self._metaTypes) | def __len__(self): return len(self._metas) |
assert type(valType) == types.TypeType | def add_metadata(self, key, valType, notify=True): """Creates a new entry in the meta data registry. The data to set will be of the given 'type' type.""" assert type(valType) == types.TypeType | |
if key in self._metas : | if key == 'userColor': print key, valType if key in self._metaTypes : | def add_metadata(self, key, valType, notify=True): """Creates a new entry in the meta data registry. The data to set will be of the given 'type' type.""" assert type(valType) == types.TypeType |
self._metas[key] = [valType, None] | self._metaTypes[key] = valType | def add_metadata(self, key, valType, notify=True): """Creates a new entry in the meta data registry. The data to set will be of the given 'type' type.""" assert type(valType) == types.TypeType |
if( value == None ): return if key not in self._metas : | if value is None : return if key not in self._metaTypes : | def set_metadata(self, key, value, notify=True): """Sets the value of a meta data.""" if( value == None ): return if key not in self._metas : raise Exception("This key does not exist : " + key) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.