示例#1
0
def getfiles(host, filelist, destdir, hashlist=[""], prog_indicator=0, createhashfile=False):
   """ stub for the old getfiles to convert parameters to getfiles1

       XXX this will go away soon

   """
   if hashlist == [""]:
      hashlist = None

   if hashlist != None and len(hashlist) != len(filelist):
      arizonareport.send_syslog(arizonareport.ERR, "getfiles(): The number of files given doesn't match the number of hashes given.")
      return (False, downloaded_files)

   tuples = []

   for (i,file) in enumerate(filelist):
      if hashlist:
         hash = hashlist[i]
      else:
         hash = None

      dict = {"filename": file}
      if hash:
         dict['hash'] = hash

      # XXX this will be going away
      dict['hashfuncs'] = [storkpackage.get_package_metadata_hash, default_hashfunc]

      tuples.append(dict)

   return getfiles1(host, tuples, destdir, prog_indicator, createhashfile)
示例#2
0
def init_sharing_program():

   # Check that we know who we are...
   if arizonaconfig.get_option('slicename') == None:
      arizonareport.send_error(0, "--slicename must be set")
      arizonareport.send_syslog(arizonareport.ERR, "slicename hasn't been set")
      sys.exit(1)
示例#3
0
def __overwrite_file(filename, text):
   """ 
   <Purpose>
      Overwrites filename with the given text.

   <Arguments>
      filename:
              File to write to.
      text:
              Text to write.

   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      None.
   """
   try:
      out_file = open(filename, "w")
      out_file.write(text)
      out_file.close()
   except IOError:
      arizonareport.send_syslog(arizonareport.ERR, "IOError writing " + filename)
      os._exit(0)
   return
示例#4
0
def mount_dir(sourcefinal, targetfinal, flags):
    arizonareport.send_syslog(arizonareport.INFO, "Stork_proper: mount " + str(sourcefinal) + " " + str(targetfinal) + " " + str(flags))

    #uncomment this to call via os.popen instaed of importing proper directly
    #return call(["mountdir", sourcefinal, targetfinal, flags])

    # import Proper.py; if it is already imported, then this is a no-op
    try:
        import Proper
    except:
        arizonareport.send_syslog(arizonareport.ERROR, "Stork_proper: failed to import Proper.py")
        return False

    # call proper to set the file flags
    try:
        output = Proper.mount_dir(sourcefinal, targetfinal, flags)
    except:
        arizonareport.send_syslog(arizonareport.ERROR, "Stork_proper: Exception in Proper call")
        return False

    if is_proper_error(output):
        arizonareport.send_syslog(arizonareport.ERROR, "Stork_proper: Error")
        return False

    arizonareport.send_syslog(arizonareport.INFO, "Stork_proper: Success")

    return True
def __handle_retrievedstatus(data):
   """ 
   <Purpose>
      Sets whether or not all files were retrieved.

   <Arguments>
      data:
              Status: must be "true" or "false"

   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      None.
   """
   global glo_status
   __report_handler("retrievedstatus", data)
   data = data.strip().lower()
   if data == "true":
      glo_status = True
   elif data == "false":
      glo_status = False
   else:
      arizonareport.send_syslog(arizonareport.INFO, "__handle_retrievedstatus: expected `true' or `false', data:" + str(data))
      arizonareport.send_error(0, "nest transfer: received unexpected __handle_retrievedstatus response:" + str(data))
      __disconnect("arizonatransfer_nest.__handle_retrievedstatus: received unexpected __handle_retrievedstatus response:" + str(data))
示例#6
0
def set_width(width):
   """
   <Purpose>
      Set the console width for download_indicator function.
      
   <Arguments>
      width:
         maximum width of the console text on the screen
   
   <Exceptions>
      TypeError:
         If the filename passed in is not a string, TypeError is raised

   <Side Effects>
      Assign filename passed in to glo_filename.

   <Returns>
      None.
   """
   global glo_width

   # if width is not an int, then raise TypeError.
   if not isinstance(width, int): 
      arizonareport.send_syslog(arizonareport.ERR, "set_width(): 'width' is incorrect")
      raise TypeError

   glo_width = width
示例#7
0
def set_filename(filename):
   """
   <Purpose>
      Set the file name for download_indicator function.
      
   <Arguments>
      filename:
         it will be set and used for download_indicator to show the file
         name on the screen.
   
   <Exceptions>
      TypeError:
         If the filename passed in is not a string, TypeError is raised

   <Side Effects>
      Assign filename passed in to glo_filename.

   <Returns>
      None.
   """
   # if filename is not a string, then raise TypeError.
   if not isinstance(filename, str): 
      arizonareport.send_syslog(arizonareport.ERR, "set_filename(): 'filename' is incorrect")
      raise TypeError

   arizonareport.send_out_comma(0, filename + ":")
示例#8
0
def __handle_retrieveindicator(data):
   """ 
   <Purpose>
      Sets whether or not the download indicator is displayed.

   <Arguments>
      data:
              Indicator: must be an int (as a string)

   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      None.
   """
   global glo_retrieveindicator
   storklog.log_nest("stork_nest_comm", "__handle_retrieveindicator", "start", "data", data)
   __report_handler("retrieveindicator", data)
   if not __identified():
      storklog.log_nest("stork_nest_comm", "__handle_retrieveindicator", "end", "error", "")
      return
   data = data.strip()
   try:
      glo_retrieveindicator = int(data)
   except ValueError:
      arizonareport.send_syslog(arizonareport.INFO, "__handle_retrieveindicator: expected an integer value, data: `" + str(data) + "'")
      arizonareport.send_error(0, "nest: retrieveindicator expected an integer value, data: `" + str(data) + "', disconnecting")
      __disconnect("stork_nest_comm.__handle_retrieveindicator: retrieveindicator expected an integer value, data: `" + str(data) + "'")
   storklog.log_nest("stork_nest_comm", "__handle_retrieveindicator", "end", "ok", "")
示例#9
0
def __handle_end(data):
   """ 
   <Purpose>
      Responds to the \end command by terminating the connection.

   <Arguments>
      data:
              Unused.         # to log the time taken
         time_before = time.time()


   <Exceptions>
      IOError if socket communications fails.
   
   <Side Effects>
      None.

   <Returns>
      None.
   """
   storklog.log_nest("stork_nest_comm", "__handle_bindscript", "start", "data", data)
   __report_handler("end", data)
   arizonareport.send_syslog(arizonareport.INFO, "Client requested disconnect.")
   #print "[DEBUG] client requested disconnection, disconnecting"
   arizonacomm.disconnect("Client requested disconnect (sent end command)")
   storklog.log_nest("stork_nest_comm", "__handle_bindscript", "end", "ok", "")
示例#10
0
def __handle_removefile(data):
   try:
      os.remove(data)
      arizonacomm.send("identifyready", "")
   except (TypeError, IOError, OSError): #changed from catching a general exception
      arizonareport.send_syslog(arizonareport.ERR, "storkidentify.__handle_removefile(): Could not remove file: `" + str(data) + "'")
      arizonareport.send_error(2, "ERROR: Could not remove file: `" + str(data) + "'") 
      __identify_done(None)
示例#11
0
def share_file(source_serv, source_file, dest_serv, dest_file):
   """
   <Purpose>
      Share a file from a source file to dest_file on dest_serv
   
   <Arguments>
      source_serv:
         'source_serv' is a vserver service which a source file is shared from
         'source_serv' should be a string.            

      source_file:
         'source_file' is a file on vserver system to share from.
         'source_file' should be a string.

      dest_serv:
         'dest_serv' is a vserver service which a source file is shared to
         'dest_serv' should be a string.            

      dest_file:
         'dest_file' is a file on vserver system to share to.
         'dest_file' should be a string.

   <Exceptions>
      OSError:
         If linking fails, then return False.

   <Side Effects>
      None.

   <Returns>
      True if sharing succeeds, otherwise False.
   """

   
   arizonareport.send_syslog(arizonareport.ERR, "share_file(): Needs to account for source vserver correctly # JUSTIN TODO FIXME")
   return False

   # check all arguments are strings
   if not isinstance(source, str):
      arizonareport.send_syslog(arizonareport.ERR, "share_file(): source should be a string.")
      return False

   if not isinstance(dest_serv, str):
      arizonareport.send_syslog(arizonareport.ERR, "share_file(): dest_serv should be a string.")
      return False

   if not isinstance(dest_file, str):
      arizonareport.send_syslog(arizonareport.ERR, "share_file(): dest_file should be a string.")
      return False

   # this copy is based on the fact that a root directory of a dest_serv is mounted to /vservers/dest_serv
   # so we can just simply use linking.
   try:
      os.link(source, "/vservers/"+dest_serv+"/"+dest_file)
   # error occures when files don't exit or is alreay linked.
   except OSError, (errno, strerror):
      arizonareport.send_syslog(arizonareport.ERR, "share_file(): I/O error(" + str(errno) + "): " + str(strerror))	
      return False
示例#12
0
def __handle_setactive(data):
   try:
      global glo_active 
      glo_active = data
      arizonacomm.send("identifyready", "")
   except (IOError, TypeError): #changed from catching a general exception
      arizonareport.send_syslog(arizonareport.ERR, "storkidentify.__handle_setactive(): Could not set file: `" + str(data) + "' as the active file")
      arizonareport.send_error(2, "ERROR: Could not set file: `" + str(data) + "' as the active file") 
      __identify_done(None)
示例#13
0
def __handle_createdirectory(data):
   global glo_active 
   try:
      glo_active = data
      os.mkdir(data)
      arizonacomm.send("identifyready", "")
   except (TypeError, IOError, OSError):  
      arizonareport.send_syslog(arizonareport.ERR, "storkidentify.__handle_createdirectory(): Could not create directory: `" + str(data) + "'")
      arizonareport.send_error(2, "ERROR: Could not create directory: `" + str(data) + "'") 
      __identify_done(None)
示例#14
0
def __handle_readactive(data):
   try:
      f = open(glo_active, "r")
      data = f.read()
      f.close()
      arizonacomm.send("identifyready", data)
   except (IOError, TypeError): #changed from catching a general exception
      arizonareport.send_syslog(arizonareport.ERR, "storkidentify.__handle_readactive(): Could not read active file: `" + str(glo_active) + "'")
      arizonareport.send_error(2, "ERROR: Could not read active file: `" + str(glo_active) + "'") 
      __identify_done(None)
示例#15
0
def __handle_appendactive(data):
   try:
      f = open(glo_active, "a")
      f.write(data)
      f.close()
      arizonacomm.send("identifyready", "")
   except (TypeError, IOError): #changed from catching a general exception
      arizonareport.send_syslog(arizonareport.ERR, "storkidentify.__handle_appendactive(): Could not append: `" + str(data) + "' to active file: `" + str(glo_active) + "'")
      arizonareport.send_error(2, "ERROR: Could not append: `" + str(data) + "' to active file: `" + str(glo_active) + "'") 
      __identify_done(None)
示例#16
0
def __handle_createfile(data):  
   global glo_active 
   try:
      glo_active = data
      f = open(data, "w+")
      f.close()
      arizonacomm.send("identifyready", "")
   except (IOError, TypeError): #changed from catching a general exception
      arizonareport.send_syslog(arizonareport.ERR, "storkidentify.__handle_createfile(): Could not create file: `" + str(data) + "'")
      arizonareport.send_error(2, "ERROR: Could not create file: `" + str(data) + "'") 
      __identify_done(None)
示例#17
0
def __handle_retrievefile(data):
   """ 
   <Purpose>
      Adds a file to the retrieve list.

   <Arguments>
      None.

   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      None.
   """
   global glo_retrievefiles
   global glo_retrievesubdirs
   
   __report_handler("retrievefile", data)
   storklog.log_nest("stork_nest_comm", "__handle_retrievefile", "start", "data", data)
   if not __identified():
      storklog.log_nest("stork_nest_comm", "__handle_retrievefile", "end", "error", "")
      return
      
   # check filename
   # TODO need other checks?  probably a security bug here  ~ . ..  
   if data[0] == "/" or data.find("../") != -1 or data.find("~/") != -1:  
      arizonareport.send_syslog(arizonareport.INFO, "__handle_retrievefile: Illegal filename path")
      arizonareport.send_error(0, "nest: retrievefile detected an illegal filename path, disconnecting")
      __disconnect("stork_nest_comm.__handle_retrievefile: retrievefile detected an illegal filename path")
      storklog.log_nest("stork_nest_comm", "__handle_retrievefile", "end", "error", "")
      return

   if glo_retrievesubdirs == None:
      glo_retrievesubdirs = []   

   # strip subdirectories from filename
   clip = data.rfind("/")
   if clip != -1:
      # need to modify destdir to include subdirectory
      glo_retrievesubdirs.append(data[: clip + 1])
         
      # remove extra path from filename
      data = data[clip + 1:]
   else:
      glo_retrievesubdirs.append("")  
 
   if glo_retrievefiles == None:
      glo_retrievefiles = []   
      
   glo_retrievefiles.append(data)
   storklog.log_nest("stork_nest_comm", "__handle_retrievefile", "end", "ok", "")
示例#18
0
def __write_file(filename, text):
   arizonageneral.check_type_simple(filename, "filename", str, "planetlab_share.__write_file")
   arizonageneral.check_type_simple(text, "text", str, "planetlab_share.__write_file")

   try:
     thefile = open(filename, "w")
     thefile.write(str(text) + '\n')
     thefile.close()
   except IOError:
      arizonareport.send_syslog(arizonareport.ERR, "IOError writing " + filename)
   return
示例#19
0
def determine_remote_files(name, destdir, hashfuncs=[default_hashfunc], maskList=[]):
   """
   <Purpose>
      Cracks open a metafile, determines the names of the files referenced
      from that metafile, and checks to make sure they are signed
      correctly.

      An unsigned metafile is assumed to exist at destdir/METAFILE_FN

   <Arguments>
      name:
         'name' of the remote thing we're synchronizing. The only purpose
         of this parameter is as text info for the user; It's suggested to
         use the same name as the 'host' parameter that is supplied to
         sync_remote_files(), but not absoletely necessary.

      destdir:
         'destdir' is a destination directory which will be synchronized.

   <Exceptions>
      None.

   <Side Effects>
      None

   <Returns>
      A tuple: (result, file_list)

      True or False to indicate success, a list of downloaded files, and a list
      of all files on the server.
   """

   metafile_path = os.path.join(destdir, METAFILE_FN)

   fetch_list = []

   if not os.path.exists(metafile_path):
       arizonareport.send_error(arizonareport.ERR, "determine_remote_files(): file " + str(metafile_path) + " does not exist")
       arizonareport.send_syslog(arizonareport.ERR, "determine_remote_files(): file " + str(metafile_path) + " does not exist")
       return (False, fetch_list)

   mtime = os.stat(metafile_path)[ST_MTIME]
   arizonareport.send_out(1, "Using metadata " + name + ", timestamp " + time.ctime(mtime))

   # Open the file we just retrieved
   arizonareport.send_out(4, "[DEBUG] opening " + metafile_path)
   try:
      dir_file = open(metafile_path)
   # if a file cannot be opened
   except IOError, (errno, strerror):
      arizonareport.send_error(arizonareport.ERR, "determine_remote_files(): I/O error(" + str(errno) + "): " + str(strerror))
      arizonareport.send_syslog(arizonareport.ERR, "determine_remote_files(): I/O error(" + str(errno) + "): " + str(strerror))
      return (False, fetch_list)
示例#20
0
def __handle_verbosity(data):
   """ 
   <Purpose>
      Handles the \verbosity command, then sends local stdout/err messages
      to the client for remote display.  See data argument for details.

   <Arguments>
      data:
              New verbosity level (-1 to 4, inclusive).  Default verbosity
              level is -1, which is silence (no messages are sent).  
              Normal verbosity levels are 0=quiet to 3=very verbose.  
              Verbosity level 4 prints raw debug messages.

   <Exceptions>
      IOError if socket communications fails.

   <Side Effects>
      Sets arizonareport verbosity, to be used when this module prints.
      Redirects/restores stdout/err

   <Returns>
      None.
   """
   global glo_verbosity_set

   storklog.log_nest("stork_nest_comm", "__handle_verbosity", "start", "data", data)
   __report_handler("verbosity", data)
   
   # check verbosity value
   try:
      verbosity = int(data)
      if verbosity < -1 or verbosity > 4:
         raise ValueError
   except ValueError:
      arizonareport.send_syslog(arizonareport.INFO, "__handle_verbosity: bad verbosity value `" + str(data) + "', must be from -1 to 4")
      arizonareport.send_error(0, "nest: bad verbosity value `" + str(data) + "', must be from -1 to 4")
      __disconnect("stork_nest_comm.__handle_verbosity: bad verbosity value `" + str(data) + "', must be from -1 to 4")
      storklog.log_nest("stork_nest_comm", "__handle_verbosity", "end", "error", "")
      return
   
   if verbosity > 0 and not glo_verbosity_set and not arizonaconfig.get_option("localoutput"):
      # turn on output redirection
      arizonareport.redirect_stdout(arizonacomm_out())       
      arizonareport.redirect_stderr(arizonacomm_err()) 
      glo_verbosity_set = True
   """elif verbosity < 0 and glo_verbosity_set:
      # turn off output redirection      
      arizonareport.restore_stdout()       
      arizonareport.restore_stderr() """      

   arizonareport.set_verbosity(verbosity)
   storklog.log_nest("stork_nest_comm", "__handle_verbosity", "end", "ok", "")
示例#21
0
def identifyready(junk_data):
   """ TODO comments """
   global glo_identified
   global glo_state
   global glo_randdir
   
   storklog.log_nest("planetlab_share", "identifyready", "start", "", "")

   if glo_state == 0:
      arizonacomm.send("createfile", glo_randdir + "/.exportdir")
      glo_state = 1      
   elif glo_state == 1:
      arizonacomm.send("appendactive", arizonaconfig.get_option("slicename") + "\n")
      glo_state = 2
   elif glo_state == 2:  
      # Try to mount their directory onto ours.  If the /tmp/.../identify 
      # directory disappears, then they are identified, otherwise not.
      __share_directory(glo_client, glo_randdir, arizonaconfig.get_option("slicename"), glo_randdir, "")
      glo_identified = not os.path.exists(glo_randdir + "/identify")
      # clean up... 
      unshare_directory(arizonaconfig.get_option("slicename"), glo_randdir)
      # BUG TODO FIXME NEEDS WORK 
      # There is a bug that gets triggered here...   Sometimes the above unmount
      # call fails silently (acts like success) and then these fail.   I will wrap
      # in try: except OSError: until I figure out
      # NOTE: I copied these comments from the previous authenticate code.. 
      #       It is possible that the bug has been fixed due to the refactoring.
      try:
         os.rmdir(glo_randdir + "/identify")
         os.rmdir(glo_randdir)
      except OSError:
         arizonareport.send_syslog(arizonareport.INFO, "Triggered known BUG in identifyready()\n")
         arizonareport.send_syslog(arizonareport.INFO, "BUG trying to rmdir(" + glo_randdir + "/identify)\n")
         arizonareport.send_syslog(arizonareport.INFO, "BUG trying to rmdir(" + glo_randdir + ")\n")
         arizonareport.send_syslog(arizonareport.INFO, "BUG Exception: " + str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1]) + " " + str(sys.exc_info()[2]))
         arizonareport.send_syslog(arizonareport.INFO, "End BUG ")
      arizonacomm.send("removefile", glo_randdir + "/.exportdir")
      glo_state = 3
   elif glo_state == 3:      
      arizonacomm.send("removedirectory", glo_randdir)
      glo_randdir = None
      glo_state = 4
   elif glo_state == 4:  
      glo_state = None
      if glo_identified:
         arizonacomm.send("identified", arizonaconfig.get_option("slicename"))
         storklog.log_nest("planetlab_share", "identifyready", "identified", "yes", "")
      else:
         arizonacomm.send("identifyfailed", "")
         storklog.log_nest("planetlab_share", "identifyready", "identified", "no", "")
   storklog.log_nest("planetlab_share", "identifyready", "end", "ok", "")
示例#22
0
def __verify_shared(slice):

   # It's us!
   if not slice or slice == arizonaconfig.get_option('slicename'):
      return True

   # Is there already a dir for this client
   if not os.path.exists(__path(slice,"/")):
      arizonareport.send_syslog(arizonareport.ERR, slice + " hasn't been shared")
      return False
      
   # We init to test (because the dir may exist but it can't be bound).   
   # If it isn't bound but could be then we'll bind here (not necessarily good)
   return init_client(slice)
          
      
def __verify_connection(host):
   """
   <Purpose>
      This verifies a connection, testing a host and target directory.

   <Arguments>
      host:
         'host' holds two things, a server name and target directory.
         For example, if you want to retrieve files from '/tmp/' directory
         in 'quadrus.cs.arizona.edu' server, the 'host' will be
         'quadrus.cs.arizona.edu/tmp'.
            
   <Exceptions>
      urllib2.URLError:
         If host name is incorrect or host is dead, then return False

      urllib2.HTTPError:
         If given target directory is incorrect, then return False

   <Side Effects>
      None.

   <Returns>
      True or False (see above)
   """
   
   # split host into server name and directory
   host.replace("http://","")
   host.replace("ftp://","")
   index = host.find('/')
   # set hostname to hold only a server name
   if index != -1:
      hostname = host[:index]
   else :
      hostname = host   

   # checking only host
   #the port number is for the odd bittorrent imports which interfere with
   # the regular usage of urllib2.urlopen
   checkurl = __build_url("http://"+hostname+"80", "")

   # urllib2 is used since urllib doestn't offer a nice way to check the connection is valid
   try :
      urllib2.urlopen(checkurl)
   # incorrect host name or host is dead
   except urllib2.URLError, (msg):      
示例#24
0
def unlink_file(target_slice, target_file):

   # Make sure the slice has bound
   if not __verify_shared(target_slice):
      return False

   targetfinal = __path(target_slice, target_file)

   arizonareport.send_syslog(arizonareport.INFO, 'Unlink a file "' + targetfinal + '"')

   # TODO FIXME Below we should catch FNF, is dir, etc. errors
   try:
      os.unlink(targetfinal)
   except OSError, (errno, strerror):
      arizonareport.send_syslog(arizonareport.ERR, "OS error(%s): %s" % (errno, strerror))
      return False
示例#25
0
def share_directory(source_slice, source_dir, target_slice, target_dir, flags):
   """
   <Purpose>
      Share a directory between two slices. It uses Proper.py in planetlab
      servers.   It assumes that source_slice and target_slice have both bound.
      If this is not the case, use __share_directory instead.

   <Arguments>
      source_slice: 
         A slice name that you want to share a directory to.

      source_dir: 
         Directory that you want to share.
       
      target_slice:
         A slice name that you want to share a directory to.

      target_dir: 
         Directory to which you want to share source_dir.
         
      flags:
         If it is not empty string, then share a directory with protection.
         
   <Exceptions>
      OSError:
         If it fails to create directories.

   <Side Effects>
      None.
      
   <Returns>
      True if it succeeds to share, otherwise return False.
   """
   
   # Make sure the slices have bound
   if not __verify_shared(source_slice):
      return False
   if not __verify_shared(target_slice):
      return False

   # Create the source dir if missing
   if not os.path.exists(__path(source_slice, "/" + source_dir)):
      try:		
         os.makedirs(__path(source_slice, "/" + source_dir))
      except OSError, (errno, strerror):
         arizonareport.send_syslog(arizonareport.ERR, "OS error(%s): %s" % (errno, strerror))	
         return False
示例#26
0
def link_file(source_slice, source_file, target_slice, target_file, verify_same):

   if not __verify_shared(source_slice):
      return False
   if not __verify_shared(target_slice):
      return False

   # Find out where things should be placed
   sourcefinal = __path(source_slice,source_file)
   targetfinal = __path(target_slice,target_file)
   
   # TODO FIXME  create destdir if it doesn't exist???

   arizonareport.send_syslog(arizonareport.INFO, 'Link a file "' + sourcefinal + '" to "' + targetfinal + '"') 
  
   try: 
      storklog.log_nest("planetlab_share", "link_file", "file-hash-size", "", sourcefinal + " " + str(os.path.getsize(sourcefinal)))
   except:
      pass

   # Is the source valid?
   if not arizonageneral.valid_fn(__path(source_slice,source_file)):
      arizonareport.send_syslog(arizonareport.ERR, "In planetlab_share.link_file, '"+sourcefinal+"' is invalid")
      return False

   if verify_same:
      # verify_same is used by stork_prepare to only link files that are
      # identical. A different file is not an error so do not return False. We
      # want to return True so that arizona_share continues to link the other
      # files in the package. 
      
      # can't be the same if the target doesn't exist
      if not os.path.exists(targetfinal):
         return True

      if not filecmp.cmp(sourcefinal, targetfinal):
         return True

   # If it exists, remove and relink because os.link fails if the target exists...
   if os.path.exists(targetfinal):
      if os.path.isfile(targetfinal):
         os.unlink(targetfinal)
      else:
         arizonareport.send_syslog(arizonareport.ERR, "In planetlab_share.link_file, '"+targetfinal+"' exists and is not a file")
         return False
   
   # Check for the dir and create if missing
   if not os.path.exists(os.path.dirname(targetfinal)):
      os.makedirs(os.path.dirname(targetfinal))

   try:
      os.link(sourcefinal, targetfinal)
   except OSError, (errno, strerror):
      arizonareport.send_syslog(arizonareport.ERR, \
          "planetlab_share.link_file('" + sourcefinal + "','" + \
          targetfinal + "') OS error(%s): %s" % (errno, strerror))
      return False
示例#27
0
def __verify_connection(host):
   """
   <Purpose>
      This verifies a connection, testing a host, username, password, port

   <Arguments>
      host:
         'host' holds two things, a server name and target directory.
         For example, if you want to retrieve files from '/tmp/' directory
         in 'quadrus.cs.arizona.edu' server, the 'host' will be
         'quadrus.cs.arizona.edu/tmp'.
            
   <Exceptions>
      URLError:
         If host name is incorrect or host is dead, then return False

      IOError:
         If given username, password, port, or target directory is 
         incorrect, then return False

   <Side Effects>
      None.

   <Returns>
      True or False (see above)
   """
   
   
   # split host into server name and directory
   index = host.find('/')
   # set hostname to hold only a server name
   if index != -1:
      hostname = host[:index]
   else :
      hostname = host   

   # checking only host
   checkurl = __build_url(hostname, "")

   # urllib2 is used since urllib doestn't offer a nice way to check the connection is valid
   try :
      urllib2.urlopen(checkurl)
   # incorrect host name or host is dead
   except urllib2.URLError, (msg):      
      arizonareport.send_syslog(arizonareport.ERR, '__verify_connection(): "' + hostname + '" '+ str(msg).split("'")[1])
      return False
def __verify_connection(host):
   """
   <Purpose>
      This verifies a connection, testing a host and target directory.

   <Arguments>
      host:
         'host' holds two things, a server name and target directory.
         For example, if you want to retrieve files from '/tmp/' directory
         in 'quadrus.cs.arizona.edu' server, the 'host' will be
         'quadrus.cs.arizona.edu/tmp'.
            
   <Exceptions>
      None.
      
   <Side Effects>
      None.

   <Returns>
      True or False (see above)
   """
   
   # split host into server name and directory
   #this could potentially be bad:(eg: http://quadrus.cs.arizona.edu/PlanetLab/...
   # would return http:
   #index = host.find('/')
   thost=host.replace("http://","")
   thost=thost.replace("ftp://","")
   index=thost.find("/")
   # set hostname to hold only a server name
   if index != -1:
      hostname = thost[:index]
   else :
      hostname = host   

   # checking only host
   checkurl = __build_url(hostname, "")

   # urllib2 is used since urllib doestn't offer a nice way to check the connection is valid
   try :
      urllib2.urlopen(checkurl)
   # incorrect host name or host is dead
   except urllib2.URLError, (msg):      
      arizonareport.send_syslog(arizonareport.ERR, '__verify_connection(): "' + hostname + '" '+ str(msg).split("'")[1])
      return False
示例#29
0
def __report_handler(name, data):
   """ 
   <Purpose>
      Syslogs the connection, handler name, and data.

   <Arguments>
      None.

   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      None.
   """
   arizonareport.send_syslog(arizonareport.INFO, "[" + glo_connection + "] Handling " + name + ", data: `" + data + "'")
示例#30
0
def __report_handler(name, data):
   """ 
   <Purpose>
      Syslogs the connection, handler name, and data.

   <Arguments>
      None.

   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      None.
   """
   arizonareport.send_syslog(arizonareport.INFO, "[" + arizonaconfig.get_option("transhost") + ":" + str(arizonaconfig.get_option("transport")) + "] Handling " + name + ", data: `" + data + "'")