def __init__(self,options): # Convert options to context if options.upgradeset : self.requested_action = 'Activate' elif options.preupgradeset : self.requested_action = 'Pre-Upgrade' elif options.addset : self.requested_action = 'Install Add' elif options.postupgradeset : self.requested_action = 'Post-Upgrade' elif options.pkg_state: self.requested_action = 'Get-Package' elif options.commitset : self.requested_action = 'Install Commit' if options.repository_path : self.server_repository_url = options.repository_path self.host = Host() if options.device_url : self.host_urls = options.device_url[:] if options.devices: self.host_urls = get_urls_from_txt(options.devices,1)[:] if options.pkg_file and not options.repository_path : self.server_repository_url = pkglist.get_repo(options.pkg_file) elif options.repository_path : self.server_repository_url = options.repository_path if options.pkg_file : self.software_packages = pkglist.get_pkgs(options.pkg_file) self.log_directory = options.logdir self.active_cli = None self.inactive_cli = None self.committed_cli = None
def __init__(self, options): # Convert options to context if options.upgradeset: self.requested_action = 'Activate' elif options.preupgradeset: self.requested_action = 'Pre-Upgrade' elif options.addset: self.requested_action = 'Install Add' elif options.postupgradeset: self.requested_action = 'Post-Upgrade' elif options.pkg_state: self.requested_action = 'Get-Package' elif options.commitset: self.requested_action = 'Install Commit' if options.repository_path: self.server_repository_url = options.repository_path self.host = Host() if options.device_url: self.host_urls = options.device_url[:] if options.devices: self.host_urls = get_urls_from_txt(options.devices, 1)[:] if options.pkg_file and not options.repository_path: self.server_repository_url = pkglist.get_repo(options.pkg_file) elif options.repository_path: self.server_repository_url = options.repository_path if options.pkg_file: self.software_packages = pkglist.get_pkgs(options.pkg_file) self.log_directory = options.logdir self.active_cli = None self.inactive_cli = None self.committed_cli = None
def start(self, device, *args, **kwargs): file_systems = self._get_filesystems(device) disk0 = file_systems.get('disk0:', None) if not disk0: self.error("No filesystem 'disk0:' on active RP") disk1 = file_systems.get('disk1:', None) if not disk1: self.log("No filesystem 'disk1:' on active RP") for fs, values in file_systems.iteritems(): if 'rw' not in values.get('flags'): self.error("{} is not 'rw'".format(fs)) if not self._can_create_dir(device, "disk0:"): self.error("Can't create dir on disk0:") free_disk0 = disk0.get('free', 0) repository_path = kwargs.get("repository", None) if not repository_path: self.error("No repository path provided") if repository_path[:4] == 'sftp': self.log('Skipping as disk space check not supported for sftp') return pkg_file = kwargs.get("pkg_file", None) if not pkg_file: self.error("No package list file provided.") packages = pkglist.get_pkgs(pkg_file) total_size = 0 for package in packages: package_url = os.path.join(repository_path, package) size = self._get_pie_size(device, package_url) total_size += size self.log("Package: {} requires {} bytes".format(package_url, size)) self.log( "Total (required/available): {}/{} bytes".format( total_size, free_disk0 ) ) if free_disk0 < total_size: self.error("Not enough space on disk0: to install packages.") return True
def start(self, device, *args, **kwargs): file_systems = self._get_filesystems(device) disk0 = file_systems.get('disk0:', None) if not disk0: self.error("No filesystem 'disk0:' on active RP") disk1 = file_systems.get('disk1:', None) if not disk1: self.log("No filesystem 'disk1:' on active RP") for fs, values in file_systems.iteritems(): if 'rw' not in values.get('flags'): self.error("{} is not 'rw'".format(fs)) if not self._can_create_dir(device, "disk0:"): self.error("Can't create dir on disk0:") free_disk0 = disk0.get('free', 0) repository_path = kwargs.get("repository", None) if not repository_path: self.error("No repository path provided") if repository_path[:4] == 'sftp': self.log('Skipping as disk space check not supported for sftp') return pkg_file = kwargs.get("pkg_file", None) if not pkg_file: self.error("No package list file provided.") packages = pkglist.get_pkgs(pkg_file) total_size = 0 for package in packages: package_url = os.path.join(repository_path, package) size = self._get_pie_size(device, package_url) total_size += size self.log("Package: {} requires {} bytes".format(package_url, size)) self.log("Total (required/available): {}/{} bytes".format( total_size, free_disk0)) if free_disk0 < total_size: self.error("Not enough space on disk0: to install packages.") return True
def update_pkgs(self): if os.path.exists(self.inputfile): data = pkglist.get_pkgs(self.inputfile) else: data = self.inputfile.split("\n") start_pkg = False if data: for line in data: if line.find(self.pkg_state) < 0 and not start_pkg: continue elif not start_pkg: start_pkg = True pkg_name = line.strip() pkg = self.validate_xrpie_pkg(pkg_name) if not pkg: pkg = self.validate_xrrpm_pkg(pkg_name) if pkg: self.pkg_list.append(pkg)
def run(self, attempts=1): """ Add the given function to a queue, and call it once for each host according to the threading options. Use decorators.bind() if you also want to pass additional arguments to the callback function. Returns an object that represents the queued task, and that may be passed to is_completed() to check the status. @type hosts: string|list(string)|Host|list(Host) @param hosts: A hostname or Host object, or a list of them. @type function: function @param function: The function to execute. @type attempts: int @param attempts: The number of attempts on failure. @rtype: object @return: An object representing the task. """ # Enable logging. mode = self.options.overwrite_logs and "w" or "a" log_decorator = log_to_file(self.options.logdir, mode, self.options.delete_logs) pre_upgrade_decorator = pre_upgrade(self.options.preupgradeset) post_upgrade_decorator = post_upgrade(self.options.postupgradeset) upgrade_decorator = upgrade(self.options.upgradeset) cli_cmd_decorator = cli_cmd_file(self.options.cli_file) if hasattr(self.options, "repository_path"): repository_decorator = repository(self.options.repository_path) if hasattr(self.options, "pkg_file"): if isinstance(self.options.pkg_file, str): pkg_list = pkglist.get_pkgs(self.options.pkg_file) else: pkg_list = self.options.pkg_file pkg_file_decorator = pkg_file(pkg_list) turbo_boot_decorator = turbo_boot(self.options.turboboot) if hasattr(self.options, "issu"): issu_decorator = issu(self.options.issu) plugins_types = "ALL" if hasattr(self.options, "addset") and self.options.addset: plugins_types = "ADD" if self.options.pkg_state: plugins_types = "POLL" if self.options.commitset: plugins_types = "COMMIT" if self.options.preupgradeset: plugins_types = "PRE_UPGRADE" elif self.options.upgradeset: plugins_types = "UPGRADE" elif self.options.postupgradeset: plugins_types = "POST_UPGRADE" elif self.options.deactivateset: plugins_types = "DEACTIVATE" elif self.options.removeset: plugins_types = "REMOVE" for pno, plugin in enumerate(plugin_map[plugins_types], start=1): msg = "{} ({:0>2}) {} {}".format(HEADER, pno, plugin.DESCRIPTION, ENDC) # print("{0}{1:+<60}".format("+" * 20, msg)) function = plugin._start function = log_decorator(function) function = pre_upgrade_decorator(function) function = upgrade_decorator(function) function = post_upgrade_decorator(function) function = cli_cmd_decorator(function) if hasattr(self.options, "repository_path"): function = repository_decorator(function) if hasattr(self.options, "pkg_file"): function = pkg_file_decorator(function) function = turbo_boot_decorator(function) if hasattr(self.options, "issu"): function = issu_decorator(function) self._run(plugin, self.devices, function, self.workqueue.enqueue, attempts) self.join() if self.failed == len(self.devices): break self.reset()
def __init__(self, pkg_lst_file=None): self.inputfile = pkg_lst_file self.pkg_named_list = pkglist.get_pkgs(pkg_lst_file) self.pkg_list = [] if self.pkg_named_list: self._update_pkgs()
def run(self, attempts=1): """ Add the given function to a queue, and call it once for each host according to the threading options. Use decorators.bind() if you also want to pass additional arguments to the callback function. Returns an object that represents the queued task, and that may be passed to is_completed() to check the status. @type hosts: string|list(string)|Host|list(Host) @param hosts: A hostname or Host object, or a list of them. @type function: function @param function: The function to execute. @type attempts: int @param attempts: The number of attempts on failure. @rtype: object @return: An object representing the task. """ # Enable logging. mode = self.options.overwrite_logs and 'w' or 'a' log_decorator = log_to_file(self.options.logdir, mode, self.options.delete_logs) pre_upgrade_decorator = pre_upgrade(self.options.preupgradeset) post_upgrade_decorator = post_upgrade(self.options.postupgradeset) upgrade_decorator = upgrade(self.options.upgradeset) cli_cmd_decorator = cli_cmd_file(self.options.cli_file) if hasattr(self.options, 'repository_path'): repository_decorator = repository(self.options.repository_path) if hasattr(self.options, 'pkg_file'): if isinstance(self.options.pkg_file, str): pkg_list = pkglist.get_pkgs(self.options.pkg_file) else: pkg_list = self.options.pkg_file pkg_file_decorator = pkg_file(pkg_list) turbo_boot_decorator = turbo_boot(self.options.turboboot) if hasattr(self.options, 'issu'): issu_decorator = issu(self.options.issu) plugins_types = "ALL" if hasattr(self.options, 'addset') and self.options.addset: plugins_types = "ADD" if self.options.pkg_state: plugins_types = "POLL" if self.options.commitset: plugins_types = "COMMIT" if self.options.preupgradeset: plugins_types = "PRE_UPGRADE" elif self.options.upgradeset: plugins_types = "UPGRADE" elif self.options.postupgradeset: plugins_types = "POST_UPGRADE" for pno, plugin in enumerate(plugin_map[plugins_types], start=1): msg = "{} ({:0>2}) {} {}".format(HEADER, pno, plugin.DESCRIPTION, ENDC) #print("{0}{1:+<60}".format("+" * 20, msg)) function = plugin._start function = log_decorator(function) function = pre_upgrade_decorator(function) function = upgrade_decorator(function) function = post_upgrade_decorator(function) function = cli_cmd_decorator(function) if hasattr(self.options, 'repository_path'): function = repository_decorator(function) if hasattr(self.options, 'pkg_file'): function = pkg_file_decorator(function) function = turbo_boot_decorator(function) if hasattr(self.options, 'issu'): function = issu_decorator(function) self._run(plugin, self.devices, function, self.workqueue.enqueue, attempts) self.join() if self.failed == len(self.devices): break self.reset()