Exemplo n.º 1
0
def log_transfer(function, pid, timestamp, timestampend):
   """
   <Purpose>
      Log the status of a transfer function. this should
      happen on entry or exit of a function.

   <Arguments>
      function:
          the transfer stub ei: coblitz, http, etc
      pid:
          the pid that this stub is running in
      timestamp:
          a timestamp when this function started transf
      timestampend:
          when this function finished transfering
   """
   # see if we should log this
   enable = arizonaconfig.get_option("enablelogging")
   logdir = arizonaconfig.get_option("logdir")
   if not enable:
      return

   logfile= logdir + "/" + get_transfer_log_filename()

   # prepare the string
   writeout = function + " " + timestamp + " " + timestampend + " " + pid + "\n"

   # try to append to the file
   try:
      tempfile = open(logfile, "a")
      tempfile.write(writeout)
      tempfile.close()
   except:
      pass
Exemplo n.º 2
0
def init():
   global glo_aws_conn
   global glo_aws_generator
   global glo_aws_bucket
   global glo_initialized

   if glo_initialized:
       return True

   awskey = arizonaconfig.get_option("awskey")
   awssecretkey = arizonaconfig.get_option("awssecretkey")
   bucket = arizonaconfig.get_option("awsbucket")

   if (not awskey) or (not awssecretkey):
      raise TypeError, "Please configure your awskey and awssecretkey"

   glo_aws_conn = S3.AWSAuthConnection(awskey, awssecretkey)
   glo_aws_generator = S3.QueryStringAuthGenerator(awskey, awssecretkey)

   if bucket[0] == '*':
      # if the user puts a '*' as the first character, then lets assume he
      # wants to specify an absolete bucket name, and not prepend the
      # awskey
      glo_aws_bucket = bucket[1:]
   else:
      glo_aws_bucket = awskey.lower() + bucket

   # create the bucket in case it does not exist
   glo_aws_conn.create_bucket(glo_aws_bucket)

   glo_initialized = True
Exemplo n.º 3
0
def init_transfer_program():
   """
   <Purpose>
      Initializes nest transfer by identifying ourselves for the nest.

   <Arguments>
      None.

   <Exceptions>
      TypeError:
         If the types of given arguments are incorrect, then TypeError 
         will be raised.

   <Side Effects>
      Sets glo_nestname

   <Returns>
      None.
   """
   global glo_nestname
   
   try:
      arizonacomm.connect(arizonaconfig.get_option("transhost"), 
                          arizonaconfig.get_option("transport"))
   except IOError: 
      arizonareport.send_error(0, "nest transfer: Could not connect to nest")
      
   glo_nestname = storkidentify.identify()
   
   # if not identified, report an error
   if glo_nestname == None:
      arizonareport.send_error(0, "nest transfer: Could not retrieve nest name (identification failed)")

   storkidentify.verify_exportdir(glo_nestname)
Exemplo n.º 4
0
def main():
   # use error reporting tool
   storkerror.init_error_reporting("stork_nest_comm.py")

   # process command line and initialize variables
   args = arizonaconfig.init_options('stork_nest_comm.py', configfile_optvar='configfile', version=stork_nest_version.VERREL)

   arizonareport.set_output_function(output_func_pid)

   # there should not be any leftover options
   if args:
      arizonareport.send_error(0, "Arguments not understood: " + str(args))
      sys.exit(1)

   arizona_share.init()

   # run as a daemon
   if arizonaconfig.get_option("daemon"):
      arizonageneral.make_daemon("stork_nest_comm.py")

   # display ready message
   if not arizonaconfig.get_option("daemon"):
      print "Ready for connections..." 
      
   # infinite loop (daemon must keep running)
   #while True:
      # Handle incoming connections
      #try:
   arizonacomm.listen("localhost", arizonaconfig.get_option("listenport"), handle_connection) 
Exemplo n.º 5
0
def translate_path(path):
    # get the hostname
    if arizonaconfig.get_option("hostname") != "":
         hostname = arizonaconfig.get_option("hostname")
    else:
         hostname = socket.gethostname()

    repbase  = arizonaconfig.get_option("repbase")

    # make a translated dest dir
    # ei: take the full path sourcepath
    # and swap out all the '/' for '_'
    # and add hostname in front of it

    urlprefix = arizonaconfig.get_option("urlprefix")
    if urlprefix:
        # make sure it has a leading slash but no trailing slash
        urlprefix = "/" + urlprefix.strip("/")
        urlprefix = urlprefix.replace("/","_")
    else:
        # set it to the empty string instead of None
        urlprefix = ""

    translate = hostname + urlprefix + os.path.abspath(path).replace(repbase,"").replace("/","_")

    return translate
Exemplo n.º 6
0
def config_prefix():
   """

   XXX: This function is deprecated and will be going away soon

   <Purpose>
      This returns the prefix for the configuration files that we want to use.
      This function automatically opens the publickeyfile and embeds that 
      string within the username.

   <Arguments>
      None (all command line arguments)

   <Exceptions>
      TypeError may be returned if the user hasn't specified a username and
      a valid publickeyfile

   <Side Effects>
      Nothing external.   If the publickeyfile is specified as a command line
      arguments it is only parsed the first time this function is called.   
      Every additional time the previous result is returned regardless of 
      changes to this file.

   <Returns>
      A string which contains the prefix for other functions that need signed
      configuration files.   Simply append "."+extension and away you go.
   """
   global initialized
   global full_username

   # Only do this the first time
   if not initialized:

      # if they forgot to set the username or the publickeyfile
      if not arizonaconfig.get_option("username"):
         # Oops, error and remind them...
         arizonareport.send_error(0, "Must specify the '--username' option")
         sys.exit(1)

      if not arizonaconfig.get_option("publickeyfile"):
         # Oops, error and remind them...
         arizonareport.send_error(0, "Must specify the '--publickeyfile' option")
         sys.exit(1)

      # Open the publickeyfile
      (success, publickey_sl) = arizonacrypt.publickey_fn_to_sl(arizonaconfig.get_option("publickeyfile"))

      if not success:
         # Oops, error and tell them
         arizonareport.send_error(0, "Invalid or missing publickeyfile in config_prefix: '" + arizonaconfig.get_option("publickeyfile") + "'")
         sys.exit(1)

      # now set the full username to be username.publickeystring
      full_username = arizonaconfig.get_option("username") + "." + arizonacrypt.publickey_sl_to_fnstring(publickey_sl)

      # Don't go through this mess again...
      initialized = True

   # Return the full username
   return full_username
Exemplo n.º 7
0
def commit():
   permUsageFileName = arizonaconfig.get_option("permUsageFileName")
   tempUsageFileName = arizonaconfig.get_option("tempUsageFileName")
   if os.path.exists(permUsageFileName):
      os.remove(permUsageFileName)
   if os.path.exists(tempUsageFileName):
      os.rename(tempUsageFileName, permUsageFileName)
Exemplo n.º 8
0
def update_gui(put_files_here):
   command1 = arizonaconfig.get_option("curlpath")+" -L -o "+os.path.join(put_files_here,"storkslicemanager.py")+" "+storksite+"gui/storkslicemanager.py"
   command2 = arizonaconfig.get_option("curlpath")+" -L -o "+os.path.join(put_files_here,"storkcurlfuncs.py")+" "+storksite+"gui/storkcurlfuncs.py"


   (sin, sout, serr) = os.popen3( command1 )
   (sin, sout, serr) = os.popen3( command2 )
   #SHUTDOWN THE GUI
   # TODO: open it back up for the user again
   sys.exit(0)
Exemplo n.º 9
0
def init():
   """
   <Purpose>
      Initialize and update repository package list(s).
   """
   global glo_initialized
   global glo_repo_sections

   glo_repo_sections = arizonaconfig.get_option("repositories")
   if not glo_repo_sections:
      # compatibility mode -- None causes arizonaconfig.get_option_section
      #   to default to the same behaviour as arizonaconfig.get_option
      glo_repo_sections = [None]

   # check repinfo
   for repo_section in glo_repo_sections:
      if arizonaconfig.get_option_section("repinfo", repo_section) == None:
         if repo_section:
             arizonareport.send_error(0, "repository " + repo_section + ":")
         arizonareport.send_error(0, "Repository package information locations must be" + \
                                     " specified either on the command line" + \
                                     " or in the configuration file.  See the" + \
                                     " `--repositorypackageinfo' option.")
         sys.exit(1)

      if not arizonaconfig.get_option_section("updatedb", repo_section):
         arizonareport.send_out(1, "Skipping update of package information...")
         update_ok = False
      else:
         arizonareport.send_out(1, "Updating package information...")
         update_ok = True

      # check to see if the user tried to override the localinfo variable for
      # a specific repository. If so, then complain because this is not yet
      # implemented
      # TODO: finish this (see __find_package_fnlist_on_one_criteria)
      if arizonaconfig.get_option_section("localinfo", repo_section) != arizonaconfig.get_option("localinfo"):
         arizonareport.send_error(0, "cannot use localinfo variable inside repository section")
         sys.exit(1)

      download_repositories(repo_section,
                            arizonaconfig.get_option_section("repinfo", repo_section),
                            arizonaconfig.get_option_section("localinfo", repo_section),
                            update_ok)

   # build the list of packageinfo directories
   build_localpdir()

   # uncomment to dump info about repositories to stdout
   # dump_repositories()

   glo_initialized = True
Exemplo n.º 10
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", "")
Exemplo n.º 11
0
def __handle_bindscript(data):
   """ 
   <Purpose>
      Responds to the \bindscript command by copying files to the 
      client slice

   <Arguments>
      data:
              Client slice name.

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

   <Returns>
      None.
   """
   storklog.log_nest("stork_nest_comm", "__handle_bindscript", "start", "data", data)
   __report_handler("bindscript", data)

   # get client name
   client = data.strip().split()[1].strip()[1:]

   # log the request
   arizonareport.send_syslog(arizonareport.INFO, "client: `" + client + "'")

   # check for bad client name
   if client == '.' or client == '..' or client.find('/') != -1:
      arizonacomm.send("", "stork nest: error")
      arizonareport.send_syslog(arizonareport.ERR, "__handle_bindscript: bad client name `" + client + "'")
      
      __disconnect("stork_nest_comm.__handle_bindscript: bad client name `" + client + "'")
      storklog.log_nest("stork_nest_comm", "__handle_bindscript", "end", "error", "")
      return

   arizonacomm.sendraw("HTTP/1.1 202 OK\r\nContent-Length: " + str(len(client) + 3) + "\r\nConnection: Keep-Alive\r\nContent-Type: text/plain\r\n\r\n" + str(client) + "\r\n\n")

   arizona_share.init_client(client)

   # Now copy files, etc. for setup
   files = glob.glob(arizonaconfig.get_option("bindfiles") + "/*")
   for filename in files:
      name = os.path.split(filename)[1]
      arizona_share.copy_file(arizonaconfig.get_option("slicename"), filename, client, "/tmp/stork/" + name)

   # Tell the client to proceed...
   arizona_share.copy_file(arizonaconfig.get_option("slicename"), "/dev/null", client, "/tmp/stork/stork_says_go")
   arizonareport.send_syslog(arizonareport.INFO, "Done...")
   storklog.log_nest("stork_nest_comm", "__handle_bindscript", "end", "ok", "")
Exemplo n.º 12
0
def __handle_prepared(junk_data):
   """
   <Purpose>
      Called when the nest has finished copying files.

   <Arguments>
      data:
              Unused.

   <Exceptions>
      IOError if there was problem ending the current session.

   <Side Effects>
      Sets glo_prepared to True.

   <Returns>
      None.
   """
   global glo_prepared
   arizonacomm.end_session()
   glo_prepared = True

   if arizonaconfig.get_option("simulate_nest_fail"):
       arizonareport.send_out(0, "simulating nest failure")
       glo_prepared = False
Exemplo n.º 13
0
   def test_divide_string_into_taglist(self):

      # Empty string becomes list containing empty string
      self.assertEqual(arizonatemplate.divide_string_into_taglist(''),[''])
 
      # typical example
      ti = arizonaconfig.get_option('tagindicator')
      mylist = arizonatemplate.divide_string_into_taglist('abc'+ti+'def'+ti+'ghi')
      self.assertEqual(mylist[0],'abc')
      self.assertEqual(mylist[1].tagname,arizonatemplate.Tag('def').tagname)
      self.assertEqual(mylist[2],'ghi')
      
      try:
        # change the tag indicator
        arizonaconfig.set_option('tagindicator', 'A')
        mylist = arizonatemplate.divide_string_into_taglist('123A456A789')

        self.assertEqual(mylist[0],'123')
        self.assertEqual(mylist[1].tagname,arizonatemplate.Tag('456').tagname)
        self.assertEqual(mylist[2],'789')
      finally:
        # restore the indicator
        arizonaconfig.set_option('tagindicator', ti)

      # mismatched tag
      self.assertException(ValueError, arizonatemplate.divide_string_into_taglist,'start'+ti+'end')
Exemplo n.º 14
0
def identify(data):
   """ TODO comments """
   global glo_identified
   global glo_state
   global glo_randdir
   global glo_client
   
   storklog.log_nest("planetlab_share", "identify", "start", "data", data)

   # if the client is already identified, we're done
   if glo_identified:
      arizonacomm.send("identified", arizonaconfig.get_option("slicename"))
      storklog.log_nest("planetlab_share", "identify", "end", "yes", "")
      return
   
   # clean up after any previous attempts
   glo_identified = False
   if glo_randdir != None:
      try:
         os.rmdir(glo_randdir)
      except:
         pass    

   # create test directories and start the identification process rolling
   glo_client = data
   glo_randdir = "/tmp/" + str(securerandom.SecureRandom().random())
   os.mkdir(glo_randdir)
   os.mkdir(glo_randdir + "/identify")
   glo_state = 0
   arizonacomm.send("createdirectory", glo_randdir)
   storklog.log_nest("planetlab_share", "identify", "end", "ok", "")
Exemplo n.º 15
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)
Exemplo n.º 16
0
def verify():
   result = True

   permUsageFileName = arizonaconfig.get_option("permUsageFileName")

   # open and read the file
   file = open(permUsageFileName, "r")
   lines = file.readlines()

   # there could be duplicate lines because multiple copies of stork may have
   # been invoked from one run of pacman
   lines = uniq(lines)

   for line in lines:
       splitline = line.split(" ")
       (filename, last_hash) = (splitline[0], splitline[1])

       # get the hash of the file
       if os.path.exists(filename):
          hash = arizonacrypt.get_fn_hash(filename)
       else:
          hash = "doesnotexist"

       if (hash != last_hash):
          arizonareport.send_out("hash mismatch file " + filename + " last=" + last_hash + " cur =" + hash)
          result = False

   return result
Exemplo n.º 17
0
def set_poisoned(key=None, string=None, file=None):
   """
   <Purpose>
      Sets a key as poisoned
   <Arguments>
      one of the following should be specified:
         key - publickey object (see arizonacrypt.publickey)
         string - publickey string
         file = file containing public key
   <Side Effects>
      Create files in poison subdirectory
   """

   if not key:
      if string:
         key = arizonacrypt.PublicKey(string = string)
      elif file:
         key = arizonacrypt.PublicKey(file = file)

   assert(key)

   hash = key.hash;
   dir = arizonaconfig.get_option("poisondir")
   fn = os.path.join(dir, hash)

   arizonageneral.makedirs_existok(dir)

   file = open(fn, "w")
   file.write(key.string)
   file.close()
Exemplo n.º 18
0
def is_poisoned(key=None, string=None, file=None):
   """
   <Purpose>
      Checks to see if a key is poisoned
   <Arguments>
      one of the following should be specified:
         key - publickey object (see arizonacrypt.publickey)
         string - publickey string
         file = file containing public key
   """

   if not key:
      if string:
         key = arizonacrypt.PublicKey(string = string)
      elif file:
         key = arizonacrypt.PublicKey(file = file)

   assert(key)

   hash = key.hash;
   dir = arizonaconfig.get_option("poisondir")
   fn = os.path.join(dir, hash)

   if os.path.exists(fn):
      return True
   else:
      return False
Exemplo n.º 19
0
def remove_poisoned(key=None, string=None, file=None):
   """
   <Purpose>
      Removes a poisoned key
   <Arguments>
      one of the following should be specified:
         key - publickey object (see arizonacrypt.publickey)
         string - publickey string
         file = file containing public key
   <Side Effects>
      Removes files in poison subdirectory
   """

   if not key:
      if string:
         key = arizonacrypt.PublicKey(string = string)
      elif file:
         key = arizonacrypt.PublicKey(file = file)

   assert(key)

   hash = key.hash;
   dir = arizonaconfig.get_option("poisondir")
   fn = os.path.join(dir, hash)

   try:
      os.remove(fn)
   except OSError:
      pass
Exemplo n.º 20
0
   def include_tpfile(self, username, publickey):
      """
      <Purpose>
         TODO fix comment
      """

      publickey_string = publickey.string
      publickey_string_old = arizonacrypt.publickey_sl_to_fnstring_compat(publickey.sl)
      publickey_hash = publickey.hash
      longname = username + "." + publickey_string

      # If we're missing this user's trusted packages file parse it
      if not self.tp_dict.has_key(longname):
         new_parents = self.parent_list[:]
         new_parents.append(self.user)

         # Get the name of the new file
         possible_tpfilenames = []
         possible_tpfilenames.append(username + "." + publickey_hash + FILE_EXTENSION)
         possible_tpfilenames.append(username + "." + publickey_string_old + FILE_EXTENSION)

         # SMB: choose between long and short key versions based on date
         (tpfilename, tp_repo) = storkpackagelist.find_file_list("tpfiles", possible_tpfilenames, None, publickey_string)

         if not tpfilename:
            raise TPFileError, "missing"

         # Parse the new file
         self.tp_dict.update(
             TrustedPackagesFileParse(arizonaconfig.get_option("tpdtd"),
             tpfilename,
             tp_repo,
             publickey_string,
             longname,
             new_parents))
Exemplo n.º 21
0
   def test_find_package_name(self):

      self.reset_options()

      # set the options needed by storkpackagelist.init()
      arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
      arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
      storkpackagelist.init()
      self.assertEquals( "/usr/local/stork/var/packageinfo", arizonaconfig.get_option("localinfo") )
      # init() should have set the localpdir variable

      # Should return None if nothing is found
      self.assertEquals(None, storkpackagelist.find_package_name('stork'))
      self.assertEquals(None, storkpackagelist.find_package_name(''))
      self.assertEquals(None, storkpackagelist.find_package_name(' '))
      self.assertEquals(None, storkpackagelist.find_package_name('-'))
      self.assertEquals(None, storkpackagelist.find_package_name('.'))
      self.assertEquals(None, storkpackagelist.find_package_name('23'))
      


      # Pass it a valid, existent, filename
      # Since grep is called with the instruction:
      #      out, err, status = arizonageneral.popen5("grep -rl ^" + field + ":" + search + " " + os.path.join(arizonaconfig.get_option("localinfo"), package_dir))                               
      # set the variables to the variable "localinfo" and "localpdir" to point to the directory where the packages are:
      # TODO arizonaconfig.set_option( "pdir", ["stork"] )
      # TODO arizonaconfig.set_option( "localinfo", "/usr/local/stork/" )      
      self.assertEquals(None, storkpackagelist.find_package_name("storkd-0.1.0-1.src.rpm") )
Exemplo n.º 22
0
def upload_file(username, password, file, type, slice=None):
   arizonareport.send_out(3, "upload_file initiated for file: "+file)

   ok_types = ["package","tp","pacman","pk","conf"]
   if type not in ok_types:
      arizonareport.send_out(2, type+" not in "+str(ok_types)+" , skipping upload")
      return None

   if not login(username,password):
      arizonareport.send_error(2, "ERROR: Not logged in and unable to login. Aborting file upload.")
      return None

   if not os.path.isfile(file):
      arizonareport.send_out(2, file," is not a file, skipping upload.")
      return None

   command = arizonaconfig.get_option("curlpath")+" -L -k -b GetCookie %SLICE% -F \"type=%TYPE%\" -F \"numfiles=1\" -F \"uploadbutton=Upload File\" -F \"file_0=@%FILE%\" "+repository+":8081/stork/upload_handler.php"
   command = command.replace("%FILE%", file).replace("%TYPE%", type)

   if type in ["pk", "conf"]  and slice!=None:
      command = command.replace("%SLICE%", "-F \"slice="+slice+"\"")
   else:
      command = command.replace("%SLICE%", "")
   

   #DEBUG -remove when we go live
   #command  = command.replace("https://stork-repository.cs.arizona.edu", "http://jplichta.ipupdater.com:8080")

   arizonareport.send_out(2, "About to run: "+command)

   (sin, sout, serr) = os.popen3( command )

   outstring = sout.read()
   errstring = serr.read()
Exemplo n.º 23
0
def login( username, password,site="www.planet-lab.org"):

   print "Using site:",site

   if site == "www.planet-lab.org":
      authtype = "PLauthenticate"
   elif site == "www.planet-lab.eu":
      authtype = "PLEauthenticate"
   else:
      raise ValueError, "Unrecognized site: "+site

   # the curl command to login
   command = arizonaconfig.get_option("curlpath")+" -L -k -d \"%USERINFO%\" -D GetCookie "+repository+":8081/stork/login.php?"

   # build the user info string
   info = "username="******"&password="******"&authmethod="+urllib.quote(authtype)
   command  = command.replace( "%USERINFO%", info )

   # try to run the command and see what we get
   (sin, sout, serr) = os.popen3( command )

   outstring = sout.read()
   errstring = serr.read()

   sout.close()
   serr.close()

   if "incorrect username" not in outstring:
      return True

   else:
      return False
Exemplo n.º 24
0
def get_file(relative_path,outputfile):
   tmptuple = tempfile.mkstemp("curldownload")
   tmp      = tmptuple[1]
   try:
      tmptuple[0].close()
   except:
      pass

   command = arizonaconfig.get_option("curlpath")+" -L -w '%{http_code}' -k -o "+tmp+" "+repository+":8081/"+relative_path
 
   arizonareport.send_out(2, "About to run: "+command)

   (sin, sout, serr) = os.popen3( command )

   outline = sout.read()
   sout.close()
   serr.close()

   if outline == "" or outline != "200":
      try:
         os.unlink(tmp)
      except:
         pass
      return False
   else:
      try:
         shutil.move(tmp, outputfile)
      except:
         pass
      return True
Exemplo n.º 25
0
def publickey_string():
   """

   XXX This function is deprecated and will be going away soon

   <Purpose>
      This returns a stringlist containing the publickey

   <Arguments>
      None (all command line arguments)

   <Exceptions>
      TypeError may be returned if the user hasn't specified a username and
      a valid publickeyfile

   <Side Effects>
      None (calls config_prefix())

   <Returns>
      A stringlist containing the publickey
   """
   config_prefix()
   (success, publickey_sl) = arizonacrypt.publickey_fn_to_sl(arizonaconfig.get_option("publickeyfile"))
   publickey_string = arizonacrypt.publickey_sl_to_fnstring(publickey_sl)
   return publickey_string
Exemplo n.º 26
0
def set_verbosity(verbosity):
   """
   <Purpose>
      Sets the current verbosity level.

   <Arguments>   
      verbosity:
              The new verbosity level:
                4 - ULTRAVERBOSE aka DEBUG
                3 - VERYVERBOSE aka DEBUG
                2 - VERBOSE
                1 - QUIET
                0 - VERYQUIET
               -1 - ABSOLUTE SILENCE
   
   <Exceptions>
      None.
   
   <Side Effects>
      Changes the storkconfig "verbose" setting. 

   <Returns>
      None.
   """
   # check params
   if not isinstance(verbosity, int): 
      raise TypeError, "The parameter 'verbosity' of the function 'set_verbosity' must be an integer."
   if verbosity < -1 or verbosity > 4:
      raise TypeError, "The parameter 'verbosity' of the function 'set_verbosity' must be from -1 to 4, inclusive."

   if arizonaconfig.get_option("verbose") == None:
      arizonaconfig.init_options("arizonareport")
      
   arizonaconfig.set_option("verbose", verbosity)
Exemplo n.º 27
0
def get_verbosity():
   """
   <Purpose>
      Returns the current verbosity level:
        4 - ULTRAVERBOSE aka DEBUG
        3 - VERYVERBOSE aka DEBUG
        2 - VERBOSE
        1 - QUIET
        0 - VERYQUIET
       -1 - ABSOLUTE SILENCE
 
   <Arguments>   
      None. 
   
   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      Returns the current verbosity level.  See "Purpose", above.
   """
   verbosity = arizonaconfig.get_option("verbose")
   if verbosity == None:
      arizonaconfig.init_options("arizonareport")
      # stork default (--verbose)
      return 2            
   else: 
      return verbosity  
Exemplo n.º 28
0
def upload_single_log(filename, suffix, subdir, compressFunc):
   filename = arizonaconfig.get_option("logdir") + "/" + filename

   newname = arizonaconfig.get_option("logdir") + "/" + get_hostname() + \
                                      "^" + get_username() + \
                                      "^" + str(time.time()) + suffix

   if not os.path.exists(filename):
       return

   try:
       os.rename(filename, newname)
   except:
       print "failed to rename " + str(filename) + " to " + str(newname)
       return

   upload_logs(suffix, subdir, None, compressFunc)
Exemplo n.º 29
0
def init_client(client_name):
   try:
      os.makedirs(__path(client_name,"/"))
   except OSError:
      # If the directory exists, this is okay...
      pass
   result = __share_directory(client_name, '/', arizonaconfig.get_option('slicename'), __path(client_name,"/"), "")		
   return result
Exemplo n.º 30
0
   def test_get_installed_versions(self):
      self.restore_stdout()
      # A non-string
      self.assertException(TypeError, storktar.get_installed_versions, 3)
      # a list of ints
      self.assertException(TypeError, storktar.get_installed_versions, [3, 5, 7])
      
      # obviously not-existing package
      self.assertEqual(storktar.get_installed_versions([""]), [])      

      # another not-existing package
      self.assertEqual(storktar.get_installed_versions(["rpm"]), [])      

      # create a info file 
      packinfo_dir = arizonaconfig.get_option("tarpackinfopath")
      if not os.path.exists(packinfo_dir):
         os.mkdir(packinfo_dir)
      testpack1 = "testpack1.packinfo"
      tempfile = file(packinfo_dir + "/"+ testpack1, "w")
      tempfile.write("testing1\nversion\n3.5\nTest pack")
      tempfile.close()
      
      # check it with package name 'testpack1'
      self.assertEqual(storktar.get_installed_versions(["testpack1"]), ["testing1 = version-3.5"])      

      # create another info file
      testpack2 = "testpack2.tgz.packinfo"
      tempfile = file(packinfo_dir + "/"+ testpack2, "w")
      tempfile.write("testing2\nversion\n3.14\nTest pack")
      tempfile.close()
      
      # check it with package name 'testpack1'
      self.assertEqual(storktar.get_installed_versions(["testpack2"]), ["testing2 = version-3.14"])      
      
      # create 3rd info file
      testpack3 = "testpack3.tar.gz.packinfo"
      tempfile = file(packinfo_dir + "/"+ testpack3, "w")
      tempfile.write("testing3\nversion\n2.93\nTest pack3")
      tempfile.close()
      
      # check it with package name 'testpack1'
      self.assertEqual(storktar.get_installed_versions(["testpack3"]), ["testing3 = version-2.93"])      

      # put these files all together
      self.assertEqual(storktar.get_installed_versions(["testpack1", "testpack2", "testpack3"]), ['testing1 = version-3.5', 'testing2 = version-3.14', 'testing3 = version-2.93'])      

      # some packages of the package list don't exist
      self.assertEqual(storktar.get_installed_versions(["testpack1", "rpm", "testpack2", "ls",  "nano", "testpack3"]), 
                                                         ['testing1 = version-3.5', 'testing2 = version-3.14', 'testing3 = version-2.93'])            
      

      # remove testing files and directory
      os.remove(packinfo_dir + "/" + testpack1)
      os.remove(packinfo_dir + "/" + testpack2)
      os.remove(packinfo_dir + "/" + testpack3)
      os.rmdir(packinfo_dir)