Skip to content

Commit

Permalink
Cleanup export config definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggatward committed Dec 7, 2016
1 parent 04fdcee commit 0339ba4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions config/EXAMPLE.yml.example

This file was deleted.

21 changes: 21 additions & 0 deletions config/exports.yml.example
Original file line number Diff line number Diff line change
@@ -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

31 changes: 23 additions & 8 deletions sat_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,15 @@ 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.')
group = parser.add_mutually_exclusive_group()
# 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',
Expand Down Expand Up @@ -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:
Expand All @@ -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)"
Expand Down

0 comments on commit 0339ba4

Please sign in to comment.