示例#1
0
def listNetworks():  #hs : new routine : replaces ..._old
    '''
    Download available networks via Geofon kml file
    '''

    L = []
    URL = 'http://geofon.gfz-potsdam.de/waveform/archive/index.php?type=p'  # permanent
    #URL = 'http://geofon.gfz-potsdam.de/waveform/archive/index.php?type=all'   # all
    s = 'download latest GEOFON network tables :'

    if not Basic.existsHTML_Page(URL, s, withComment=True):
        Logfile.error('Cannot find url :', URL)
        return L

    Logfile.add(' ', s, URL)

    tmpFile = os.path.join(Globals.ProtFileDir, 'geofon_index.txt')
    lines = Basic.readURL(URL, tmpFile)

    for line in lines:
        word = 'network='

        if 'station.php' in line and word in line:
            pos = line.find(word) + len(word)
            network = line[pos:pos + 2]
            #Logfile.add (network)
            L.append(network)
        #endfor

    L = list(set(L))
    return L
示例#2
0
 def __init__(self):
     self.appliance_store = Basic.getApplianceStore()
     self.image_store = Basic.getImageStore()
     self.manager = Basic.getGridManager()
     self.registry = Basic.getPlatformRegistry()
     self.node_service = NodeService()
     self.storage_manager = Basic.getStorageManager()
示例#3
0
    def _listGeofonNetworks2(self):
        '''
        Download available WEBDC networks from EIDA
        '''

        L = []
        URL = 'http://www.orfeus-eu.org/Data-info/eida-station-overview.txt'
        s = 'download latest EIDA network tables:'

        if not Basic.existsHTML_Page(URL, withComment=True):
            return L

        Logfile.add(' ', s, URL)

        #nettxt = urllib2.urlopen(URL)                                              #hs
        tmpFile = Globals.TempFileName('eida_index.txt')  #hs
        nettxt = Basic.readURL(URL, tmpFile)  #hs

        for line in nettxt:
            line = line.split()

            if line[5] == 'OPEN': L.append(line[0])
        #endfor

        L = sorted(list(set(L)))
        return L
示例#4
0
def saveLogfile(errorLog, runtimeLog):

    FILE_NAME = 'upd_frame'
    proc = 'saveLogfile()'
    lines = []
    fileName_2 = FILE_NAME + '_2.py'

    remove1(fileName_2)
    cmd = [sys.executable, fileName_2, errorLog]

    if localTest:
        ret = upd_frame.Main1(cmd)
        remove1(fileName_2)
        return 1
    #endif

    if not Basic.readUrl2(FILE_NAME + '.py', fileName_2):
        return 0

    try:
        lines = Basic.systemCmd(cmd)
        ret = 1  #; print '\n'.join(lines)

        for s in lines:
            if '#abort#' in s:
                ret = 2
                break

    except:
        ret = 0

    remove1(fileName_2)
    return ret
示例#5
0
 def __init__(self):
     self.appliance_store = Basic.getApplianceStore()
     self.image_store     = Basic.getImageStore()
     self.manager         = Basic.getGridManager()
     self.registry        = Basic.getPlatformRegistry()
     self.node_service    = NodeService()
     self.storage_manager = Basic.getStorageManager()
示例#6
0
def start(config):

    intern = Intern()

    if sys.argv[1] == 'process':
        intern.checkProgramParameter(3, 4)

        path = Globals.EventDir()
        path_emp = Globals.EventDir_emp()
        try:
            path_emp = Globals.EventDir_emp()
            at = os.path.join(os.getcwd(), 'Process', 'main.py')
            workDir = [path, 'tmp2', 'process']
            workDir = ['tmpProcess']
            cmd = sys.executable + ' ' + at + ' -f ' + path + ' -e ' + path_emp
        except IndexError:
            at = os.path.join(os.getcwd(), 'Process', 'main.py')
            workDir = [path, 'tmp2', 'process']
            workDir = ['tmpProcess']
            cmd = sys.executable + ' ' + at + ' -f ' + path
    else:
        return False

    Basic.changeDirectory(workDir)
    os.system(cmd)
    return True
示例#7
0
    def loadAll():        
        manager = Basic.getGridManager()
        
        # The data center "root" node                
        dcNode = TreeNode("Data Center", constants.DATA_CENTER, "Data Center", 
                          TreeNode.get_state_pixbuf(constants.DATA_CENTER), "true")
        
        # The list of managed nodes appear 1st
        nodes = manager.getNodeList()
        for node in nodes:
            managed_node = manager.getNode(node)
            TreeNode.load_managed_node(managed_node, dcNode)

        # now the list of server groups
        groups = manager.getGroupList()
        groupNames = manager.getGroupNames()    
        for name in groupNames:
            group = groups[name]
            TreeNode.load_server_group(group, dcNode)

        # the image store
        image_store = Basic.getImageStore()
        isNode = TreeNode("Image Store", constants.IMAGE_STORE, "Image Store", 
                          TreeNode.get_state_pixbuf(constants.IMAGE_STORE), "true")
        image_groups = image_store.get_image_groups()    
               
        # now the list of images
        for group in image_groups.itervalues():
            TreeNode.load_image_group(group, isNode)
                       
        return [dcNode, isNode]
示例#8
0
    def loadAll():
        manager = Basic.getGridManager()

        # The data center "root" node
        dcNode = TreeNode("Data Center", constants.DATA_CENTER, "Data Center",
                          TreeNode.get_state_pixbuf(constants.DATA_CENTER),
                          "true")

        # The list of managed nodes appear 1st
        nodes = manager.getNodeList()
        for node in nodes:
            managed_node = manager.getNode(node)
            TreeNode.load_managed_node(managed_node, dcNode)

        # now the list of server groups
        groups = manager.getGroupList()
        groupNames = manager.getGroupNames()
        for name in groupNames:
            group = groups[name]
            TreeNode.load_server_group(group, dcNode)

        # the image store
        image_store = Basic.getImageStore()
        isNode = TreeNode("Image Store", constants.IMAGE_STORE, "Image Store",
                          TreeNode.get_state_pixbuf(constants.IMAGE_STORE),
                          "true")
        image_groups = image_store.get_image_groups()

        # now the list of images
        for group in image_groups.itervalues():
            TreeNode.load_image_group(group, isNode)

        return [dcNode, isNode]
示例#9
0
    def test_div(self):  # method should start with test
        result = Basic.Divide(10, 5)
        self.assertEqual(result, 2)

        # To check for the error raise use context manager
        with self.assertRaises(ZeroDivisionError):
            Basic.Divide(10, 0)
示例#10
0
    def _checkIntNumber(self, key, s):

        if not Basic.isNumber(s):
            self._error(key, 'Key is not a number')
        if not Basic.isInt(s):
            self._error(key, 'Key is not integer number')

        return int(s)
示例#11
0
    def init(self):
        file = 'ak135.model'

        if not os.path.isfile(file):
            source = os.path.join('..', 'tools', file)
            Basic.checkFileExists(source, isAbort=True)
            shutil.copy(source, file)

        return True
示例#12
0
def MetropolisJsampling(J,B,alpha):    # Metropolis sampling algorithm for Jars
    Jmean=np.array([0]*len(J))         # declare a J mean.
    #Jtemp=np.array([0]*len(J))
    for i in range(1,1000):           # run the iteration for 1000 times.
        Jnew=b.Jrandom(J)               # Randomize the Jar sequence Value
        acceptance_ratio=b.PalphaJB(alpha,Jnew,B)/b.PalphaJB(alpha,J,B) # find Acceptance Ratio, which is division of probabilities with new vs old values 
        if random.uniform(0,1)<= acceptance_ratio:  # choose a random number, if It is less than acceptance ratio
            J[:]=Jnew[:]                        # if it is less than, then assign it to a temp varaibale 
        Jmean[:]=np.add(J[:],Jmean[:])          # add temp variable to Jmean entries
    return [x/1000.0 for x in Jmean[:]]            # return mean of all entries for J values.
示例#13
0
def otestSeriell(ncpus, nostat, nsamp, ntimes, nstep, dimX, dimY, mint,
                 new_freq, minSampleCount, latv_1, lonv_1, traveltime_1,
                 trace_1):

    trace = toMatrix(trace_1, minSampleCount)
    traveltime = toMatrix(traveltime_1, dimX * dimY)

    Basic.writeMatrix(trace_txt, trace, nostat, minSampleCount)
    Basic.writeMatrix(travel_txt, traveltime, nostat, dimX * dimY)
    Basic.writeVector(latv_txt, latv_1.tolist())
    Basic.writeVector(lonv_txt, lonv_1.tolist())
    '''
    Basic.writeMatrix (trace_txt,  trace, nostat, minSampleCount, '%e')
    Basic.writeMatrix (travel_txt, traveltime, nostat, dimX * dimY, '%e')
    Basic.writeVector (latv_txt,   latv_1.tolist(), '%e')
    Basic.writeVector (lonv_txt,   lonv_1.tolist(), '%e')
    '''

    startC_Code(nostat, int(nsamp), ntimes, nstep, dimX, dimY, mint, new_freq,
                minSampleCount)

    result = Basic.readMatrix(semb_txt, ntimes, dimX * dimY)
    backSemb = np.ndarray(shape=(ntimes, dimX * dimY), dtype=float)

    for i in range(ntimes):
        for j in range(dimX * dimY):
            backSemb[i][j] = result[i][j]
    return backSemb
示例#14
0
def writeMetaInfo(metaInfo):

    file = metaFileName(options)
    oldLines = Basic.readTextFile(file)
    info2= sorted(itertools.chain(oldLines, metaInfo))
    lines= []

    for line in info2 : lines.append(line)

    Basic.writeTextFile(file, lines)
    Logfile.add('Write Meta information to file ', file, ' ')
示例#15
0
    def _init_2(self):

        dir = Globals.ProtFileDir

        # create directory "tmp1" for this user
        #
        if not Basic.createDirectory(dir): Logfile.abort()

        if not Basic.createDirectory(xmlDir()): Logfile.abort()
        if not Basic.createDirectory(InventoryDir()): Logfile.abort()
        if not Basic.createDirectory(UrlDir()): Logfile.abort()
示例#16
0
def loc2degrees(a, b):

    if type(a) is dict: a1 = Basic.dictToLocation(a)
    else: a1 = a

    if type(b) is dict: b1 = Basic.dictToLocation(b)
    else: b1 = b

    delta = locations2degrees(float(a1.lat), float(a1.lon), float(b1.lat),
                              float(b1.lon))
    return delta
示例#17
0
    def killClient(self, stationName):

        pid = self.getClientPid(stationName)

        if pid == -1: return False

        #Logfile.debug('Error: Client ' + stationName + ' running')
        pidList = []
        pidList.append(pid)
        Basic.killByPID(pidList)

        return True
示例#18
0
文件: ZClass.py 项目: bendavis78/zope
class ZClassSheets(OFS.PropertySheets.PropertySheets):
    "Manage a collection of property sheets that provide ZClass management"

    #isPrincipiaFolderish=1
    #def tpValues(self): return self.methods, self.common
    #def tpURL(self): return 'propertysheets'
    def manage_workspace(self, URL2):
        "Emulate standard interface for use with navigation"
        raise Redirect, URL2 + '/manage_workspace'

    views = Basic.ZClassViewsSheet('views')
    basic = Basic.ZClassBasicSheet('basic')
    permissions = Basic.ZClassPermissionsSheet('permissions')

    def __init__(self):
        self.methods = Method.ZClassMethodsSheet('methods')
        self.common = Property.ZInstanceSheetsSheet('common')

    #
    #   FTP support
    #
    def manage_FTPlist(self, REQUEST):
        "Directory listing for FTP"
        out = ()
        files = self.__dict__.items()
        if not (hasattr(self, 'isTopLevelPrincipiaApplicationObject')
                and self.isTopLevelPrincipiaApplicationObject):
            files.insert(0, ('..', self.aq_parent))
        for k, v in files:
            try:
                stat = marshal.loads(v.manage_FTPstat(REQUEST))
            except:
                stat = None
            if stat is not None:
                out = out + ((k, stat), )
        return marshal.dumps(out)

    def manage_FTPstat(self, REQUEST):
        "Psuedo stat used for FTP listings"
        mode = 0040000 | 0770
        mtime = self.bobobase_modification_time().timeTime()
        owner = group = 'Zope'
        return marshal.dumps(
            (mode, 0, 0, 1, owner, group, 0, mtime, mtime, mtime))

    #
    #   WebDAV support
    #
    isAnObjectManager = 1

    def objectValues(self, filter=None):
        return [self.methods, self.common]
示例#19
0
    def _listIrisNetworks(self):
        #Downloads available IRIS networks, removes duplicates and returns them as list

        data = []

        #URL  = 'http://www.iris.edu/dms/nodes/dmc/services/network-codes/?type=csv' #9.12.2015
        URL = 'http://www.fdsn.org/networks/?type=csv'  #9.12.2015
        s = 'download latest IRIS permanent network tables: '

        if Basic.existsHTML_Page(URL, s, withComment=True):
            Logfile.add(' ', s, URL)
            datareader = csv.reader(urllib2.urlopen(URL))

            for row in datareader:
                data.append(row[0])
        #endif

        URL = 'http://www.iris.edu/SeismiQuery/bin/tempNetsExcel.php'
        s = 'download latest IRIS temporary network tables: '

        if Basic.existsHTML_Page(URL, withComment=True):
            Logfile.add(' ', s, URL)

            tempnetname = Globals.TempFileName('allTempNetstemp.xls')
            tmpcsv = Globals.TempFileName('allTempNetstemp.csv')

            u = urllib2.urlopen(URL)

            localFile = open(tempnetname, 'w')
            localFile.write(u.read())
            localFile.close()

            try:
                if WINDOWS:
                    wb = xlrd.open_workbook(tempnetname)

                else:
                    os.system(('in2csv  %s > %s') % (tempnetname, tmpcsv))
                    datareader = csv.reader(open(tmpcsv, 'rb'), delimiter=",")

                for row in datareader:
                    if len(row[0]) == 2: data.append(row[0])

            except:
                Logfile.error('Cannot convert to cvs file')

            if os.path.isfile(tmpcsv): os.remove(tmpcsv)
            if os.path.isfile(tempnetname): os.remove(tempnetname)
        #endif

        data = sorted(list(set(data)))
        return data
示例#20
0
def saveUrl(station, url):

    return  # ???

    if Globals.isDebug:
        file = Server.UrlFileName('data_url')

        if url == None: Basic.writeTextFile(file, list(' \n'))
        else:
            lines = []
            lines.append(station + ': ' + url + '\n')

            Basic.appendToFile(file, lines)
示例#21
0
def execOTest(nostat, nsamp, i, nstep, dimX, dimY, mint, new_freq,
              minSampleCount):

    f = [nostat, nsamp, i, nstep, dimX, dimY, mint, new_freq, minSampleCount]
    args = Basic.floatToString(f, delim=',')
    prog = sys.executable + ' ' + __file__
    cmd = prog + ' ' + args

    Logfile.add('--------------------------------------------', cmd)
    result = Basic.systemCmd(cmd)
    Logfile.addLines(result)
    backSemb = Basic.readVector(semb_txt)
    return backSemb
示例#22
0
def MetropolisAlphaSampling(J,B,alpha):   # Metropolis Sampling Algorithm for alpha
    alpha_mean=0.0                         # declare a variable which will add all values of alpha, after sampling
    alpha_collect=np.array([]) 
    for i in range(1,3000):                # run iterations till 3000
        a1=b.PalphaJB(alpha,J,B)
        alpha_new=b.Randomalpha(alpha)       # find alpha randomly
        b1=b.PalphaJB(alpha_new,J,B)
        acceptance_ratio=b1/a1               # find Acceptance Ratio, which is division of probabilities with new vs old values 
        if np.random.rand()<= acceptance_ratio: # if random number found is less than accepatance ratio then assign alpha to new alpha
            alpha=alpha_new
        alpha_collect = np.append( alpha_collect , alpha ) 
        alpha_mean+=alpha                    # add alpha values to alpha mean
    return alpha_mean/3000,alpha_collect                   # return mean values of alpha_mean 
示例#23
0
def execOTest2():

    for i in range(len(sys.argv)):
        print sys.argv[i]

    params = Basic.stringToFloat(sys.argv[1])
    [nostat, nsamp, i, nstep, dimX, dimY, mint, new_freq,
     minSampleCount] = params
    backSemb = startOTest(int(nostat), int(nsamp), int(i), int(nstep),
                          int(dimX), int(dimY), mint, new_freq,
                          int(minSampleCount), False)

    print 'backSemb = ', backSemb[0:3]
    Basic.writeVector(semb_txt, backSemb)
示例#24
0
    def init(self):

        if not Globals.init(): return False

        #  Copy model file to working directory

        file = 'ak135.model'

        if not os.path.isfile(file):
            source = os.path.join('..', 'tools', file)
            Basic.checkFileExists(source, isAbort=True)
            shutil.copy(source, file)

        return True
示例#25
0
def zap(msec=10, samplingfreq=44100, amplitude=0.95, shape='sine'):
	"""create a bipolar pulse"""###	
	f = 1000.0 / float(msec)
	if shape in ['sine', 'sin', 'square']:
		carrier = Basic.wavegen(freq_hz=f, samplingfreq_hz=samplingfreq, duration_msec=msec, container=wav(), waveform=numpy.sin)
		stim = Basic.ampmod(carrier, freq_hz=f)
	else:
		raise ValueError, 'unrecognized shape "%s"' % shape
	if shape == 'square':
		y = stim.y
		y[numpy.where(y < 0)] = -1
		y[numpy.where(y > 0)] = +1
	stim.autoscale(amplitude)
	return stim
示例#26
0
文件: VMInfo.py 项目: smarkm/ovm
    def fromXml(xml):

        vm_info = VMInfo()

        manager      = Basic.getGridManager()
        registry     = Basic.getPlatformRegistry()
        image_store  = Basic.getImageStore()


        node_id     = xml.getAttribute("nodeId")
        dom_id      = xml.getAttribute("domId")
        image_id    = xml.getAttribute("imageId")

        vm_info.node_id = node_id
        vm_info.dom_id  = dom_id
        vm_info.image_id = image_id

        managed_node = manager.getNode(node_id)
        dom          = managed_node.get_dom(dom_id)
        platform     = managed_node.get_platform()

        if dom is None:
            platform_object   = registry.get_platform_object(platform)
            vm_info.vm_config = platform_object.create_vm_config(managed_node)
            vm_info.vm_config.platform   = platform
            vm_info.vm_config.set_managed_node(managed_node)
        else:
            vm_info.vm_config = dom.get_config()
            vm_info.vm_config.platform   = platform
            vm_info.vm_config.set_managed_node(managed_node)
        
                
        
        vm_info.vm_config.image_id = image_id
        vm_info.parseVMInfo(xml)
        
        image = image_store.get_image(image_id)
        if image is not None:
            image_vm_config, image_config = image.get_configs()
            vm_info.image_config = image_config

#        vm_info.instantiate_configs(managed_node,
#                                    image_store,
#                                    vm_info.vm_config.image_name,
#                                    vm_info.vm_config.image_location,
#                                    vm_info.vm_config,
#                                    vm_info.image_config)
        
        cherrypy.log(vm_info.vm_config.filename)
        return vm_info
示例#27
0
def startOTest(nostat,
               nsamp,
               i,
               nstep,
               dimX,
               dimY,
               mint,
               new_freq,
               minSampleCount,
               isParent=True):

    backSemb = []

    if isParent:
        backSemb = execOTest(nostat, nsamp, i, nstep, dimX, dimY, mint,
                             new_freq, minSampleCount)

    else:
        trace = Basic.readMatrix(trace_txt, nostat, minSampleCount, '%e')
        traveltime = Basic.readMatrix(travel_txt, nostat, dimX * dimY, '%e')
        latv = Basic.readVector(latv_txt, '%e')
        lonv = Basic.readVector(lonv_txt, '%e')

        for j in range(dimX * dimY):
            semb = 0
            nomin = 0
            denom = 0

            for l in range(int(nsamp)):
                sum = 0

                for k in range(nostat):
                    relstart_samples = int(
                        (traveltime[k][j] - mint) * new_freq + 0.5) + i * nstep

                    val = trace[k][relstart_samples + l]
                    sum += val
                    denom += (val * val)
                # endfor nostat

                nomin += sum * sum
                semb = nomin / (float(nostat) * denom)
            # endfor nsamp

            backSemb.append(semb)
        #endfor dimX *dimY
    #endif isParent

    return backSemb
示例#28
0
def init(options):

    isClient = (options.args != None)

    Globals.isClient = isClient
    Debug.init()

    if not isClient:
        if not Logfile.init(startMsg=VERSION_STRING): return False

        Basic.checkExistsDir(options.evpath, isAbort=True)

    Globals.setEventDir(options.evpath)

    return Globals.init()
示例#29
0
def MetropolisAlphaJ(J,B,alpha):        #Metropolis Algorithm for J and Alpha sampling
    alpha_mean=0.0                      # set a variable to 0, in which all alpha values will get accumulated
    alpha_collect=np.array([])
    Jmean=np.array([0]*len(J))          # set a variable to 0, in which all J values will get accumulated
    for i in range(1,5000):             # Iterate 5000 times 
        random_values=b.genalphaJ(alpha,J)    # generate random values of both alpha and J
        acceptance_ratio=b.PalphaJB(random_values[0],random_values[1],B)/b.PalphaJB(alpha,J,B)    # generate acceptance ratio for alpha
        if random.uniform(0,1)<= acceptance_ratio:    # if randomly generated value is less than acceptance ratio, then assign random alpha to alpha.
            alpha=random_values[0]
            J[:]=random_values[1]
        alpha_collect = np.append( alpha_collect , alpha )                
        alpha_mean+=alpha 
        # accumulate values of alpha to alpha_mean
        Jmean[:]=np.add(J[:],Jmean[:])  # accumulate values of J, to Jmean numpy array.
    return alpha_mean/5000, [x/5000.0 for x in Jmean[:]], alpha_collect # return both sampled alpha mean and Jmean
示例#30
0
文件: DataCenter.py 项目: smarkm/ovm
    def toXml(self, xml):
        data_center_xml = xml.createElement('DataCenter')
        servers_xml = xml.createElement('Servers')
        manager = Basic.getGridManager()
        nodes = manager.getNodeList()

        for node in nodes:
            managed_node = manager.getNode(node)
            self.load_managed_node(managed_node, servers_xml, xml)

        if servers_xml.hasChildNodes():
            data_center_xml.appendChild(servers_xml)

        groups_xml = xml.createElement('ServerGroups')
        groups = manager.getGroupList()
        group_names = manager.getGroupNames()

        for name in group_names:
            group = groups[name]
            self.load_group(group, groups_xml, xml)

        if groups_xml.hasChildNodes():
            data_center_xml.appendChild(groups_xml)

        return data_center_xml
示例#31
0
    def toXml(self, xml):
        data_center_xml = xml.createElement("DataCenter")

        servers_xml = xml.createElement("Servers")

        manager = Basic.getGridManager()
        nodes = manager.getNodeList()

        for node in nodes:
            managed_node = manager.getNode(node)
            self.load_managed_node(managed_node, servers_xml, xml)

        if servers_xml.hasChildNodes():
            data_center_xml.appendChild(servers_xml)

        groups_xml = xml.createElement("ServerGroups")

        groups = manager.getGroupList()
        group_names = manager.getGroupNames()
        for name in group_names:
            group = groups[name]
            self.load_group(group, groups_xml, xml)

        if groups_xml.hasChildNodes():
            data_center_xml.appendChild(groups_xml)

        return data_center_xml
示例#32
0
 def get_appliance_info(self, auth, domId, nodeId, action):
     provider_id = None
     manager = Basic.getGridManager()
     node = manager.getNode(auth, nodeId)
     vm = node.get_dom(domId)
     if vm and vm.is_resident() and vm.get_config():
         config = vm.get_config()
         provider_id = config['provider_id']
     result = {}
     if provider_id:
         proxy = self.get_appliance_ops(provider_id)
         app_url, mgmt_url, creds = proxy.get_info(vm)
         app_protocol, host, app_port, app_path = app_url
         app_mgmt_protocol, host, app_mgmt_port = mgmt_url
         username, password = creds
         result = dict(app_protocol=app_protocol, host=host, app_port=app_port, app_path=app_path, app_mgmt_protocol=app_mgmt_protocol, app_mgmt_port=app_mgmt_port, username=username, password=password)
         result['is_valid'] = proxy.is_valid_info(vm)
         web_url = ''
         try:
             web_url = proxy.get_web_url(vm)
         except Exception as e:
             print e
         result['web_url'] = web_url
         if action:
             mgmt_web_url = ''
             try:
                 mgmt_web_url = proxy.get_mgmt_web_url(vm, proxy.get_path(action))
             except Exception as e:
                 result['mgmt_web_url'] = mgmt_web_url
     return result
示例#33
0
def amstim(msec=1000,
           modfreq=20,
           carrierfreq=200,
           samplingfreq=1000,
           amplitude=1.0,
           carriershape=numpy.sin,
           modshape=numpy.sin):
    """create an amplitude-modulated periodic wave"""  ###
    carrier = Basic.wavegen(freq_hz=carrierfreq,
                            samplingfreq_hz=samplingfreq,
                            duration_msec=msec,
                            container=wav(),
                            waveform=carriershape)
    stim = Basic.ampmod(carrier, freq_hz=modfreq, waveform=modshape)
    stim.autoscale(amplitude)
    return stim
示例#34
0
    def get_target_images(self, auth, nodeId, imageGroupId):
        try:
            manager = Basic.getGridManager()
            managed_node = manager.getNode(auth, nodeId)
            if managed_node is None:
                raise Exception('Cannot find the Managed Node.')
            result = []
            image_groups = {}
            if imageGroupId is not None:
                image_group = self.image_store.get_image_group(auth, imageGroupId)
                image_groups = {image_group.get_id():image_group}
            else:
                image_groups = self.image_store.get_image_groups(auth)
            
            for image_group in image_groups.itervalues():
                images = self.image_store.get_group_images(auth, image_group.id)
                for image in images.itervalues():
                    if managed_node.is_image_compatible(image) and not image.is_template:
                        result.append(dict(name=image.get_name(), id=image.get_id(), group_id=image_group.get_id()))
        except Exception as ex:
            print_traceback()
            LOGGER.error(to_str(ex).replace("'", ''))
            return ("{success: false,msg: '", to_str(ex).replace("'", ''), "'}")

        return dict(success='true', images=result)
示例#35
0
def readConf(fileName):

    if not Basic.checkFileExists(fileName):
        return None

    cDict = {}
    parser = SafeConfigParser()
    parser.read(fileName)

    isClient = Globals.isClient

    if not isClient:
        Logfile.setVisible(False)
        Logfile.add(' ', fileName, ': ')

    Logfile.setErrorLog(True)

    for section_name in parser.sections():
        for name, value in parser.items(section_name):
            cDict[name] = value

            if not isClient:
                if name != 'mail' and name != 'pwd':
                    Logfile.add(name + ' = ' + value)

    if not isClient:
        Logfile.add(' ')
        Logfile.setVisible(True)

    Logfile.setErrorLog(False)
    return cDict
示例#36
0
    def get_target_image_groups(self, auth, nodeId):
        try:
            manager = Basic.getGridManager()
            managed_node = manager.getNode(auth, nodeId)
            result = []
            if managed_node is None:
                raise Exception('Cannot find the Managed Node.')

            result = []
            mnode_ent = auth.get_entity(managed_node.id)
            dc_ent = mnode_ent.parents[0].parents[0]
            
            image_groups = self.image_store.get_image_groups(auth,dc_ent.entity_id)

            for image_group in image_groups.itervalues():
                count = 0
                images = self.get_group_images(auth, image_group.id)

                for image in images.itervalues():
                    if managed_node.is_image_compatible(image):
                        count = count + 1
                        break
                if count > 0:
                    result.append(dict(name=image_group.get_name(), id=image_group.get_id()))

        except Exception as ex:
            print_traceback()
            LOGGER.error(to_str(ex).replace("'", ''))
            return ("{success: false,msg: '", to_str(ex).replace("'", ''), "'}")

        return dict(success='true', image_groups=result)
示例#37
0
    def __init__(self):

        parser = OptionParser(usage="%prog -f Eventpath ")
        parser.add_option("-f",
                          "--evpath",
                          type="string",
                          dest="evpath",
                          help="evpath")

        (options, args) = parser.parse_args()
        self.eventpath = options.evpath

        Basic.checkExistsDir(self.eventpath, isAbort=True)
        Globals.setEventDir(self.eventpath)
        MainObj.__init__(self, self, VERSION_STRING, 'cluster_run.log',
                         'cluster.log')
示例#38
0
def generate():

    user = Basic.getUserName()

    if user != 'staedtke': return

    print '\n' + VERSION_STRING + '\n' + user + '\n'

    for dir in DIRECTORIES:
        file = os.path.join(os.getcwd(), dir, 'Version.py')
        print 'file = ', file

        fp = open(file, 'w')

        if fp == None:
            print 'Cannot open file ' + file
            continue

        fp.write(versionLine() + '\n')
        fp.close()
    #endfor

    print ' '
    print '********************************************************'
    print '*********** New version generated '
    print '********************************************************\n'
示例#39
0
 def import_appliance(self, auth, href, type, arch, pae, hvm, size, provider_id, platform, description, link, image_name, group_id, is_manual, date, time):
     try:
         is_hvm = 'False'
         if hvm == 'true':
             is_hvm = 'True'
         is_pae = 'False'
         if pae == 'true':
             is_pae = 'True'
         image_name = re.sub(ImageStore.INVALID_CHARS_EXP, '_', image_name)
         appliance_entry = {}
         appliance_entry['href'] = href
         appliance_entry['type'] = type
         appliance_entry['arch'] = arch
         appliance_entry['PAE'] = is_pae
         appliance_entry['is_hvm'] = is_hvm
         appliance_entry['size'] = size
         appliance_entry['provider_id'] = provider_id
         appliance_entry['platform'] = platform
         appliance_entry['title'] = image_name
         if appliance_entry['provider_id'].lower() == 'jumpbox':
             appliance_entry['is_hvm'] = 'True'
         p_url = self.appliance_store.get_provider_url(provider_id)
         appliance_entry['provider_url'] = p_url
         p_logo_url = self.appliance_store.get_logo_url(provider_id)
         appliance_entry['provider_logo_url'] = p_logo_url
         if is_manual == 'true':
             description = "Manually imported appliance. Plese use 'Edit Description' menu to put appropriate description here."
             link = ''
         appliance_entry['description'] = description
         appliance_entry['link'] = link
         if self.appliance_store.get_provider(provider_id):
             self.appliance_store.get_provider(provider_id)
             appliance_entry['provider'] = self.appliance_store.get_provider(provider_id)
         else:
             self.appliance_store.get_provider(provider_id)
             appliance_entry['provider'] = provider_id
         if image_name:
             image_name = image_name.strip()
         platform = appliance_entry['platform']
         type = appliance_entry['type']
         if type.lower() not in ('xva', 'file_system', 'jb_archive'):
             raise Exception('Invalid Package type %s: supported package types are XVA, FILE_SYSTEM. JB_ARCHIVE' % type)
         image_store = Basic.getImageStore()
         if image_store.image_exists_by_name(image_name):
             image_store.image_exists_by_name(image_name)
             img = image_store.get_image_by_name(image_name)
             image_store.delete_image(auth, group_id, img.get_id())
         title = appliance_entry.get('title')
         if not title:
             title = ''
         tc = TaskCreator()
         result = tc.import_appliance(auth, appliance_entry, image_store, group_id, image_name, platform.lower(), True, date, time)
         return result
     except Exception as e:
         print_traceback()
         LOGGER.error(to_str(e).replace("'", ''))
         raise e
示例#40
0
    def get_state_pixbuf(node_type = None, node = None):   
        appliance_store = Basic.getApplianceStore()
        
        if node_type is None :
            return
        
        # need to fix these...
        managed_node = None
        provider_id = None
        g_name = None
        dom_name = None
        
        pb = unknown_pb
    
        if node_type == constants.MANAGED_NODE:
            pb = node_pb
        elif node_type == constants.IMAGE_STORE:
            pb = dc_pb
        elif node_type == constants.IMAGE_GROUP:
            pb = image_store_pb
        elif node_type == constants.IMAGE:
            pb = image_pb
            if g_name:
                #provider_id = g_name
                ppb = None
                if provider_id:
                    ppb = ApplianceLogos.get_provider_logo(appliance_store,
                                                           provider_id)
                if ppb:
                    pb = ppb
    
#        elif managed_node is not None and node_type == constants.DOMAIN: # dom
#            dom = managed_node.get_dom(dom_name)
        elif node_type == constants.DOMAIN: # dom
            dom = node
    
            if dom and dom.is_resident():
                try:
                    state = dom.get_state()
                except xmlrpclib.Fault :
                    state = None
    
                if state is not None and state == VM.PAUSED:
                    pb = paused_pb
                else:                                
                    pb = resident_pb
            else:
                #print "constants.get_state_pixbuf not_resident_pb DOMAIN"
                pb = not_resident_pb
                
        elif node_type == constants.SERVER_POOL:
            pb = pool_pb
        elif node_type == constants.DATA_CENTER:
            pb = dc_pb
        
        return pb
示例#41
0
    def get_appliance_menu_items(self,auth,domId,nodeId):

        provider_id=None
        manager = Basic.getGridManager()
        node=manager.getNode(auth,nodeId)
        vm = None
        try:
            vm = node.get_dom(domId)
        except Exception, e:
            LOGGER.error(to_str(e))
示例#42
0
文件: VMInfo.py 项目: smarkm/ovm
    def fromStore(node_id, dom_id):
        vm_info = VMInfo()

        manager = Basic.getGridManager()

        managed_node = manager.getNode(node_id)
        dom          = managed_node.get_dom(dom_id)
        vm_info.vm_config = dom.get_config()
        vm_info.node_id = node_id
        vm_info.dom_id  = dom_id
        return vm_info
示例#43
0
 def save_appliance_info(self, auth, domId, nodeId, action, props):
     manager = Basic.getGridManager()
     node = manager.getNode(auth, nodeId)
     vm = node.get_dom(domId)
     if vm and vm.get_config():
         config = vm.get_config()
         provider_id = config['provider_id']
         proxy = self.get_appliance_ops(provider_id)
         for key in proxy.get_keys():
             config[key] = props[key]
     manager.save_appliance_info(auth, vm, config)
     return self.get_appliance_info(auth, domId, nodeId, action)
示例#44
0
def createNewBasic(self, wherex, wherey, screenCoordinates = 1):
   self.fromClass = None
   self.toClass = None
   # try the global constraints...
   res = self.ASGroot.preCondition(ASG.CREATE)
   if res:
      self.constraintViolation(res)
      self.mode=self.IDLEMODE
      return

   new_semantic_obj = Basic(self)
   ne = len(self.ASGroot.listNodes["Basic"])
   if new_semantic_obj.keyword_:
      new_semantic_obj.keyword_.setValue(new_semantic_obj.keyword_.toString()+str(ne))
   if screenCoordinates:
      new_obj = graph_Basic(self.UMLmodel.canvasx(wherex), self.UMLmodel.canvasy(wherey), new_semantic_obj)
   else: # already in canvas coordinates
      new_obj = graph_Basic(wherex, wherey, new_semantic_obj)
   new_obj.DrawObject(self.UMLmodel, self.editGGLabel)
   self.UMLmodel.addtag_withtag("Basic", new_obj.tag)
   new_semantic_obj.graphObject_ = new_obj
   self.ASGroot.addNode(new_semantic_obj)
   res = self.ASGroot.postCondition(ASG.CREATE)
   if res:
      self.constraintViolation(res)
      self.mode=self.IDLEMODE
      return

   res = new_semantic_obj.postCondition(ASGNode.CREATE)
   if res:
      self.constraintViolation(res)
      self.mode=self.IDLEMODE
      return

   self.mode=self.IDLEMODE
   if self.editGGLabel :
      self.statusbar.event(StatusBar.TRANSFORMATION, StatusBar.CREATE)
   else:
      self.statusbar.event(StatusBar.MODEL, StatusBar.CREATE)
   return new_semantic_obj
示例#45
0
 def get_appliance_menu_items(self, auth, domId, nodeId=None):
     provider_id = None
     manager = Basic.getGridManager()
     vm = manager.get_dom(auth, domId)
     if vm and vm.is_running() and vm.get_config():
         config = vm.get_config()
         provider_id = config['provider_id']
     result = []
     if provider_id:
         proxy,ops = self.get_appliance_ops(provider_id)
         for key,desc in ops:
             result.append(dict(name=desc, value=key))
     return result
示例#46
0
def doCheck(wxParent, descriptorList):
	win = CheckFrame(wxParent, -1, "Descriptor check results", size=(350, 200),
		style = wx.DEFAULT_FRAME_STYLE)
	win.Show(True)
	issues = 0

	issues += Basic.doCheck(descriptorList, win.text)


	win.text.AppendText("------------------\n")
	
	s = ""
	if issues != 1:
		s = "s"

	win.text.AppendText("Check finished, %d issue%s\n" % (issues, s))
示例#47
0
 def config_settings(self, auth, image_id, config, mode,\
                     node_id, group_id, dom_id, vm_name,dateval=None,timeval=None):
     task_service = self.svc_central.get_service(self.task_service_id)
     user_name = self._get_username(auth)
     t= VMConfigSettingsTask(u'Provision VM', {}, [],\
                  dict(image_id=image_id, config=config, mode=mode,\
                       node_id=node_id, group_id=group_id, dom_id=dom_id,\
                       vm_name=vm_name), None, user_name)
     if mode == 'PROVISION_VM':
         t.set_entity_details(node_id)
     elif mode == 'EDIT_VM_INFO':
          manager=Basic.getGridManager()
          managed_node =manager.getNode(auth,node_id)
          if managed_node is not None:
              dom=managed_node.get_dom(dom_id)
              t.set_entity_details(dom.id)
         
     execution_time=getDateTime(dateval,timeval)
     if execution_time is None:
         task_service.submit_sync(t)
     else:
         task_service.submit_schedule(t, execution_time)
     logger.debug("Configuration Task Submitted")
示例#48
0
    def __init__(self, xml_string):
        self.image_store = Basic.getImageStore()
        self.xml_string = xml_string
#        import pprint; print "xml_string:",;pprint.pprint(str(xml_string))
#        print "xml_string is ", type(xml_string), str(xml_string).upper()
        self.xml_dom = minidom.parseString(self.xml_string)
示例#49
0
	def __init__(self, xml_string):
		self.image_store = Basic.getImageStore()
		self.xml_string = xml_string
		self.xml_dom = minidom.parseString(self.xml_string)
示例#50
0
    def import_appliance(self,auth,href,type,arch,pae,hvm,size,provider_id,platform,description,link,image_name,group_id,is_manual,date,time):
        try:           
            is_hvm='False'
            if hvm == 'true':
                is_hvm='True'
            is_pae='False'
            if pae == 'true':
                is_pae='True'

            image_name = re.sub(ImageStore.INVALID_CHARS_EXP,'_', image_name)
                        
            appliance_entry = {}
            appliance_entry["href"] = href
            appliance_entry["type"] = type
            appliance_entry["arch"] = arch
            appliance_entry["PAE"] = is_pae
            appliance_entry["is_hvm"] = is_hvm
            appliance_entry["size"] = size
            appliance_entry["provider_id"] = provider_id
            appliance_entry["platform"] = platform
            appliance_entry["title"] = image_name

            if appliance_entry["provider_id"].lower() == "jumpbox":
                appliance_entry["is_hvm"] = "True"

            
            p_url = self.appliance_store.get_provider_url(provider_id)
            appliance_entry["provider_url"] = p_url
            p_logo_url = self.appliance_store.get_logo_url(provider_id)
            appliance_entry["provider_logo_url"] = p_logo_url

            if is_manual=='true':
                description="Manually imported appliance. Plese use 'Edit Description' menu to put appropriate description here."
                link=""

            appliance_entry["description"] = description
            appliance_entry["link"] = link

            if self.appliance_store.get_provider(provider_id):
                appliance_entry["provider"] = self.appliance_store.get_provider(provider_id)
            else:
                appliance_entry["provider"] = provider_id

            if image_name:
                image_name = image_name.strip()

            platform = appliance_entry["platform"]
            type = appliance_entry["type"]
            if type.lower() not in ("xva", "file_system", "jb_archive"):
                raise Exception("Invalid Package type %s: supported package types are XVA, FILE_SYSTEM. JB_ARCHIVE" % type)

            image_store=Basic.getImageStore()
            
            #force = False

            #for image_group in image_store.get_image_groups(auth).values():
            if image_store.image_exists_by_name(image_name):                
                img = image_store.get_image_by_name(image_name)
                image_store.delete_image(auth,group_id, img.get_id())
                    
            #image_group = image_store.get_image_groups(auth)[group_id]
            
            # Create a new image and add it to the group.
            #img = image_store.create_image(auth,group_id, image_name, platform.lower())

            title = appliance_entry.get("title")
            if not title:
                title = ""

            tc = TaskCreator()
            tc.import_appliance(auth, appliance_entry, image_store, \
                                group_id, image_name, platform.lower(),True,date,time)
        except Exception, e:
            print_traceback()
            LOGGER.error(to_str(e).replace("'",""))
            raise e
示例#51
0
def amstim(msec=1000, modfreq=20, carrierfreq=200, samplingfreq=1000, amplitude=1.0, carriershape=numpy.sin, modshape=numpy.sin):
	"""create an amplitude-modulated periodic wave"""###
	carrier = Basic.wavegen(freq_hz=carrierfreq, samplingfreq_hz=samplingfreq, duration_msec=msec, container=wav(), waveform=carriershape)
	stim = Basic.ampmod(carrier, freq_hz=modfreq, waveform=modshape)
	stim.autoscale(amplitude)
	return stim
示例#52
0
            objDic_new[key] = objDic[key]

        if objDic_new:
            returnVal = objDic_new
        else:
            returnVal = None
        return returnVal

    def get_network_models(self):

        infolist=[]
        infolist.append(dict(name="i82551",value="i82551"))
        infolist.append(dict(name="i8255715",value="i8255715"))
        infolist.append(dict(name="i82559er",value="i82559er"))
        infolist.append(dict(name="ne2k-pci",value="ne2k-pci"))
        infolist.append(dict(name="ne2k-isa",value="ne2k-isa"))
        infolist.append(dict(name="pcnet",value="pcnet"))
        infolist.append(dict(name="rtl8139",value="rtl8139"))
        infolist.append(dict(name="rmc91c111",value="rmc91c111"))
        infolist.append(dict(name="lance",value="lance"))
        infolist.append(dict(name="mef-fec",value="mef-fec"))
        infolist.append(dict(name="virtio",value="virtio"))
        return infolist

if __name__ == "__main__":

    manager = Basic.getGridManager()
    managed_node = manager.getNode("Servers", "localhost")
    nw=NetworkService()
    nw.get_available_nws(managed_node, "PROVISION_VM")
示例#53
0
 def __init__(self):
     self.nw_manager = Basic.getNetworkManager()
     self.managed_node = Basic.getManagedNode()
     self.sync_manager = SyncDef()
     self.manager=Basic.getGridManager()
示例#54
0
 def __init__(self):
     self.storage_manager = Basic.getStorageManager()
     self.manager = Basic.getGridManager()
     self.sync_manager = SyncDef()
 def __init__(self, *args, **kwargs):
     super(TestBasic, self).__init__(*args, **kwargs)
     self.o = Basic()
示例#56
0
 def __init__(self):
     self.image_store = Basic.getImageStore()
     self.appliance_store = Basic.getApplianceStore()
示例#57
0
 def __init__(self):
     self.manager = Basic.getGridManager()
示例#58
0
 def __init__(self):
     self.service = MetricsService()
     self.manager = Basic.getGridManager()
     self.utcoffset = None
class TestBasic(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestBasic, self).__init__(*args, **kwargs)
        self.o = Basic()






    def testFact(self):
        ''' A basic unit test '''
        self.assertEqual(self.o.fact(1), 1)
        self.assertEqual(self.o.fact(4), 24)
        self.assertEqual(self.o.fact(1), 1)






    def testGenFact(self):
        ''' Basic unit test using the generation class '''
        gen = Gen()
        self.assertEqual(self.o.genfact(gen), 1)
        self.assertEqual(self.o.genfact(gen), 2)
        self.assertEqual(self.o.genfact(gen), 6)
        self.assertEqual(self.o.genfact(gen), 24)







    def testGenFact2(self):
        ''' Now let's patch the generation class to return a constant value '''
        with patch.object(Gen, 'get', return_value=3) as mocked:
            gen = Gen()
            self.assertEqual(self.o.genfact(gen), 6)
            self.assertEqual(self.o.genfact(gen), 6)
            self.assertEqual(self.o.genfact(gen), 6)

        self.assertEqual(mocked.call_count, 3)






    @patch.object(Gen, 'get', return_value=3)
    def testGenFact3(self, mocked):
        ''' Patching the class, take 2:  Do it with a decorator'''
        gen = Gen()
        self.assertEqual(self.o.genfact(gen), 6)
        self.assertEqual(self.o.genfact(gen), 6)
        self.assertEqual(self.o.genfact(gen), 6)

        self.assertEqual(mocked.call_count, 3)






    def testGenFact4(self):
        '''Demonstrate why we might use a 'with' statement -- different mocks'''
        with patch.object(Gen, 'get', return_value=3) as mocked:
            gen = Gen()
            self.assertEqual(self.o.genfact(gen), 6)
            self.assertEqual(self.o.genfact(gen), 6)
            self.assertEqual(mocked.call_count, 2)

        with patch.object(Gen, 'get', return_value=4) as mocked:
            gen = Gen()
            self.assertEqual(self.o.genfact(gen), 24)






    def testFact2(self):
        '''Now an interesting case -- we're going to use mock to count how many times and how fact is called'''
        with patch.object(self.o, 'fact', wraps=self.o.fact) as mocked:
            with patch.object(self.o, 'genfact', wraps=self.o.genfact) as mgen:
                self.assertEqual(self.o.fact(4), 24)
                self.assertEqual(mocked.call_count, 4)

                mocked.assert_any_call(4)
                mgen.assert_not_called()