def create_backup_be(self, be_name=None): """Create a backup BE if the BE being modified is the live one. 'be_name' is an optional string indicating the name to use for the new backup BE.""" self.check_be_name(be_name) if self.is_live_BE: # Create a clone of the live BE, but do not mount or # activate it. Do nothing with the returned snapshot # name that is taken of the clone during beCopy. ret, be_name_clone, not_used = be.beCopy() if ret != 0: raise api_errors.UnableToCopyBE() if not be_name: be_name = self.get_new_be_name( suffix="-backup-1") ret = be.beRename(be_name_clone, be_name) if ret != 0: raise api_errors.UnableToRenameBE( be_name_clone, be_name) elif be_name is not None: raise api_errors.BENameGivenOnDeadBE(be_name)
def rename(opts): """ Description: Rename the name of a Boot Environment. The following is the subcommand, options and args that make up the opts object passed in: rename beName newBeName Parameters: opts - A object containing the mount subcommand and all the options and arguments passed in on the command line mentioned above. Returns: 0 - Success 1 - Failure """ be = BootEnvironment() try: be_names = getopt.getopt(opts, "")[1] except getopt.GetoptError: msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1) usage() if len(be_names) != 2: msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1) usage() if lb.beVerifyBEName(be_names[0]) != 0: msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1) return 1 if lb.beVerifyBEName(be_names[1]) != 0: msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1) return 1 rc = lb.beRename(be_names[0], be_names[1]) if rc == 0: return 0 be.msg_buf["0"] = be_names[0] if rc == msg.Msgs.BE_ERR_BE_NOENT: be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, be_names[0]) elif rc == msg.Msgs.BE_ERR_PERM or rc == msg.Msgs.BE_ERR_ACCESS: be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_PERMISSIONS, rc) msg.printMsg(msg.Msgs.BEADM_ERR_RENAME, be.msg_buf, -1) return 1 else: be.msg_buf["1"] = lb.beGetErrDesc(rc) if be.msg_buf["1"] == None: be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc) msg.printMsg(msg.Msgs.BEADM_ERR_RENAME, be.msg_buf, -1) return 1
def init_image_recovery(self, img, be_name=None): """Initialize for an update. If a be_name is given, validate it. If we're operating on a live BE then clone the live BE and operate on the clone. If we're operating on a non-live BE we use the already created snapshot""" self.img = img if self.is_live_BE: # Create a clone of the live BE and mount it. self.destroy_snapshot() self.check_be_name(be_name) # Do nothing with the returned snapshot name # that is taken of the clone during beCopy. ret, self.be_name_clone, not_used = be.beCopy() if ret != 0: raise api_errors.UnableToCopyBE() if be_name: ret = be.beRename(self.be_name_clone, be_name) if ret == 0: self.be_name_clone = be_name else: raise api_errors.UnableToRenameBE( self.be_name_clone, be_name) if be.beMount(self.be_name_clone, self.clone_dir) != 0: raise api_errors.UnableToMountBE( self.be_name_clone, self.clone_dir) # record the UUID of this cloned boot environment not_used, self.be_name_clone_uuid = \ BootEnv.get_be_name(self.clone_dir) # Set the image to our new mounted BE. img.find_root(self.clone_dir, exact_match=True) elif be_name is not None: raise api_errors.BENameGivenOnDeadBE(be_name)
def init_image_recovery(self, img, be_name=None): """Initialize for an image-update. If a be_name is given, validate it. If we're operating on a live BE then clone the live BE and operate on the clone. If we're operating on a non-live BE we use the already created snapshot""" self.img = img if self.is_live_BE: # Create a clone of the live BE and mount it. self.destroy_snapshot() self.check_be_name(be_name) # Do nothing with the returned snapshot name # that is taken of the clone during beCopy. ret, self.be_name_clone, not_used = be.beCopy() if ret != 0: raise api_errors.UnableToCopyBE() if be_name: ret = be.beRename(self.be_name_clone, be_name) if ret == 0: self.be_name_clone = be_name else: raise api_errors.UnableToRenameBE( self.be_name_clone, be_name) if be.beMount(self.be_name_clone, self.clone_dir) != 0: raise api_errors.UnableToMountBE( self.be_name_clone, self.clone_dir) # Set the image to our new mounted BE. img.find_root(self.clone_dir) elif be_name is not None: raise api_errors.BENameGivenOnDeadBE(be_name)
def rename_be(orig_name, new_name): return be.beRename(orig_name, new_name)
def rename(opts): """ Description: Rename the name of a Boot Environment. The following is the subcommand, options and args that make up the opts object passed in: rename beName newBeName Parameters: opts - A object containing the mount subcommand and all the options and arguments passed in on the command line mentioned above. Returns: 0 - Success 1 - Failure """ be = BootEnvironment() try: be_names = getopt.getopt(opts, "")[1] except getopt.GetoptError: msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1) usage() if len(be_names) != 2: msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1) usage() if lb.beVerifyBEName(be_names[0]) != 0: msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1) return 1 if lb.beVerifyBEName(be_names[1]) != 0: msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1) return 1 rc = lb.beRename(be_names[0], be_names[1]) if rc == 0: return 0 be.msg_buf["0"] = be_names[0] if rc == msg.Msgs.BE_ERR_BE_NOENT: be.msg_buf["1"] = \ msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, be_names[0]) elif rc == msg.Msgs.BE_ERR_PERM or rc == msg.Msgs.BE_ERR_ACCESS: be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_PERMISSIONS, rc) msg.printMsg(msg.Msgs.BEADM_ERR_RENAME, be.msg_buf, -1) return 1 else: be.msg_buf["1"] = lb.beGetErrDesc(rc) if be.msg_buf["1"] == None: be.msg_buf["1"] = \ msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc) msg.printMsg(msg.Msgs.BEADM_ERR_RENAME, be.msg_buf, -1) return 1