diff --git a/README.md b/README.md index 3ea338a..85a9571 100644 --- a/README.md +++ b/README.md @@ -114,13 +114,10 @@ for import sync, however this behaviour can be overridden with the (-r) flag. Th will be useful to periodically ensure that the disconnected satellite repos are consistent - the repodata will indicate mismatches with synced content. -To export a selected repository set, a config file must exist in the config directory. -The name of the config file is the 'environment' that the configuration applies to. -This is useful if you have a development and production disconnected Satellite and -don't want to export the full DOV to the development environment. In this case -we will name the config file DEVELOPMENT.yml and its contents will look like the -example below. Repository names are the LABEL taken from the Satellite server and -must maintain the YAML array formatting. +To export a selected repository set, the exports.yml config file must exist in the +config directory. The format of this file is shown below, and contains one or more +'env' stanzas, containing a list of repositories to export. The repository name is +the LABEL taken from the Satellite server. Note also that the 'environment' export option also allows for the export of ISO (file) based repositories in addition to yum RPM content. Using the DOV export does @@ -129,15 +126,28 @@ the current pulp version in Satellite. The 'environment' export performs some additional magic to export the file content. ``` -env: - name: DEVELOPMENT - repos: [ - Red_Hat_Enterprise_Linux_7_Server_RPMs_x86_64_7Server, - Red_Hat_Enterprise_Linux_7_Server_-_Extras_RPMs_x86_64, - Red_Hat_Enterprise_Linux_7_Server_-_RH_Common_RPMs_x86_64_7Server, - Red_Hat_Enterprise_Linux_7_Server_ISOs_x86_64_7Server, - ] +exports: + env1: + name: DEVELOPMENT + repos: + - Red_Hat_Satellite_6_2_for_RHEL_7_Server_RPMs_x86_64 + - Red_Hat_Satellite_Tools_6_2_for_RHEL_7_Server_RPMs_x86_64 + - Red_Hat_Enterprise_Linux_7_Server_Kickstart_x86_64_7_3 + - Red_Hat_Enterprise_Linux_7_Server_RPMs_x86_64_7Server + - Red_Hat_Enterprise_Linux_7_Server_-_Extras_RPMs_x86_64 + - Red_Hat_Enterprise_Linux_7_Server_-_Optional_RPMs_x86_64_7Server + - Red_Hat_Enterprise_Linux_7_Server_-_RH_Common_RPMs_x86_64_7Server + - Red_Hat_Software_Collections_RPMs_for_Red_Hat_Enterprise_Linux_7_Server_x86_64_7Server + - Red_Hat_Enterprise_Linux_7_Server_ISOs_x86_64_7Server + - epel-7-x86_64 + + env2: + name: TEST + repos: + - Red_Hat_Satellite_Tools_6_2_for_RHEL_6_Server_RPMs_x86_64 + - Red_Hat_Satellite_6_2_for_RHEL_7_Server_RPMs_x86_64 ``` + To export in this manner the '-e DEVELOPMENT' option must be used. Exports to the 'environment' will be timestamped in the same way that DOV exports are done, so ongoing incremental exports are possible. @@ -151,7 +161,7 @@ Performs Export of Default Content View. optional arguments: -h, --help show this help message and exit -o ORG, --org ORG Organization (Uses default if not specified) - -e ENV, --env ENV Environment config file + -e ENV, --env ENV Environment config -a, --all Export ALL content -i, --incr Incremental Export of content since last run -s SINCE, --since SINCE @@ -164,9 +174,9 @@ optional arguments: ### Examples ``` -./sat_export.py -e DEV # Incr export of repos defined in DEV.yml +./sat_export.py -e DEV # Incr export of repos defined in the DEV config ./sat_export.py -o AnotherOrg # Incr export of DoV for a different org -./sat_export.py -e DEV -a # Full export of repos defined in DEV.yml +./sat_export.py -e DEV -a # Full export of repos defined in the DEV config Output file format will be: sat_export_2016-07-29_DEV_00 diff --git a/config/EXAMPLE.yml.example b/config/EXAMPLE.yml.example deleted file mode 100644 index 604352e..0000000 --- a/config/EXAMPLE.yml.example +++ /dev/null @@ -1,7 +0,0 @@ -env: - name: EXAMPLE - repos: [ - Red_Hat_Enterprise_Linux_7_Server_RPMs_x86_64_7Server, - Red_Hat_Enterprise_Linux_7_Server_-_Extras_RPMs_x86_64, - Red_Hat_Enterprise_Linux_7_Server_-_RH_Common_RPMs_x86_64_7Server, - ] diff --git a/config/exports.yml.example b/config/exports.yml.example new file mode 100644 index 0000000..1d88798 --- /dev/null +++ b/config/exports.yml.example @@ -0,0 +1,21 @@ +exports: + env1: + name: SAT1 + repos: + - Red_Hat_Satellite_6_2_for_RHEL_7_Server_RPMs_x86_64 + - Red_Hat_Satellite_Tools_6_2_for_RHEL_7_Server_RPMs_x86_64 + - Red_Hat_Enterprise_Linux_7_Server_Kickstart_x86_64_7_3 + - Red_Hat_Enterprise_Linux_7_Server_RPMs_x86_64_7Server + - Red_Hat_Enterprise_Linux_7_Server_-_Extras_RPMs_x86_64 + - Red_Hat_Enterprise_Linux_7_Server_-_Optional_RPMs_x86_64_7Server + - Red_Hat_Enterprise_Linux_7_Server_-_RH_Common_RPMs_x86_64_7Server + - Red_Hat_Software_Collections_RPMs_for_Red_Hat_Enterprise_Linux_7_Server_x86_64_7Server + - Red_Hat_Enterprise_Linux_7_Server_ISOs_x86_64_7Server + - epel-7-x86_64 + + env2: + name: TEST + repos: + - Red_Hat_Satellite_Tools_6_2_for_RHEL_6_Server_RPMs_x86_64 + - Red_Hat_Satellite_6_2_for_RHEL_7_Server_RPMs_x86_64 + diff --git a/sat_export.py b/sat_export.py index f037a24..aee35fa 100755 --- a/sat_export.py +++ b/sat_export.py @@ -517,10 +517,7 @@ def main(args): global vardir dir = os.path.dirname(__file__) vardir = os.path.join(dir, 'var') - - # Log the fact we are starting - msg = "------------- Content export started by " + runuser + " ----------------" - helpers.log_msg(msg, 'INFO') + confdir = os.path.join(dir, 'config') # Check for sane input parser = argparse.ArgumentParser(description='Performs Export of Default Content View.') @@ -528,7 +525,7 @@ def main(args): # pylint: disable=bad-continuation parser.add_argument('-o', '--org', help='Organization (Uses default if not specified)', required=False) - parser.add_argument('-e', '--env', help='Environment config file', required=False) + parser.add_argument('-e', '--env', help='Environment config', required=False) group.add_argument('-a', '--all', help='Export ALL content', required=False, action="store_true") group.add_argument('-i', '--incr', help='Incremental Export of content since last run', @@ -557,14 +554,27 @@ def main(args): org_id = helpers.get_org_id(org_name) exported_repos = [] # If a specific environment is requested, find and read that config file - repocfg = os.path.join(dir, 'config/' + args.env + '.yml') + repocfg = os.path.join(dir, confdir + '/exports.yml') if args.env: if not os.path.exists(repocfg): - print "ERROR: Config file " + repocfg + " not found." + msg = 'Config file ' + confdir + '/exports.yml not found.' + helpers.log_msg(msg, 'ERROR') sys.exit(-1) + cfg = yaml.safe_load(open(repocfg, 'r')) ename = args.env - erepos = cfg["env"]["repos"] + erepos = [] + validrepo = False + for x in cfg['exports']: + if cfg['exports'][x]['name'] == ename: + validrepo = True + erepos = cfg['exports'][x]['repos'] + + if not validrepo: + msg = 'Unable to find export config for ' + ename + helpers.log_msg(msg, 'ERROR') + sys.exit(-1) + msg = "Specific environment export called for " + ename + ". Configured repos:" helpers.log_msg(msg, 'DEBUG') for repo in erepos: @@ -577,6 +587,11 @@ def main(args): msg = "DoV export called" helpers.log_msg(msg, 'DEBUG') + # Log the fact we are starting + msg = "------------- Content export started by " + runuser + " ----------------" + if not args.last: + helpers.log_msg(msg, 'INFO') + # Get the current time - this will be the 'last export' time if the export is OK start_time = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') print "START: " + start_time + " (" + ename + " export)"