Created
October 26, 2017 15:44
-
-
Save dav1x/6bdf2d5c49d2f62b69b1c782d05d9f6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: sw=4 ts=4 et | |
# Davis Phillips [email protected] | |
# All all OCP imagestreams from registry.access.redhat.com to local sat6 installation | |
import os, argparse, socket, getpass, subprocess | |
class ocpSat6(object): | |
__name__ = 'ocpSat6' | |
openshift3Images=['openshift3/ose-deployer','openshift3/ose-docker-registry','openshift3/registry-console','openshift3/ose-pod','openshift3/ose-docker-builder','openshift3/ose-sti-builder','openshift3/ose-haproxy-router','openshift3/logging-elasticsearch','openshift3/logging-kibana','openshift3/logging-fluentd','openshift3/logging-auth-proxy','openshift3/metrics-hawkular-metrics','openshift3/metrics-cassandra','openshift3/metrics-heapster','openshift3/ose','openshift3/node','openshift3/openvswitch','rhel7/etcd','openshift3/ose-keepalived-ipfailover'] | |
xpaasImages=['redhat-openjdk-18/openjdk18-openshift', 'jboss-webserver-3/webserver30-tomcat8-openshift', 'jboss-eap-7/eap70-openshift','redhat-sso-7/sso70-openshift','rhscl/postgresql-95-rhel7','rhscl/nodejs-4-rhel7','rhscl/nodejs-6-rhel7','rhscl/python-27-rhel7','rhscl/python-35-rhel7'] | |
jenkinsImages=['openshift3/jenkins-2-rhel7', 'openshift3/jenkins-slave-base-rhel7', 'openshift3/jenkins-slave-maven-rhel7', 'openshift3/jenkins-slave-nodejs-rhel7'] | |
def __init__(self, load=True): | |
if load: | |
self._parseCli() | |
self._addData() | |
self._syncData() | |
def _parseCli(self): | |
parser = argparse.ArgumentParser(description='Add all OCP images for disconnected installation to satellite 6', add_help=True) | |
parser.add_argument('--orgid', action='store', default='1',help='Satellite organization ID to create new product for OCP images in') | |
parser.add_argument('--productname', action='store', default='OCP3',help='Satellite product name to use to create OCP images') | |
parser.add_argument('--password', action='store', help='Password for hammer CLI') | |
self.args = parser.parse_args() | |
if not self.args.password: | |
self.args.password = getpass.getpass(prompt='Please enter the password to use for the admin account in hammer CLI: ') | |
def _syncData(self): | |
print "Sync repo data? (This may take a while)" | |
go = raw_input("Continue? y/n:\n") | |
if 'y' not in go: | |
exit(0) | |
cmd="hammer --password %s product synchronize --name %s --organization-id %s" % (self.args.password, self.args.productname, self.args.orgid) | |
os.system(cmd) | |
def _addData(self): | |
print "Adding OCP images to org ID: %s with the product name: %s" % (self.args.orgid, self.args.productname) | |
go = raw_input("Continue? y/n:\n") | |
if 'y' not in go: | |
exit(0) | |
print "Adding product with name: %s" % self.args.productname | |
cmd="hammer --password %s product create --name %s --organization-id %s" % (self.args.password, self.args.productname, self.args.orgid) | |
os.system(cmd) | |
print "Adding openshift3 images" | |
for image in self.openshift3Images: | |
cmd='hammer --password %s repository create --name %s --organization-id %s --content-type docker --url "https://registry.access.redhat.com" --docker-upstream-name %s --product %s' % ( self.args.password, image, self.args.orgid, image, self.args.productname ) | |
os.system(cmd) | |
print "Adding xpaas images" | |
for image in self.xpaasImages: | |
cmd='hammer --password %s repository create --name %s --organization-id %s --content-type docker --url "https://registry.access.redhat.com" --docker-upstream-name %s --product %s' % ( self.args.password, image, self.args.orgid, image, self.args.productname ) | |
os.system(cmd) | |
print "Adding Jenkins images" | |
for image in self.jenkinsImages: | |
cmd='hammer --password %s repository create --name %s --organization-id %s --content-type docker --url "https://registry.access.redhat.com" --docker-upstream-name %s --product %s' % ( self.args.password, image, self.args.orgid, image, self.args.productname ) | |
os.system(cmd) | |
print "The following vars should exist in your OpenShift install playbook" | |
cmd="hammer --password %s organization list" % self.args.password | |
result = subprocess.check_output(cmd, shell=True) | |
lines = result.splitlines() | |
for line in lines: | |
if self.args.orgid in line: | |
orgLabel = line.split("|")[2] | |
hostname = socket.getfqdn() | |
oreg_url = "%s:5000/%s-%s-openshift3_ose-${component}:${version}" % ( hostname, orgLabel, self.args.productname ) | |
print "oreg_url: %s" % ( oreg_url.replace(" ", "")) | |
print 'openshift_disable_check: "docker_image_availability"' | |
print 'openshift_docker_insecure_registries: "%s:5000"' % hostname | |
print 'openshift_docker_additional_registries: "%s:5000"' % hostname | |
print "openshift_examples_modify_imagestreams: True" | |
if __name__ == '__main__': | |
ocpSat6() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment