Exemple #1
0
 def mount(self):
     """Mount the filesystem. Not responsibile for checking that is already
     mounted (caller should check with is_mounted() first). Is responsible
     to create the parent of the mount point (e.g. /mnt) if it does not
     already exist.
     """
     # the real work is done in _do_mount(). We provide some common error handling here
     with capture_logging(logging.getLogger()) as l:
         try:
             self._do_mount()
         except UserError:
             raise
         except Exception, e:
             raise UserError(errors[ERR_MOUNT],
                             msg_args={'mp':self.connect_args.mp,
                                       'name':self.df_name,
                                       'error':e},
                             context=l.getvalue().split('\n'),
                             developer_msg=self.connect_args.__repr__())
Exemple #2
0
 def run_smbinfo(credentials_file):
     with capture_logging(logging.getLogger()) as l:
         r = re.compile(re.escape("Share: ") + r'(.+)$')
         shares = []
         cmd = [smbinfo, '-a', credentials_file, 'list-shares', host_or_ip]
         if os.getuid()!=0:
             cmd = ['/usr/bin/sudo',] + cmd
         try:
             results = process.run_program_and_capture_results(cmd, None, logger, expected_rcs=[0])
             for line in results.split('\n'):
                 mo = r.match(line)
                 if mo!=None:
                     shares.append(mo.group(1))
         except process.SubprocBadRcError, e:
             # check the various error codes
             if e.rc==4:
                 ue = convert_exc_to_user_error(sys.exc_info(),
                                                errors[ERR_SHARE_LIST_PERM],
                                                msg_args={'host':host_or_ip})
             elif e.rc==110:
                 ue = convert_exc_to_user_error(sys.exc_info(),
                                                errors[ERR_SHARE_CONN_TIMEOUT],
                                                msg_args={'host':host_or_ip})
             else:
                 ue = convert_exc_to_user_error(sys.exc_info(),
                                                errors[ERR_SHARE_LIST_EXC],
                                                msg_args={"host":host_or_ip,
                                                          "exc":"%s(%s)" % (e.__class__.__name__,
                                                                            unicode(e))})
             ue.developer_msg = l.getvalue()
             raise ue
         except Exception, e:
             ue = convert_exc_to_user_error(sys.exc_info(),
                                            errors[ERR_SHARE_LIST_EXC],
                                            msg_args={"host":host_or_ip,
                                                      "exc":"%s(%s)" % (e.__class__.__name__,
                                                                        unicode(e))})
             ue.developer_msg = l.getvalue()
             raise ue