def check_for_package(connection, reponame, package): ''' list packages in a repository ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "p") RHUIManager.select_one(connection, reponame) Expect.expect(connection, "\(blank line for no filter\):") Expect.enter(connection, package) pattern = re.compile('.*only\.\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] reslist = map(lambda x: x.strip(), ret.split("\r\n")) print reslist packagelist = [] for line in reslist: if line == '': continue if line == 'Packages:': continue if line == 'No packages found that match the given filter.': continue if line == 'No packages in the repository.': continue packagelist.append(line) Expect.enter(connection, 'q') return packagelist
def check_for_package(connection, reponame, package): ''' list packages in a repository ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "p") RHUIManager.select_one(connection, reponame) Expect.expect(connection, "\(blank line for no filter\):") Expect.enter(connection, package) pattern = re.compile( '.*only\.\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] reslist = map(lambda x: x.strip(), ret.split("\r\n")) print reslist packagelist = [] for line in reslist: if line == '': continue if line == 'Packages:': continue if line == 'No packages found that match the given filter.': continue if line == 'No packages in the repository.': continue packagelist.append(line) Expect.enter(connection, 'q') return packagelist
def list(connection): ''' list repositories ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "l") # eating prompt!! pattern = re.compile('l\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] print ret reslist = map(lambda x: x.strip(), ret.split("\r\n")) print reslist repolist = [] for line in reslist: # Readling lines and searching for repos if line == '': continue if "Custom Repositories" in line: continue if "Red Hat Repositories" in line: continue if "No repositories are currently managed by the RHUI" in line: continue repolist.append(line) Expect.enter(connection, 'q') return repolist
def associate_repo_cds(connection, clustername, repolist): ''' associate a repository with a CDS cluster ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "s") RHUIManager.select_one(connection, clustername) RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check(connection, "The following repositories will be associated with the " + clustername + " cluster:", repolist, ["Red Hat Repositories", "Custom Repositories"]) RHUIManager.quit(connection)
def info(connection, repolist): ''' detailed information about repositories Method returns list of items from rhui-manager info screen. Some of them are variable and these are replaced by "rh_repo" constant. ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "i") RHUIManager.select(connection, repolist) try: pattern = re.compile( '.*for more commands: \r\n\r\nName:\s(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] print ret res = map(lambda x: x.strip(), ret.split("\r\n")) reslist = ["Name:"] for line in res: reslist.extend( map(lambda y: y.strip(), re.split("\s{3}", line))) print reslist repoinfo = [] rh_repo = 0 rh_repo_info = 0 for line in reslist: # Readling lines if line == '': continue if rh_repo_info == 1: line = "rh_repo" rh_repo_info = 0 if line == "Red Hat": rh_repo = 1 if "Relative Path:" in line: if rh_repo == 1: rh_repo_info = 1 if "Package Count:" in line: if rh_repo == 1: rh_repo_info = 1 if "Last Sync:" in line: if rh_repo == 1: rh_repo_info = 1 if "Next Sync:" in line: if rh_repo == 1: rh_repo_info = 1 repoinfo.append(line) print repoinfo except: repoinfo = [] Expect.enter(connection, 'q') return repoinfo
def list(connection): ''' return the list of currently managed CDSes ''' RHUIManager.screen(connection, "cds") # eating prompt!! lines = RHUIManager.list_lines(connection, prompt=RHUIManagerCds.prompt) ret = Cds.parse(lines) # custom quitting; have eaten the prompt Expect.enter(connection, 'q') return [cds for _, cds in ret]
def _sync_cds(self, cdslist): """ Sync cds """ if (not "RHUA" in self.rs.Instances.keys()) or len(self.rs.Instances["RHUA"]) < 1: raise nose.exc.SkipTest("can't test without RHUA!") try: RHUIManagerSync.sync_cds(self.rs.Instances["RHUA"][0], cdslist) except ExpectFailed: # The CDS is not available for syncing so most probably it's syncing right now # Trying to check the status Expect.enter(self.rs.Instances["RHUA"][0], "b") RHUIManager.quit(self.rs.Instances["RHUA"][0]) self._sync_wait_cds(cdslist)
def info(connection, repolist): ''' detailed information about repositories Method returns list of items from rhui-manager info screen. Some of them are variable and these are replaced by "rh_repo" constant. ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "i") RHUIManager.select(connection, repolist) try: pattern = re.compile('.*for more commands: \r\n\r\nName:\s(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] print ret res = map(lambda x: x.strip(), ret.split("\r\n")) reslist = ["Name:"] for line in res: reslist.extend(map(lambda y: y.strip(), re.split("\s{3}", line))) print reslist repoinfo = [] rh_repo = 0 rh_repo_info = 0 for line in reslist: # Readling lines if line == '': continue if rh_repo_info == 1: line = "rh_repo" rh_repo_info = 0 if line == "Red Hat": rh_repo = 1 if "Relative Path:" in line: if rh_repo == 1: rh_repo_info = 1 if "Package Count:" in line: if rh_repo == 1: rh_repo_info = 1 if "Last Sync:" in line: if rh_repo == 1: rh_repo_info = 1 if "Next Sync:" in line: if rh_repo == 1: rh_repo_info = 1 repoinfo.append(line) print repoinfo except: repoinfo = [] Expect.enter(connection, 'q') return repoinfo
def change_password(connection, username, password): ''' change a user's password ''' RHUIManager.screen(connection, "users") Expect.enter(connection, "p") Expect.expect(connection, "Username:"******"New Password:"******"Re-enter Password:"******"Password successfully updated")
def _sync_cds(self, cdslist): """ Sync cds """ if (not "RHUA" in self.rs.Instances.keys()) or len( self.rs.Instances["RHUA"]) < 1: raise nose.exc.SkipTest("can't test without RHUA!") try: RHUIManagerSync.sync_cds(self.rs.Instances["RHUA"][0], cdslist) except ExpectFailed: # The CDS is not available for syncing so most probably it's syncing right now # Trying to check the status Expect.enter(self.rs.Instances["RHUA"][0], "b") RHUIManager.quit(self.rs.Instances["RHUA"][0]) self._sync_wait_cds(cdslist)
def list(connection): """ return the list currently managed CDSes and clusters as it is provided by the cds list command """ RHUIManager.screen(connection, "cds") Expect.enter(connection, "l") # eating prompt!! pattern = re.compile("l(\r\n)+(.*)rhui\s* \(cds\)\s* =>", re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[2])[0] # custom quitting; have eaten the prompt Expect.enter(connection, "q") return ret
def list(connection): ''' return the list currently managed CDSes and clusters as it is provided by the cds list command ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "l") # eating prompt!! pattern = re.compile('l(\r\n)+(.*)rhui\s* \(cds\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[2])[0] # custom quitting; have eaten the prompt Expect.enter(connection, 'q') return ret
def delete_cds(connection, clustername, cdslist, force=False): ''' unregister (delete) a CDS instance from the RHUI ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "d") RHUIManager.select_one(connection, clustername) RHUIManager.select(connection, cdslist) RHUIManager.proceed_with_check(connection, "The following CDS instances from the %s cluster will be unregistered:" % clustername, cdslist) if force: Expect.expect(connection, "Forcibly remove these CDS instances", 60) Expect.enter(connection, "y") RHUIManager.quit(connection, timeout=30)
def get_cds_status(connection, cdsname): ''' display CDS sync summary ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "dc") res_list = Expect.match(connection, re.compile(".*\n" + cdsname.replace(".", "\.") + "[\.\s]*\[([^\n]*)\].*" + cdsname.replace(".", "\.") + "\s*\r\n([^\n]*)\r\n", re.DOTALL), [1, 2], 60) connection.cli.exec_command("killall -s SIGINT rhui-manager") ret_list = [] for val in [res_list[0]] + res_list[1].split(" "): val = Util.uncolorify(val.strip()) ret_list.append(val) RHUIManager.quit(connection) return ret_list
def delete_cds(connection, clustername, cdslist, force=False): """ unregister (delete) a CDS instance from the RHUI """ RHUIManager.screen(connection, "cds") Expect.enter(connection, "d") RHUIManager.select_one(connection, clustername) RHUIManager.select(connection, cdslist) RHUIManager.proceed_with_check( connection, "The following CDS instances from the %s cluster will be unregistered:" % clustername, cdslist ) if force: Expect.expect(connection, "Forcibly remove these CDS instances", 60) Expect.enter(connection, "y") RHUIManager.quit(connection, timeout=30)
def get_repo_status(connection, reponame): ''' display repo sync summary ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "dr") reponame_quoted = reponame.replace(".", "\.") res = Expect.match(connection, re.compile(".*" + reponame_quoted + "\s*\r\n([^\n]*)\r\n.*", re.DOTALL), [1], 60)[0] connection.cli.exec_command("killall -s SIGINT rhui-manager") res = Util.uncolorify(res) ret_list = res.split(" ") for i in range(len(ret_list)): ret_list[i] = ret_list[i].strip() RHUIManager.quit(connection) return ret_list
def associate_repo_cds(connection, clustername, repolist): """ associate a repository with a CDS cluster """ RHUIManager.screen(connection, "cds") Expect.enter(connection, "s") RHUIManager.select_one(connection, clustername) RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check( connection, "The following repositories will be associated with the " + clustername + " cluster:", repolist, ["Red Hat Repositories", "Custom Repositories"], ) RHUIManager.quit(connection)
def generate_new(connection, days="", cert_pw=None): ''' generate a new identity certificate ''' RHUIManager.screen(connection, "identity") Expect.enter(connection, "g") Expect.expect(connection, "Proceed\? \[y/n\]") Expect.enter(connection, "y") Expect.expect(connection, "regenerated using rhui-manager.*:") Expect.enter(connection, days) Expect.expect(connection, "Enter pass phrase for.*:") if cert_pw: Expect.enter(connection, cert_pw) else: Expect.enter(connection, Util.get_ca_password(connection)) RHUIManager.quit(connection, "Successfully regenerated RHUI Identity certificate", 30)
def sync_cluster(connection, clusterlist): ''' sync a CDS cluster immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sl") RHUIManager.select(connection, clusterlist) RHUIManager.proceed_with_check(connection, "The following CDS clusters will be scheduled for synchronization:", clusterlist) RHUIManager.quit(connection)
def delete_repo(connection, repolist): ''' delete a repository from the RHUI ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "d") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check(connection, "The following repositories will be deleted:", repolist, ["Red Hat Repositories", "Custom Repositories"]) RHUIManager.quit(connection)
def sync_cds(connection, cdslist): ''' sync an individual CDS immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sc") RHUIManager.select(connection, cdslist) RHUIManager.proceed_with_check(connection, "The following CDS instances will be scheduled for synchronization:", cdslist) RHUIManager.quit(connection)
def _sync_repo(self, repolist): """ Sync repo """ if (not "RHUA" in self.rs.Instances.keys()) or len(self.rs.Instances["RHUA"]) < 1: raise nose.exc.SkipTest("can't test without RHUA!") try: RHUIManagerSync.sync_repo(self.rs.Instances["RHUA"][0], repolist) except ExpectFailed: # The repo is not available for syncing so most probably it's syncing right now # Trying to check the status Expect.enter(self.rs.Instances["RHUA"][0], "b") RHUIManager.quit(self.rs.Instances["RHUA"][0]) for repo in repolist: reposync = ["In Progress", "", ""] while reposync[0] in ["In Progress", "Never"]: time.sleep(10) reposync = RHUIManagerSync.get_repo_status(self.rs.Instances["RHUA"][0], repo) nose.tools.assert_equal(reposync[2], "Success")
def get_repo_status(connection, reponame): ''' display repo sync summary ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "dr") reponame_quoted = reponame.replace(".", "\.") res = Expect.match( connection, re.compile(".*" + reponame_quoted + "\s*\r\n([^\n]*)\r\n.*", re.DOTALL), [1], 60)[0] connection.cli.exec_command("killall -s SIGINT rhui-manager") res = Util.uncolorify(res) ret_list = res.split(" ") for i in range(len(ret_list)): ret_list[i] = ret_list[i].strip() RHUIManager.quit(connection) return ret_list
def add_rh_repo_by_product(connection, productlist): ''' add a new Red Hat content repository (By Product) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 180) Expect.enter(connection, "2") RHUIManager.select(connection, productlist) RHUIManager.proceed_with_check(connection, "The following products will be deployed:", productlist) RHUIManager.quit(connection, "Content will not be downloaded", 45)
def upload_content(connection, repolist, path): ''' upload content to a custom repository ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "u") RHUIManager.select(connection, repolist) Expect.expect(connection, "will be uploaded:") Expect.enter(connection, path) RHUIManager.proceed_without_check(connection) RHUIManager.quit(connection)
def delete_repo(connection, repolist): ''' delete a repository from the RHUI ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "d") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check( connection, "The following repositories will be deleted:", repolist, ["Red Hat Repositories", "Custom Repositories"]) RHUIManager.quit(connection)
def sync_repo(connection, repolist): ''' sync an individual repository immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sr") Expect.expect(connection, "Select one or more repositories.*for more commands:", 60) Expect.enter(connection, "l") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check(connection, "The following repositories will be scheduled for synchronization:", repolist) RHUIManager.quit(connection)
def sync_cluster(connection, clusterlist): ''' sync a CDS cluster immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sl") RHUIManager.select(connection, clusterlist) RHUIManager.proceed_with_check( connection, "The following CDS clusters will be scheduled for synchronization:", clusterlist) RHUIManager.quit(connection)
def sync_cds(connection, cdslist): ''' sync an individual CDS immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sc") RHUIManager.select(connection, cdslist) RHUIManager.proceed_with_check( connection, "The following CDS instances will be scheduled for synchronization:", cdslist) RHUIManager.quit(connection)
def get_cds_status(connection, cdsname): ''' display CDS sync summary ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "dc") res_list = Expect.match( connection, re.compile( ".*\n" + cdsname.replace(".", "\.") + "[\.\s]*\[([^\n]*)\].*" + cdsname.replace(".", "\.") + "\s*\r\n([^\n]*)\r\n", re.DOTALL), [1, 2], 60) connection.cli.exec_command("killall -s SIGINT rhui-manager") ret_list = [] for val in [res_list[0]] + res_list[1].split(" "): val = Util.uncolorify(val.strip()) ret_list.append(val) RHUIManager.quit(connection) return ret_list
def move_cds(connection, cdslist, clustername): ''' move the CDSes to clustername ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "m") RHUIManager.select(connection, cdslist) RHUIManagerCds._select_cluster(connection, clustername) RHUIManager.proceed_with_check(connection, "The following Content Delivery Servers will be moved to the %s cluster:\r\n.*-+" % clustername, cdslist) RHUIManager.quit(connection, "successfully moved CDS")
def _sync_repo(self, repolist): """ Sync repo """ if (not "RHUA" in self.rs.Instances.keys()) or len( self.rs.Instances["RHUA"]) < 1: raise nose.exc.SkipTest("can't test without RHUA!") try: RHUIManagerSync.sync_repo(self.rs.Instances["RHUA"][0], repolist) except ExpectFailed: # The repo is not available for syncing so most probably it's syncing right now # Trying to check the status Expect.enter(self.rs.Instances["RHUA"][0], "b") RHUIManager.quit(self.rs.Instances["RHUA"][0]) for repo in repolist: reposync = ["In Progress", "", ""] while reposync[0] in ["In Progress", "Never"]: time.sleep(10) reposync = RHUIManagerSync.get_repo_status( self.rs.Instances["RHUA"][0], repo) nose.tools.assert_equal(reposync[2], "Success")
def add_rh_repo_by_product(connection, productlist): ''' add a new Red Hat content repository (By Product) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 180) Expect.enter(connection, "2") RHUIManager.select(connection, productlist) RHUIManager.proceed_with_check( connection, "The following products will be deployed:", productlist) RHUIManager.quit(connection, "Content will not be downloaded", 45)
def add_cds(connection, cds=Cds(), update=False): ''' Register (add) a new CDS instance @param cds: rhuilib.cds.Cds instance @param update: Bool; update the cds if it is already tracked or rise ExpectFailed ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "a") Expect.expect(connection, "Hostname of the Content Delivery Server instance to register:") Expect.enter(connection, cds.host_name) state = Expect.expect_list(connection, [ \ (re.compile(".*Username with SSH access to %s and sudo privileges:.*" % cds.host_name, re.DOTALL), 1), (re.compile(".*A Content Delivery Server instance with that hostname exists.*Continue\?\s+\(y/n\): ", re.DOTALL), 2) ]) if state == 2: # cds of the same hostname is already being tracked if not update: # but we don't wish to update its config: raise raise ExpectFailed("%s already tracked but update wasn't required" % cds.host_name) else: # we wish to update, send 'y' answer Expect.enter(connection, "y") # the question about user name comes now Expect.expect(connection, "Username with SSH access to %s and sudo privileges:" % cds.host_name) # if the execution reaches here, uesername question was already asked Expect.enter(connection, cds.user_name) Expect.expect(connection, "Absolute path to an SSH private key to log into %s as ec2-user:"******".*Cannot find file, please enter a valid path.*", re.DOTALL), 1), (PROCEED_PATTERN, 2) ]) if state == 1: # don't know how to continue with invalid path: raise Expect.enter(connection, CTRL_C) Expect.enter(connection, "q") raise InvalidSshKeyPath(cds.ssh_key_path) # all OK, confirm Expect.enter(connection, "y") # some installation and configuration through Puppet happens here, let it take its time RHUIManager.quit(connection, "The Content Delivery Server was successfully configured.", timeout=180)
def create_conf_rpm(connection, clustername, primary_cds, dirname, certpath, certkey, rpmname, rpmversion="", unprotected_repos=None): ''' create a client configuration RPM from an entitlement certificate ''' RHUIManager.screen(connection, "client") Expect.enter(connection, "c") Expect.expect(connection, "Full path to local directory.*:") Expect.enter(connection, dirname) Expect.expect(connection, "Name of the RPM:") Expect.enter(connection, rpmname) Expect.expect(connection, "Version of the configuration RPM.*:") Expect.enter(connection, rpmversion) Expect.expect(connection, "Full path to the entitlement certificate.*:") Expect.enter(connection, certpath) Expect.expect(connection, "Full path to the private key for the above entitlement certificate:") Expect.enter(connection, certkey) RHUIManager.select_one(connection, clustername) RHUIManager.select_one(connection, primary_cds) if unprotected_repos: RHUIManager.select(connection, unprotected_repos) RHUIManager.quit(connection, "Successfully created client configuration RPM")
def add_cds(connection, clustername, cdsname, hostname="", displayname=""): """ register (add) a new CDS instance """ RHUIManager.screen(connection, "cds") RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname) state = Expect.expect_list( connection, [ (re.compile(".*Enter a CDS cluster name:.*", re.DOTALL), 1), (re.compile(".*Select a CDS cluster or enter a new one:.*", re.DOTALL), 2), ], ) if state == 1: Expect.enter(connection, clustername) else: Expect.enter(connection, "b") Expect.expect(connection, "rhui \(cds\) =>") RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname) RHUIManagerCds._select_cluster(connection, clustername) # We need to compare the output before proceeding checklist = ["Hostname: " + cdsname] if hostname != "": checklist.append("Client Hostname: " + hostname) else: checklist.append("Client Hostname: " + cdsname) if displayname != "": checklist.append("Name: " + displayname) else: checklist.append("Name: " + cdsname) checklist.append("Cluster: " + clustername) RHUIManager.proceed_with_check(connection, "The following CDS instance will be registered:", checklist) RHUIManager.quit(connection, "Successfully registered")
def move_cds(connection, cdslist, clustername): """ move the CDSes to clustername """ RHUIManager.screen(connection, "cds") Expect.enter(connection, "m") RHUIManager.select(connection, cdslist) RHUIManagerCds._select_cluster(connection, clustername) RHUIManager.proceed_with_check( connection, "The following Content Delivery Servers will be moved to the %s cluster:\r\n.*-+" % clustername, cdslist, ) RHUIManager.quit(connection, "successfully moved CDS")
def add_cds(connection, clustername, cdsname, hostname="", displayname=""): ''' register (add) a new CDS instance ''' RHUIManager.screen(connection, "cds") RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname) state = Expect.expect_list(connection, [(re.compile(".*Enter a CDS cluster name:.*", re.DOTALL), 1), (re.compile(".*Select a CDS cluster or enter a new one:.*", re.DOTALL), 2)]) if state == 1: Expect.enter(connection, clustername) else: Expect.enter(connection, 'b') Expect.expect(connection, "rhui \(cds\) =>") RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname) RHUIManagerCds._select_cluster(connection, clustername) # We need to compare the output before proceeding checklist = ["Hostname: " + cdsname] if hostname != "": checklist.append("Client Hostname: " + hostname) else: checklist.append("Client Hostname: " + cdsname) if displayname != "": checklist.append("Name: " + displayname) else: checklist.append("Name: " + cdsname) checklist.append("Cluster: " + clustername) RHUIManager.proceed_with_check(connection, "The following CDS instance will be registered:", checklist) RHUIManager.quit(connection, "Successfully registered")
def generate_ent_cert(connection, clustername, repolist, certname, dirname, validity_days="", cert_pw=None): ''' generate an entitlement certificate ''' RHUIManager.screen(connection, "client") Expect.enter(connection, "e") RHUIManager.select_one(connection, clustername) RHUIManager.select(connection, repolist) Expect.expect(connection, "Name of the certificate.*contained with it:") Expect.enter(connection, certname) Expect.expect(connection, "Local directory in which to save the generated certificate.*:") Expect.enter(connection, dirname) Expect.expect(connection, "Number of days the certificate should be valid.*:") Expect.enter(connection, validity_days) RHUIManager.proceed_with_check(connection, "Repositories to be included in the entitlement certificate:", repolist, ["Custom Entitlements", "Red Hat Repositories"]) Expect.expect(connection, "Enter pass phrase for.*:") if cert_pw: Expect.enter(connection, cert_pw) else: Expect.enter(connection, Util.get_ca_password(connection)) RHUIManager.quit(connection)
def delete_cdses(connection, *cdses): ''' unregister (delete) CDS instance from the RHUI ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "d") RHUIManager.select_items(connection, *cdses) RHUIManager.quit(connection, timeout=30)
def sync_repo(connection, repolist): ''' sync an individual repository immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sr") Expect.expect(connection, "Select one or more repositories.*for more commands:", 60) Expect.enter(connection, "l") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check( connection, "The following repositories will be scheduled for synchronization:", repolist) RHUIManager.quit(connection)
def add_rh_repo_by_repo(connection, repolist): ''' add a new Red Hat content repository (By Repository) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 180) Expect.enter(connection, "3") RHUIManager.select(connection, repolist) repocheck = list(repolist) for repo in repolist: #adding repo titles to check list repotitle = re.sub(" \\\\\([^\(]*\\\\\)$", "", repo) if not repotitle in repocheck: repocheck.append(repotitle) RHUIManager.proceed_with_check(connection, "The following product repositories will be deployed:", repocheck) RHUIManager.quit(connection, "Content will not be downloaded", 45)
def add_rh_repo_all(connection): ''' add a new Red Hat content repository (All in Certificate) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 180) Expect.enter(connection, "1") RHUIManager.proceed_without_check(connection) RHUIManager.quit(connection, "Content will not be downloaded", 45)
def add_rh_repo_by_repo(connection, repolist): ''' add a new Red Hat content repository (By Repository) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 180) Expect.enter(connection, "3") RHUIManager.select(connection, repolist) repocheck = list(repolist) for repo in repolist: #adding repo titles to check list repotitle = re.sub(" \\\\\([^\(]*\\\\\)$", "", repo) if not repotitle in repocheck: repocheck.append(repotitle) RHUIManager.proceed_with_check( connection, "The following product repositories will be deployed:", repocheck) RHUIManager.quit(connection, "Content will not be downloaded", 45)
def upload_content_cert(connection, certpath): ''' upload a new or updated Red Hat content certificate ''' if certpath[:1] == '/': Expect.enter(connection, "mkdir -p `dirname " + certpath + "` && echo SUCCESS") Expect.expect(connection, "[^ ]SUCCESS") connection.sftp.put(certpath, certpath) RHUIManager.screen(connection, "entitlements") Expect.enter(connection, "u") Expect.expect(connection, "Full path to the new content certificate:") Expect.enter(connection, certpath) RHUIManager.proceed_with_check(connection, "The RHUI will be updated with the following certificate:", [certpath]) RHUIManager.quit(connection, "Red Hat Entitlements.*Valid.*------------------")
def upload_content_cert(connection, certpath): ''' upload a new or updated Red Hat content certificate ''' if certpath[:1] == '/': Expect.enter(connection, "mkdir -p `dirname " + certpath + "` && echo SUCCESS") Expect.expect(connection, "[^ ]SUCCESS") connection.sftp.put(certpath, certpath) RHUIManager.screen(connection, "entitlements") Expect.enter(connection, "u") Expect.expect(connection, "Full path to the new content certificate:") Expect.enter(connection, certpath) RHUIManager.proceed_with_check( connection, "The RHUI will be updated with the following certificate:", [certpath]) RHUIManager.quit(connection, "Red Hat Entitlements.*Valid.*------------------")
def add_custom_repo(connection, reponame, displayname="", path="", checksum_alg="2", entitlement="y", entitlement_path="", redhat_gpg="y", custom_gpg=None): ''' create a new custom repository ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "c") Expect.expect(connection, "Unique ID for the custom repository.*:") Expect.enter(connection, reponame) checklist = ["ID: " + reponame] Expect.expect(connection, "Display name for the custom repository.*:") Expect.enter(connection, displayname) if displayname != "": checklist.append("Name: " + displayname) else: checklist.append("Name: " + reponame) Expect.expect(connection, "Path at which the repository will be served.*:") Expect.enter(connection, path) if path != "": path_real = path else: path_real = reponame checklist.append("Path: " + path_real) Expect.expect(connection, "Enter value.*:") Expect.enter(connection, checksum_alg) Expect.expect( connection, "Should the repository require an entitlement certificate to access\? \(y/n\)" ) Expect.enter(connection, entitlement) if entitlement == "y": Expect.expect( connection, "Path that should be used when granting an entitlement for this repository.*:" ) Expect.enter(connection, entitlement_path) if entitlement_path != "": checklist.append("Entitlement: " + entitlement_path) else: educated_guess, replace_count = re.subn( "(i386|x86_64)", "$basearch", path_real) if replace_count > 1: # bug 815975 educated_guess = path_real checklist.append("Entitlement: " + educated_guess) Expect.expect(connection, "packages are signed by a GPG key\? \(y/n\)") if redhat_gpg == "y" or custom_gpg: Expect.enter(connection, "y") checklist.append("GPG Check Yes") Expect.expect( connection, "Will the repository be used to host any Red Hat GPG signed content\? \(y/n\)" ) Expect.enter(connection, redhat_gpg) if redhat_gpg == "y": checklist.append("Red Hat GPG Key: Yes") else: checklist.append("Red Hat GPG Key: No") Expect.expect( connection, "Will the repository be used to host any custom GPG signed content\? \(y/n\)" ) if custom_gpg: Expect.enter(connection, "y") Expect.expect( connection, "Enter the absolute path to the public key of the GPG keypair:" ) Expect.enter(connection, custom_gpg) Expect.expect( connection, "Would you like to enter another public key\? \(y/n\)") Expect.enter(connection, "n") checklist.append("Custom GPG Keys: '" + custom_gpg + "'") else: Expect.enter(connection, "n") checklist.append("Custom GPG Keys: \(None\)") else: Expect.enter(connection, "n") checklist.append("GPG Check No") checklist.append("Red Hat GPG Key: No") RHUIManager.proceed_with_check( connection, "The following repository will be created:", checklist) RHUIManager.quit(connection, "Successfully created repository")
def add_custom_repo(connection, reponame, displayname="", path="", checksum_alg="2", entitlement="y", entitlement_path="", redhat_gpg="y", custom_gpg=None): ''' create a new custom repository ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "c") Expect.expect(connection, "Unique ID for the custom repository.*:") Expect.enter(connection, reponame) checklist = ["ID: " + reponame] Expect.expect(connection, "Display name for the custom repository.*:") Expect.enter(connection, displayname) if displayname != "": checklist.append("Name: " + displayname) else: checklist.append("Name: " + reponame) Expect.expect(connection, "Path at which the repository will be served.*:") Expect.enter(connection, path) if path != "": path_real = path else: path_real = reponame checklist.append("Path: " + path_real) Expect.expect(connection, "Enter value.*:") Expect.enter(connection, checksum_alg) Expect.expect(connection, "Should the repository require an entitlement certificate to access\? \(y/n\)") Expect.enter(connection, entitlement) if entitlement == "y": Expect.expect(connection, "Path that should be used when granting an entitlement for this repository.*:") Expect.enter(connection, entitlement_path) if entitlement_path != "": checklist.append("Entitlement: " + entitlement_path) else: educated_guess, replace_count = re.subn("(i386|x86_64)", "$basearch", path_real) if replace_count > 1: # bug 815975 educated_guess = path_real checklist.append("Entitlement: " + educated_guess) Expect.expect(connection, "packages are signed by a GPG key\? \(y/n\)") if redhat_gpg == "y" or custom_gpg: Expect.enter(connection, "y") checklist.append("GPG Check Yes") Expect.expect(connection, "Will the repository be used to host any Red Hat GPG signed content\? \(y/n\)") Expect.enter(connection, redhat_gpg) if redhat_gpg == "y": checklist.append("Red Hat GPG Key: Yes") else: checklist.append("Red Hat GPG Key: No") Expect.expect(connection, "Will the repository be used to host any custom GPG signed content\? \(y/n\)") if custom_gpg: Expect.enter(connection, "y") Expect.expect(connection, "Enter the absolute path to the public key of the GPG keypair:") Expect.enter(connection, custom_gpg) Expect.expect(connection, "Would you like to enter another public key\? \(y/n\)") Expect.enter(connection, "n") checklist.append("Custom GPG Keys: '" + custom_gpg + "'") else: Expect.enter(connection, "n") checklist.append("Custom GPG Keys: \(None\)") else: Expect.enter(connection, "n") checklist.append("GPG Check No") checklist.append("Red Hat GPG Key: No") RHUIManager.proceed_with_check(connection, "The following repository will be created:", checklist) RHUIManager.quit(connection, "Successfully created repository")
def info(connection, clusterlist): ''' display detailed information on a CDS clusters @param clusterlist - list of clusters to examine @returns a list of Cds instances ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "i") RHUIManager.select(connection, clusterlist) pattern = re.compile('.*-= RHUI CDS Clusters =-(.*)rhui\s* \(cds\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] reslist = ret.split("\r\n") i = 0 clusterlist = [] cluster = {} while i < len(reslist): line = reslist[i] # Readling lines and searching for clusters if line.strip() != '': if line[:2] == ' ' and not line[2:3] in [' ', '-']: # We've found a new cluster! if cluster != {}: clusterlist.append(cluster) cluster = {} cluster['Name'] = line[2:] i += 2 while reslist[i][:4] == ' ' or reslist[i] == '': if reslist[i] == '': i += 1 continue line = reslist[i].strip() if line == "CDS Instances": # Figuring out cds instances instances = [] i += 2 while reslist[i].strip() != "": # New cds cds = reslist[i].strip() hostname = reslist[i + 1].strip().split(':')[1].strip() client = reslist[i + 2].strip().split(':')[1].strip() instances.append(RhuiCds(name=reslist[i].strip(), hostname=hostname, client_hostname=client, description='RHUI CDS', cluster=cluster['Name'])) i += 3 cluster['Instances'] = sorted(instances) elif line == "Repositories": # Figuring out repositories repositories = [] i += 2 while reslist[i].strip() != "": # New repo repo = reslist[i].strip() i += 1 if repo == '(None)': # no repos, continue with next (empty) # line continue repositories.append(repo) cluster['Repositories'] = repositories # update all cluster CDSes with appropriate repo # records for cds in cluster['Instances']: cds.repos = repositories break else: i += 1 i += 1 if cluster != {}: clusterlist.append(cluster) cdses = [] for cluster in clusterlist: cdses.extend(cluster['Instances']) Expect.enter(connection, 'q') return cdses
def info(connection, clusterlist): """ display detailed information on a CDS clusters @param clusterlist - list of clusters to examine @returns a list of Cds instances """ RHUIManager.screen(connection, "cds") Expect.enter(connection, "i") RHUIManager.select(connection, clusterlist) pattern = re.compile(".*-= RHUI CDS Clusters =-(.*)rhui\s* \(cds\)\s* =>", re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] reslist = ret.split("\r\n") i = 0 clusterlist = [] cluster = {} while i < len(reslist): line = reslist[i] # Readling lines and searching for clusters if line.strip() != "": if line[:2] == " " and not line[2:3] in [" ", "-"]: # We've found a new cluster! if cluster != {}: clusterlist.append(cluster) cluster = {} cluster["Name"] = line[2:] i += 2 while reslist[i][:4] == " " or reslist[i] == "": if reslist[i] == "": i += 1 continue line = reslist[i].strip() if line == "CDS Instances": # Figuring out cds instances instances = [] i += 2 while reslist[i].strip() != "": # New cds cds = reslist[i].strip() hostname = reslist[i + 1].strip().split(":")[1].strip() client = reslist[i + 2].strip().split(":")[1].strip() instances.append( RhuiCds( name=reslist[i].strip(), hostname=hostname, client_hostname=client, description="RHUI CDS", cluster=cluster["Name"], ) ) i += 3 cluster["Instances"] = sorted(instances) elif line == "Repositories": # Figuring out repositories repositories = [] i += 2 while reslist[i].strip() != "": # New repo repo = reslist[i].strip() i += 1 if repo == "(None)": # no repos, continue with next (empty) # line continue repositories.append(repo) cluster["Repositories"] = repositories # update all cluster CDSes with appropriate repo # records for cds in cluster["Instances"]: cds.repos = repositories break else: i += 1 i += 1 if cluster != {}: clusterlist.append(cluster) cdses = [] for cluster in clusterlist: cdses.extend(cluster["Instances"]) Expect.enter(connection, "q") return cdses