Пример #1
0
    def setup_config(self, config, force=0):
        # Figure out the log level
        debug_level = self.options.verbose
        if debug_level is None:
            debug_level = CFG.debug
        self.debug_level = debug_level
        logfile = self.options.logfile
        if logfile is None or logfile == '':
            logfile = CFG.log_file
        initLOG(level=debug_level, log_file=logfile)

        # Get the ssl cert
        ssl_cert = CFG.osa_ssl_cert
        try:
            self.check_cert(ssl_cert)
        except jabber_lib.InvalidCertError:
            e = sys.exc_info()[1]
            log_error("Invalid SSL certificate:", e)
            return 1

        self.ssl_cert = ssl_cert

        rhnSQL.initDB()

        self._username = '******'
        self._password = self.get_dispatcher_password(self._username)
        if not self._password:
            self._password = self.create_dispatcher_password(32)
        self._resource = 'superclient'
        js = config.get('jabber_server')
        self._jabber_servers = [ idn_ascii_to_puny(js) ]
Пример #2
0
    def setup_config(self, config, force=0):
        # Figure out the log level
        debug_level = self.options.verbose
        if debug_level is None:
            debug_level = CFG.debug
        self.debug_level = debug_level
        logfile = self.options.logfile
        if logfile is None or logfile == '':
            logfile = CFG.log_file
        initLOG(level=debug_level, log_file=logfile)

        # Get the ssl cert
        ssl_cert = CFG.osa_ssl_cert
        try:
            self.check_cert(ssl_cert)
        except jabber_lib.InvalidCertError:
            e = sys.exc_info()[1]
            log_error("Invalid SSL certificate:", e)
            return 1

        self.ssl_cert = ssl_cert

        rhnSQL.initDB()

        self._username = '******'
        self._password = self.get_dispatcher_password(self._username)
        if not self._password:
            self._password = self.create_dispatcher_password(32)
        self._resource = 'superclient'
        js = config.get('jabber_server')
        self._jabber_servers = [idn_ascii_to_puny(js)]
Пример #3
0
def getProxySetting():
    """ returns proxy string in format hostname:port
    hostname is converted to Punycode (RFC3492) if needed
    """
    cfg = initUp2dateConfig()
    proxy = None
    proxyHost = cfg["httpProxy"]

    if proxyHost:
        if proxyHost[:7] == "http://":
            proxyHost = proxyHost[7:]
        parts = proxyHost.split(':')
        parts[0] = str(idn_ascii_to_puny(parts[0]))
        proxy = ':'.join(parts)

    return proxy
Пример #4
0
def getProxySetting():
    """ returns proxy string in format hostname:port
    hostname is converted to Punycode (RFC3492) if needed
    """
    cfg = initUp2dateConfig()
    proxy = None
    proxyHost = cfg["httpProxy"]

    if proxyHost:
        if proxyHost[:7] == "http://":
            proxyHost = proxyHost[7:]
        parts = proxyHost.split(':')
        parts[0] = idn_ascii_to_puny(parts[0])
        proxy = ':'.join(parts)

    return proxy
Пример #5
0
    def setURL(self):
        server = sstr(idn_ascii_to_puny(self.options.server))
        if server is None:
            self.die(1, "Required parameter --server not supplied")
        scheme, netloc, path, params, query, fragment = tupleify_urlparse(
            urlparse.urlparse(server))
        if not netloc:
            # No schema - trying to patch it up ourselves?
            server = "http://%s" % server
            scheme, netloc, path, params, query, fragment = tupleify_urlparse(
                urlparse.urlparse(server))

        if not netloc:
            self.die(2, "Invalid URL %s" % server)
        if path == '':
            path = '/APP'
        if scheme.lower() not in ('http', 'https'):
            self.die(3, "Unknown URL scheme %s" % scheme)
        self.url = urlparse.urlunparse((scheme, netloc, path, params, query,
                                        fragment))
        self.url_v2 = urlparse.urlunparse((scheme, netloc, "/PACKAGE-PUSH",
                                           params, query, fragment))
Пример #6
0
    def setURL(self):
        server = sstr(idn_ascii_to_puny(self.options.server))
        if server is None:
            self.die(1, "Required parameter --server not supplied")
        scheme, netloc, path, params, query, fragment = tupleify_urlparse(
            urlparse.urlparse(server))
        if not netloc:
            # No schema - trying to patch it up ourselves?
            server = "http://%s" % server
            scheme, netloc, path, params, query, fragment = tupleify_urlparse(
                urlparse.urlparse(server))

        if not netloc:
            self.die(2, "Invalid URL %s" % server)
        if path == '':
            path = '/APP'
        if scheme.lower() not in ('http', 'https'):
            self.die(3, "Unknown URL scheme %s" % scheme)
        self.url = urlparse.urlunparse(
            (scheme, netloc, path, params, query, fragment))
        self.url_v2 = urlparse.urlunparse(
            (scheme, netloc, "/PACKAGE-PUSH", params, query, fragment))
Пример #7
0
class Runner(jabber_lib.Runner):
    client_factory = dispatcher_client.Client

    # We want the dispatcher to check in quite often in case the jabberd
    # connection drops
    _min_sleep = 10
    _max_sleep = 10

    def __init__(self):
        jabber_lib.Runner.__init__(self)
        initCFG("osa-dispatcher")
        self._tcp_server = None
        self._poll_interval = None
        self._next_poll_interval = None
        # Cache states
        self._state_ids = {}

    def read_config(self):
        ret = {
            'jabber_server' : CFG.jabber_server,
        }
        return ret

    _query_get_dispatcher_password = """
    select id, password
      from rhnPushDispatcher
     where jabber_id like :jabber_id
    """

    _update_dispatcher_password = """
    update rhnPushDispatcher
       set password = :password_in
     where id = :id_in
    """

    def get_dispatcher_password(self, username):
        h = rhnSQL.prepare(self._query_get_dispatcher_password)
        h.execute(jabber_id = username + "%")
        ret = h.fetchall_dict()

        if ret and len(ret) == 1:
            if ret[0]['password']:
                return ret[0]['password']
            else:
                # Upgrade Spacewalk 1.5 -> 1.6: the dispatcher row exists,
                # we just need to generate and save the password.
                self._password = self.create_dispatcher_password(32)
                u = rhnSQL.prepare(self._update_dispatcher_password)
                u.execute(password_in = self._password, id_in = ret[0]['id'])
                return self._password
        else:
            return None

    def create_dispatcher_password(self, length):
        chars = string.ascii_letters + string.digits
        return "".join(choice(chars) for x in range(length))

    def setup_config(self, config):
        # Figure out the log level
        debug_level = self.options.verbose
        if debug_level is None:
            debug_level = CFG.debug
        self.debug_level = debug_level
        initLOG(level=debug_level, log_file=CFG.log_file)

        # Get the ssl cert
        ssl_cert = CFG.osa_ssl_cert
        try:
            self.check_cert(ssl_cert)
        except jabber_lib.InvalidCertError, e:
            log_error("Invalid SSL certificate:", e)
            return 1

        self.ssl_cert = ssl_cert

        rhnSQL.initDB()

        self._username = '******'
        self._password = self.get_dispatcher_password(self._username)
        if not self._password:
            self._password = self.create_dispatcher_password(32)
        self._resource = 'superclient'
        js = config.get('jabber_server')
        self._jabber_servers = [ idn_ascii_to_puny(js) ]
Пример #8
0
def processCommandline():
    options = [
        Option('--sanity-only',
               action='store_true',
               help="confirm certificate sanity. Does not activate " +
               "the Red Hat Satellite locally or remotely."),
        Option('--ignore-expiration',
               action='store_true',
               help='execute regardless of the expiration ' +
               'of the RHN Certificate (not recommended).'),
        Option('--ignore-version-mismatch',
               action='store_true',
               help='execute regardless of version ' +
               'mismatch of existing and new certificate.'),
        Option('-v',
               '--verbose',
               action='count',
               help='be verbose ' +
               '(accumulable: -vvv means "be *really* verbose").'),
        Option('--dump-version',
               action='store',
               help="requested version of XML dump"),
        Option('--manifest',
               action='store',
               help='the RHSM manifest path/filename to activate for CDN'),
        Option('--rhn-cert',
               action='store',
               help='this option is deprecated, use --manifest instead'),
        Option('--deactivate',
               action='store_true',
               help='deactivate CDN-activated Satellite'),
        Option('--disconnected',
               action='store_true',
               help="activate locally, not subscribe to remote repository"),
        Option('--manifest-info',
               action='store_true',
               help="show information about currently activated manifest"),
        Option('--manifest-download',
               action='store_true',
               help="download new manifest from RHSM to temporary location"),
        Option('--manifest-refresh',
               action='store_true',
               help="download new manifest from RHSM and activate it"),
        Option('--manifest-reconcile-request',
               action='store_true',
               help="request regeneration of entitlement certificates")
    ]

    parser = OptionParser(option_list=options)
    options, args = parser.parse_args()

    initCFG('server.satellite')
    if options.verbose is None:
        options.verbose = 0
    CFG.set('DEBUG', options.verbose)
    rhnLog.initLOG(LOG_PATH, options.verbose)
    log2disk(0, "Command: %s" % str(sys.argv))

    # we take no extra commandline arguments that are not linked to an option
    if args:
        writeError(
            "These arguments make no sense in this context (try --help): %s" %
            repr(args))
        sys.exit(1)

    # No need to check further if deactivating
    if options.deactivate:
        return options

    if options.sanity_only:
        options.disconnected = 1

    if options.manifest_refresh:
        options.manifest_download = 1

    if CFG.DISCONNECTED and not options.disconnected:
        msg = """Satellite server has been setup to run in disconnected mode.
       Either correct server configuration in /etc/rhn/rhn.conf
       or use --disconnected to activate it locally."""
        writeError(msg)
        sys.exit(1)

    options.http_proxy = idn_ascii_to_puny(CFG.HTTP_PROXY)
    options.http_proxy_username = CFG.HTTP_PROXY_USERNAME
    options.http_proxy_password = CFG.HTTP_PROXY_PASSWORD
    log(1, 'HTTP_PROXY: %s' % options.http_proxy)
    log(1, 'HTTP_PROXY_USERNAME: %s' % options.http_proxy_username)
    log(1, 'HTTP_PROXY_PASSWORD: <password>')

    return options
Пример #9
0
def main():
    # Initialize a command-line processing object with a table of options
    optionsTable = [
        Option('-v', '--verbose', action='count', help='Increase verbosity',
               default=0),
        Option('-d', '--dir', action='store',
               help='Process packages from this directory'),
        Option('-c', '--channel', action='append',
               help='Manage this channel (specified by label)'),
        Option('-n', '--count', action='store',
               help='Process this number of headers per call', type='int'),
        Option('-l', '--list', action='store_true',
               help='Only list the specified channels'),
        Option('-r', '--reldir', action='store',
               help='Relative dir to associate with the file'),
        Option('-o', '--orgid', action='store',
               help='Org ID', type='int'),
        Option('-u', '--username', action='store',
               help='Use this username to connect to RHN/Satellite'),
        Option('-p', '--password', action='store',
               help='Use this password to connect to RHN/Satellite'),
        Option('-s', '--stdin', action='store_true',
               help='Read the package names from stdin'),
        Option('-X', '--exclude', action='append',
               help='Exclude packages that match this glob expression'),
        Option('--force', action='store_true',
               help='Force the package upload (overwrites if already uploaded)'),
        Option('--nosig', action='store_true', help='Push unsigned packages'),
        Option('--newest', action='store_true',
               help='Only push the packages that are newer than the server ones'),
        Option('--nullorg', action='store_true', help='Use the null org id'),
        Option('--header', action='store_true',
               help='Upload only the header(s)'),
        Option('--source', action='store_true',
               help='Upload source package information'),
        Option('--server', action='store',
               help='Push to this server (http[s]://<hostname>/APP)'),
        Option('--proxy', action='store',
               help='Use proxy server (<server>:<port>)'),
        Option('--test', action='store_true',
               help='Only print the packages to be pushed'),
        Option('-?', '--usage', action='store_true',
               help='Briefly describe the options'),
        Option('-N', '--new-cache', action='store_true',
               help='Create a new username/password cache'),
        Option('--extended-test', action='store_true',
               help='Perform a more verbose test'),
        Option('--no-session-caching', action='store_true',
               help='Disables session-token authentication.'),
        Option('--tolerant', action='store_true',
               help='If rhnpush errors while uploading a package, continue uploading the rest of the packages.'),
        Option('--ca-chain', action='store', help='alternative SSL CA Cert'),
        Option('--timeout', action='store', type='int', metavar='SECONDS',
               help='Change default connection timeout.')
    ]

    # Having to maintain a store_true list is ugly. I'm trying to get rid of this.
    true_list = ['usage', 'test', 'source', 'header', 'nullorg', 'newest',
                 'nosig', 'force', 'list', 'stdin', 'new_cache',
                 'extended_test', 'no_session_caching', 'tolerant']
    # pylint: disable=E1101,E1103
    optionParser = OptionParser(option_list=optionsTable, usage="%prog [OPTION] [<package>]")
    manager = rhnpush_confmanager.ConfManager(optionParser, true_list)
    options = manager.get_config()

    upload = UploadClass(options, files=options.files)

    if options.usage:
        optionParser.print_usage()
        sys.exit(0)

    if options.proxy:
        options.proxy = idn_ascii_to_puny(options.proxy)

    if options.list:
        if not options.channel:
            upload.die(1, "Must specify a channel for --list to work")
        upload.list()
        return

    if options.dir and not options.stdin:
        upload.directory()

    elif options.stdin and not options.dir:
        upload.readStdin()

    elif options.dir and options.stdin:
        upload.readStdin()
        upload.directory()

    if options.exclude:
        upload.filter_excludes()

    if options.newest:
        if not options.channel:
            upload.die(1, "Must specify a channel for --newest to work")

        upload.newest()

    if not upload.files:
        if upload.newest:
            print("No new files to upload; exiting")
        else:
            print("Nothing to do (try --help for more options)")
        sys.exit(0)

    if options.test:
        upload.test()
        return

    if options.extended_test:
        upload.extended_test()
        return

    if options.header:
        upload.uploadHeaders()
        return

    ret = upload.packages()
    if ret != 0:
        return 1
Пример #10
0
def convert_url_to_puny(url):
    """ returns url where hostname is converted to Punycode (RFC3492) """
    s = urlsplit(url)
    return sstr(
        urlunsplit((s[0], ustr(idn_ascii_to_puny(s[1])), s[2], s[3], s[4])))
Пример #11
0
def processCommandline():
    options = [
        Option('--systemid',
               action='store',
               help='(FOR TESTING ONLY) alternative systemid path/filename. ' +
               'The system default is used if not specified.'),
        Option('--rhn-cert',
               action='store',
               help='new RHN certificate path/filename (default is' +
               ' %s - the saved RHN cert).' % DEFAULT_RHN_CERT_LOCATION),
        Option('--no-ssl',
               action='store_true',
               help='(FOR TESTING ONLY) disables SSL'),
        Option('--sanity-only',
               action='store_true',
               help="confirm certificate sanity. Does not activate" +
               "the Red Hat Satellite locally or remotely."),
        Option('--ignore-expiration',
               action='store_true',
               help='execute regardless of the expiration' +
               'of the RHN Certificate (not recommended).'),
        Option('--ignore-version-mismatch',
               action='store_true',
               help='execute regardless of version ' +
               'mismatch of existing and new certificate.'),
        Option('-v',
               '--verbose',
               action='count',
               help='be verbose ' +
               '(accumulable: -vvv means "be *really* verbose").'),
        Option('--dump-version',
               action='store',
               help="requested version of XML dump"),
        Option('--manifest',
               action='store',
               help='the RHSM manifest path/filename to activate for CDN'),
    ]

    options, args = OptionParser(option_list=options).parse_args()

    # we take no extra commandline arguments that are not linked to an option
    if args:
        msg = "ERROR: these arguments make no sense in this context (try --help): %s\n" % repr(
            args)
        raise ValueError(msg)

    initCFG('server.satellite')

    # systemid
    if not options.systemid:
        options.systemid = DEFAULT_SYSTEMID_LOCATION
    options.systemid = fileutils.cleanupAbsPath(options.systemid)

    if not options.rhn_cert and not options.manifest:
        print "NOTE: using backup cert as default: %s" % DEFAULT_RHN_CERT_LOCATION
        options.rhn_cert = DEFAULT_RHN_CERT_LOCATION

    if options.manifest:
        if not cdn_activation:
            sys.stderr.write(
                "ERROR: Package spacewalk-backend-cdn has to be installed for using --manifest.\n"
            )
            sys.exit(1)
        cdn_manifest = Manifest(options.manifest)
        tmp_cert_path = cdn_manifest.get_certificate_path()
        if tmp_cert_path is not None:
            options.rhn_cert = tmp_cert_path

    options.rhn_cert = fileutils.cleanupAbsPath(options.rhn_cert)
    if not os.path.exists(options.rhn_cert):
        sys.stderr.write("ERROR: RHN Cert (%s) does not exist\n" %
                         options.rhn_cert)
        sys.exit(1)

    if not options.sanity_only and CFG.DISCONNECTED:
        sys.stderr.write(
            """ERROR: Satellite server has been setup to run in disconnected mode.
       Correct server configuration in /etc/rhn/rhn.conf.
""")
        sys.exit(1)

    options.server = ''
    if not options.sanity_only:
        if not CFG.RHN_PARENT:
            sys.stderr.write(
                "ERROR: rhn_parent is not set in /etc/rhn/rhn.conf\n")
            sys.exit(1)
        options.server = idn_ascii_to_puny(
            rhnLib.parseUrl(CFG.RHN_PARENT)[1].split(':')[0])
        print 'RHN_PARENT: %s' % options.server

    options.http_proxy = idn_ascii_to_puny(CFG.HTTP_PROXY)
    options.http_proxy_username = CFG.HTTP_PROXY_USERNAME
    options.http_proxy_password = CFG.HTTP_PROXY_PASSWORD
    options.ca_cert = CFG.CA_CHAIN
    if options.verbose:
        print 'HTTP_PROXY: %s' % options.http_proxy
        print 'HTTP_PROXY_USERNAME: %s' % options.http_proxy_username
        print 'HTTP_PROXY_PASSWORD: <password>'
        if not options.no_ssl:
            print 'CA_CERT: %s' % options.ca_cert

    return options
Пример #12
0
def convert_url_to_puny(url):
    """ returns url where hostname is converted to Punycode (RFC3492) """
    s = urlsplit(url)
    return urlunsplit((s[0], idn_ascii_to_puny(s[1]), s[2], s[3], s[4])).encode('utf-8')
def processCommandline():
    options = [
        Option('--systemid',     action='store',      help='(FOR TESTING ONLY) alternative systemid path/filename. '
               + 'The system default is used if not specified.'),
        Option('--rhn-cert',     action='store',      help='new RHN certificate path/filename (default is'
               + ' %s - the saved RHN cert).' % DEFAULT_RHN_CERT_LOCATION),
        Option('--no-ssl',       action='store_true', help='(FOR TESTING ONLY) disables SSL'),
        Option('--sanity-only',  action='store_true', help="confirm certificate sanity. Does not activate"
               + "the Red Hat Satellite locally or remotely."),
        Option('--disconnected', action='store_true', help="activate locally, but not on remote RHN servers,"),
        Option('--ignore-expiration', action='store_true', help='execute regardless of the expiration'
               + 'of the RHN Certificate (not recommended).'),
        Option('--ignore-version-mismatch', action='store_true', help='execute regardless of version '
               + 'mismatch of existing and new certificate.'),
        Option('-v', '--verbose', action='count',      help='be verbose '
               + '(accumulable: -vvv means "be *really* verbose").'),
        Option('--dump-version', action='store', help="requested version of XML dump"),
    ]

    options, args = OptionParser(option_list=options).parse_args()

    # we take no extra commandline arguments that are not linked to an option
    if args:
        msg = "ERROR: these arguments make no sense in this context (try --help): %s\n" % repr(args)
        raise ValueError(msg)

    initCFG('server.satellite')

    # systemid, rhn-cert
    if not options.systemid:
        options.systemid = DEFAULT_SYSTEMID_LOCATION
    options.systemid = fileutils.cleanupAbsPath(options.systemid)

    if not options.rhn_cert:
        print "NOTE: using backup cert as default: %s" % DEFAULT_RHN_CERT_LOCATION
        options.rhn_cert = DEFAULT_RHN_CERT_LOCATION
    options.rhn_cert = fileutils.cleanupAbsPath(options.rhn_cert)
    if not os.path.exists(options.rhn_cert):
        sys.stderr.write("ERROR: RHN Cert (%s) does not exist\n" % options.rhn_cert)
        sys.exit(1)

    if options.sanity_only:
        options.disconnected = 1

    if CFG.DISCONNECTED and not options.disconnected:
        sys.stderr.write("""ERROR: Satellite server has been setup to run in disconnected mode.
       Either correct server configuration in /etc/rhn/rhn.conf
       or use --disconnected to activate it locally.
""")
        sys.exit(1)

    options.server = ''
    if not options.disconnected:
        if not CFG.RHN_PARENT:
            sys.stderr.write("ERROR: rhn_parent is not set in /etc/rhn/rhn.conf\n")
            sys.exit(1)
        options.server = idn_ascii_to_puny(rhnLib.parseUrl(CFG.RHN_PARENT)[1].split(':')[0])
        print 'RHN_PARENT: %s' % options.server

    options.http_proxy = idn_ascii_to_puny(CFG.HTTP_PROXY)
    options.http_proxy_username = CFG.HTTP_PROXY_USERNAME
    options.http_proxy_password = CFG.HTTP_PROXY_PASSWORD
    options.ca_cert = CFG.CA_CHAIN
    if options.verbose:
        print 'HTTP_PROXY: %s' % options.http_proxy
        print 'HTTP_PROXY_USERNAME: %s' % options.http_proxy_username
        print 'HTTP_PROXY_PASSWORD: <password>'
        if not options.no_ssl:
            print 'CA_CERT: %s' % options.ca_cert

    return options
Пример #14
0
def main():
    # Initialize a command-line processing object with a table of options
    optionsTable = [
        Option('-v',
               '--verbose',
               action='count',
               help='Increase verbosity',
               default=0),
        Option('-d',
               '--dir',
               action='store',
               help='Process packages from this directory'),
        Option('-c',
               '--channel',
               action='append',
               help='Manage this channel (specified by label)'),
        Option('-n',
               '--count',
               action='store',
               help='Process this number of headers per call',
               type='int'),
        Option('-l',
               '--list',
               action='store_true',
               help='Only list the specified channels'),
        Option('-r',
               '--reldir',
               action='store',
               help='Relative dir to associate with the file'),
        Option('-o', '--orgid', action='store', help='Org ID', type='int'),
        Option('-u',
               '--username',
               action='store',
               help='Use this username to connect to RHN/Satellite'),
        Option('-p',
               '--password',
               action='store',
               help='Use this password to connect to RHN/Satellite'),
        Option('-s',
               '--stdin',
               action='store_true',
               help='Read the package names from stdin'),
        Option('-X',
               '--exclude',
               action='append',
               help='Exclude packages that match this glob expression'),
        Option(
            '--force',
            action='store_true',
            help='Force the package upload (overwrites if already uploaded)'),
        Option('--nosig', action='store_true', help='Push unsigned packages'),
        Option(
            '--newest',
            action='store_true',
            help='Only push the packages that are newer than the server ones'),
        Option('--nullorg', action='store_true', help='Use the null org id'),
        Option('--header',
               action='store_true',
               help='Upload only the header(s)'),
        Option('--source',
               action='store_true',
               help='Upload source package information'),
        Option('--server',
               action='store',
               help='Push to this server (http[s]://<hostname>/APP)'),
        Option('--proxy',
               action='store',
               help='Use proxy server (<server>:<port>)'),
        Option('--test',
               action='store_true',
               help='Only print the packages to be pushed'),
        Option('-?',
               '--usage',
               action='store_true',
               help='Briefly describe the options'),
        Option('-N',
               '--new-cache',
               action='store_true',
               help='Create a new username/password cache'),
        Option('--extended-test',
               action='store_true',
               help='Perform a more verbose test'),
        Option('--no-session-caching',
               action='store_true',
               help='Disables session-token authentication.'),
        Option(
            '--tolerant',
            action='store_true',
            help=
            'If rhnpush errors while uploading a package, continue uploading the rest of the packages.'
        ),
        Option('--ca-chain', action='store', help='alternative SSL CA Cert'),
        Option('--timeout',
               action='store',
               type='int',
               metavar='SECONDS',
               help='Change default connection timeout.')
    ]

    # Having to maintain a store_true list is ugly. I'm trying to get rid of this.
    true_list = [
        'usage', 'test', 'source', 'header', 'nullorg', 'newest', 'nosig',
        'force', 'list', 'stdin', 'new_cache', 'extended_test',
        'no_session_caching', 'tolerant'
    ]
    # pylint: disable=E1101,E1103
    optionParser = OptionParser(option_list=optionsTable,
                                usage="%prog [OPTION] [<package>]")
    manager = rhnpush_confmanager.ConfManager(optionParser, true_list)
    options = manager.get_config()

    upload = UploadClass(options, files=options.files)

    if options.usage:
        optionParser.print_usage()
        sys.exit(0)

    if options.proxy:
        options.proxy = idn_ascii_to_puny(options.proxy)

    if options.list:
        if not options.channel:
            upload.die(1, "Must specify a channel for --list to work")
        upload.list()
        return

    if options.dir and not options.stdin:
        upload.directory()

    elif options.stdin and not options.dir:
        upload.readStdin()

    elif options.dir and options.stdin:
        upload.readStdin()
        upload.directory()

    if options.exclude:
        upload.filter_excludes()

    if options.newest:
        if not options.channel:
            upload.die(1, "Must specify a channel for --newest to work")

        upload.newest()

    if not upload.files:
        if upload.newest:
            print("No new files to upload; exiting")
        else:
            print("Nothing to do (try --help for more options)")
        sys.exit(0)

    if options.test:
        upload.test()
        return

    if options.extended_test:
        upload.extended_test()
        return

    if options.header:
        upload.uploadHeaders()
        return

    ret = upload.packages()
    if ret != 0:
        return 1
Пример #15
0
def processCommandline():
    options = [
        Option('--sanity-only',  action='store_true', help="confirm certificate sanity. Does not activate "
               + "the Red Hat Satellite locally or remotely."),
        Option('--ignore-expiration', action='store_true', help='execute regardless of the expiration '
               + 'of the RHN Certificate (not recommended).'),
        Option('--ignore-version-mismatch', action='store_true', help='execute regardless of version '
               + 'mismatch of existing and new certificate.'),
        Option('-v', '--verbose', action='count',      help='be verbose '
               + '(accumulable: -vvv means "be *really* verbose").'),
        Option('--dump-version', action='store', help="requested version of XML dump"),
        Option('--manifest',     action='store',      help='the RHSM manifest path/filename to activate for CDN'),
        Option('--rhn-cert', action='store', help='this option is deprecated, use --manifest instead'),
        Option('--deactivate', action='store_true', help='deactivate CDN-activated Satellite'),
        Option('--disconnected', action='store_true', help="activate locally, not subscribe to remote repository"),
        Option('--manifest-info', action='store_true', help="show information about currently activated manifest"),
        Option('--manifest-download', action='store_true',
               help="download new manifest from RHSM to temporary location"),
        Option('--manifest-refresh', action='store_true', help="download new manifest from RHSM and activate it"),
        Option('--manifest-reconcile-request', action='store_true',
               help="request regeneration of entitlement certificates")
    ]

    parser = OptionParser(option_list=options)
    options, args = parser.parse_args()

    initCFG('server.satellite')
    if options.verbose is None:
        options.verbose = 0
    CFG.set('DEBUG', options.verbose)
    rhnLog.initLOG(LOG_PATH, options.verbose)
    log2disk(0, "Command: %s" % str(sys.argv))

    # we take no extra commandline arguments that are not linked to an option
    if args:
        writeError("These arguments make no sense in this context (try --help): %s" % repr(args))
        sys.exit(1)

    # No need to check further if deactivating
    if options.deactivate:
        return options

    if options.sanity_only:
        options.disconnected = 1

    if options.manifest_refresh:
        options.manifest_download = 1

    if CFG.DISCONNECTED and not options.disconnected:
        msg = """Satellite server has been setup to run in disconnected mode.
       Either correct server configuration in /etc/rhn/rhn.conf
       or use --disconnected to activate it locally."""
        writeError(msg)
        sys.exit(1)

    options.http_proxy = idn_ascii_to_puny(CFG.HTTP_PROXY)
    options.http_proxy_username = CFG.HTTP_PROXY_USERNAME
    options.http_proxy_password = CFG.HTTP_PROXY_PASSWORD
    log(1, 'HTTP_PROXY: %s' % options.http_proxy)
    log(1, 'HTTP_PROXY_USERNAME: %s' % options.http_proxy_username)
    log(1, 'HTTP_PROXY_PASSWORD: <password>')

    return options