Exemple #1
0
 def put(self, urlarray, payload):
     url = self._array2url(urlarray)
     debug("Sending PUT to %s" % url)
     r = requests.put("%s/%s" % (self._baseurl, url),
                      auth=self._auth,
                      headers=self._jsonheader,
                      verify=False,
                      data=json.dumps(payload),
                      timeout=self._timeout)
     debug("Return code: %d" % r.status_code)
     if r.status_code == 201:
         j = json.loads(r.text)
     else:
         error("PUT to %s returned %d" % (url, r.status_code))
         j = {}
     return r.status_code, j
Exemple #2
0
 def rman(self, finalscript):
     self._setenv()
     debug("RMAN execution starts")
     BackupLogger.close()
     starttime = datetime.now()
     with TemporaryFile() as f:
         p = Popen([os.path.join(self.oraclehome, 'bin', 'rman'), "log", BackupLogger.logfile, "append"], stdout=f, stderr=f, stdin=PIPE)
         # Send the script to RMAN
         p.communicate(input=finalscript)
     endtime = datetime.now()
     BackupLogger.init()
     debug("RMAN execution time %s" % (endtime-starttime))
     # If RMAN exists with any code except 0, then there was some error
     if p.returncode != 0:
         error("RMAN execution failed with code %d" % p.returncode)
         raise Exception('rman', "RMAN exited with code %d" % p.returncode)
     else:
         debug("RMAN execution successful")
Exemple #3
0
 def sqlldr(self, login, finalscript):
     self._setenv()
     debug("SQLLDR execution starts")
     f1 = mkstemp(suffix=".ctl")
     ftmp = os.fdopen(f1[0], "w")
     ftmp.write(finalscript)
     ftmp.close()
     f2 = mkstemp(suffix=".log")
     os.close(f2[0])
     with TemporaryFile() as f:
         p = Popen([os.path.join(self.oraclehome, 'bin', 'sqlldr'), login, "control=%s" % f1[1], "log=%s" % f2[1], "errors=0", "silent=all"], stdout=f, stderr=None, stdin=None)
         p.communicate()
         if p.returncode != 0:
             error("SQLLDR exited with code %d" % p.returncode)
             raise Exception('sqlldr', "sqlldr exited with code %d" % p.returncode)
         else:
             debug("SQLLDR execution successful")
     os.unlink(f1[1])
     os.unlink(f2[1])
Exemple #4
0
 def get(self, urlarray, return_json=True):
     url = self._array2url(urlarray)
     debug("Sending GET to %s" % url)
     r = requests.get("%s/%s" % (self._baseurl, url),
                      auth=self._auth,
                      headers=self._jsonheader,
                      verify=False,
                      timeout=self._timeout)
     debug("Return code: %d" % r.status_code)
     if r.status_code != 200:
         error("GET to %s returned %d" % (url, r.status_code))
         raise Exception(
             'zfssareturncode',
             "GET request return code is not 200 (%s)" % r.status_code)
     if return_json:
         j = json.loads(r.text)
         return j
     else:
         return None
Exemple #5
0
 def sqlplus(self, finalscript, silent=False):
     self._setenv()
     with TemporaryFile() as f:
         args = [os.path.join(self.oraclehome, 'bin', 'sqlplus')]
         if silent:
             args.append('-S')
         args.append('/nolog')
         debug("SQL*Plus execution starts")
         BackupLogger.close()
         p = Popen(args, stdout=f, stderr=f, stdin=PIPE)
         p.communicate(input=finalscript)
         BackupLogger.init()
         if p.returncode != 0:
             error("SQL*Plus exited with code %d" % p.returncode)
             raise Exception('sqlplus', "sqlplus exited with code %d" % p.returncode)
         else:
             debug("SQL*Plus execution successful")
         if silent:
             f.seek(0,0)
             return f.read()
Exemple #6
0
 def dropclone(self, cloneid):
     j = self.filesystem_info(cloneid)
     if "origin" not in j:
         raise Exception(self._exceptionbase,
                         'Specified filesystem is not a clone.')
     origin = j["origin"]
     if origin["project"] != self._project or origin[
             "share"] != self._filesystem:
         raise Excption(
             self._exceptionbase,
             "Specified filesystem is not cloned from share %s" %
             self._filesystem)
     r = self._http.delete([
         'pools', self._pool, 'projects', self._project, 'filesystems',
         cloneid
     ])
     if r != 204:
         error("Dropping clone failed. Return code: %d" % r)
         raise Exception(self._exceptionbase,
                         "Dropping clone failed. Return code: %d" % r)