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 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 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 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 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 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 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 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 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 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 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 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 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 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 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_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 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 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 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