def go(self, argv): """ The main entry point into XenBackup #. Do something #. Do something else """ # Read the command line options self.get_options(argv) self.host = XenHost(self.args['-u'], self.args['<servername>'], self.args['-p']) vms = self.host.get_vm_list() print(self.config) ready = self.host.before_backup(self.config['backup_location']['precommands'], self.config['backup_location']['dir'], ) if ready: backup_vm_list = self.config['backup_vm_names'] for vm_obj in self.host.iter_vm(backup_vm_list): vm_obj.backup() ready = self.host.after_backup(self.config['backup_location']['postcommands']) else: print("Error trying to find backup location")
class XenBackup(object): """ The main clas. Performs the following functions: """ def __init__ (self): """ """ self.config = None def _get_config_file(self, config_file): """ Read in the yaml config file :param config_file: Configuration file (YAML format) :type config_file: file :returns: dict of yaml file :rtype: dict """ with config_file: myconfig = yaml.load(config_file) return myconfig def get_options(self, argv): """ Parse the command-line options and set the following object properties: :param argv: usually just sys.argv[1:] :returns: Nothing :ivar debug: Enable logging debug statements :ivar verbose: Enable verbose logging :ivar config: Dict of the config file """ self.args = argv if argv['--verbose']: logging.basicConfig(level=logging.INFO, format='%(message)s') if argv['--debug']: logging.basicConfig(level=logging.DEBUG, format='%(message)s') config_filename = self.args['<config>'] assert os.path.exists(config_filename), "Oops, cannot find config file" with open(self.args['<config>']) as f: self.config = yaml.load(f) def go(self, argv): """ The main entry point into XenBackup #. Do something #. Do something else """ # Read the command line options self.get_options(argv) self.host = XenHost(self.args['-u'], self.args['<servername>'], self.args['-p']) vms = self.host.get_vm_list() print(self.config) ready = self.host.before_backup(self.config['backup_location']['precommands'], self.config['backup_location']['dir'], ) if ready: backup_vm_list = self.config['backup_vm_names'] for vm_obj in self.host.iter_vm(backup_vm_list): vm_obj.backup() ready = self.host.after_backup(self.config['backup_location']['postcommands']) else: print("Error trying to find backup location")