예제 #1
0
    def doRESOLVEURL(self, headers, body):

        spacewalk_auth_headers = ['X-RHN-Server-Id',
                                  'X-RHN-Auth-User-Id',
                                  'X-RHN-Auth',
                                  'X-RHN-Auth-Server-Time',
                                  'X-RHN-Auth-Expire-Offset']

        if not os.geteuid() == 0:
            # you can't access auth data if you are not root
            self.answer("ERROR", {}, "Can't access managed repositores without root access")
            return


        if not headers.has_key('channel'):
            self.answer("ERROR", {}, "Missing argument channel")
            return

        if headers.has_key('server'):
            server = int(headers['server'])
        else:
            server = 0

        # do we have spacewalk-client-tools with timeout option?
        args = getargspec(rhnChannel.getChannelDetails)[0]
        timeout = self._getTimeout()
        if 'timeout' in args:
            details = rhnChannel.getChannelDetails(timeout=timeout)
        else:
            details = rhnChannel.getChannelDetails();

	self.channel = None
        for channel in details:
            if channel['label'] == headers['channel']:
                self.channel = channel
        if not self.channel:
            self.answer("ERROR", {}, "Can't retrieve information for channel %s" % headers['channel'])
            return

        self.auth_headers = {}
        if 'timeout' in args:
            login_info = up2dateAuth.getLoginInfo(timeout=timeout)
        else:
            login_info = up2dateAuth.getLoginInfo()
	for k,v in login_info.items():
	    if k in spacewalk_auth_headers:
		self.auth_headers[k] = v
	#self.answer("META", li)

	# url is a list, use the one provided by the given server
	if type(self.channel['url']) == type([]):
	    self.channel['url'] = self.channel['url'][server]
        timeoutstr = ""
        if timeout:
            timeoutstr = "&timeout=%d" % timeout
        url = "%s/GET-REQ/%s?head_requests=no%s" % (self.channel['url'],
                                                    self.channel['label'],
                                                    timeoutstr)

        self.answer("RESOLVEDURL", self.auth_headers, url)
    def doRESOLVEURL(self, headers, body):

        spacewalk_auth_headers = ['X-RHN-Server-Id',
                                  'X-RHN-Auth-User-Id',
                                  'X-RHN-Auth',
                                  'X-RHN-Auth-Server-Time',
                                  'X-RHN-Auth-Expire-Offset']

        if not os.geteuid() == 0:
            # you can't access auth data if you are not root
            self.answer("ERROR", {}, "Can't access managed repositores without root access")
            return


        if not headers.has_key('channel'):
            self.answer("ERROR", {}, "Missing argument channel")
            return

        # do we have spacewalk-client-tools with timeout option?
        args = getargspec(rhnChannel.getChannelDetails)[0]
        timeout = self._getTimeout()
        if 'timeout' in args:
            details = rhnChannel.getChannelDetails(timeout=timeout)
        else:
            details = rhnChannel.getChannelDetails();

	self.channel = None
        for channel in details:
            if channel['label'] == headers['channel']:
                self.channel = channel
        if not self.channel:
            self.answer("ERROR", {}, "Can't retrieve information for channel %s" % headers['channel'])
            return

        self.auth_headers = {}
        if 'timeout' in args:
            login_info = up2dateAuth.getLoginInfo(timeout=timeout)
        else:
            login_info = up2dateAuth.getLoginInfo()
	for k,v in login_info.items():
	    if k in spacewalk_auth_headers:
		self.auth_headers[k] = v
	#self.answer("META", li)

	# url might be a list type, we use the 1st one
	if type(self.channel['url']) == type([]):
	    self.channel['url'] = self.channel['url'][0]
        timeoutstr = ""
        if timeout:
            timeoutstr = "&timeout=%d" % timeout
        url = "%s/GET-REQ/%s?head_requests=no%s" % (self.channel['url'],
                                                    self.channel['label'],
                                                    timeoutstr)

        self.answer("RESOLVEDURL", self.auth_headers, url)
예제 #3
0
 def testGetChannelDetails(self):
     "rhnChannel.GetChannelDetails"
     res = rhnChannel.getChannelDetails()
     # since most of the values are host-specific, we'll just test
     # that we have the right keys
     self.assertEqual(sorted(res[0].dict.keys()),
                      sorted(self.channelListDetails))
예제 #4
0
 def testGetChannelDetails(self):
     "rhnChannel.GetChannelDetails"
     res = rhnChannel.getChannelDetails()
     # since most of the values are host-specific, we'll just test
     # that we have the right keys
     self.assertEqual(sorted(res[0].dict.keys()),
                      sorted(self.channelListDetails))
예제 #5
0
def get_channels():
    """Return channels associated with a machine"""
    try:
        channels = []
        for channel in rhnChannel.getChannelDetails():
            channels.append(channel['label'])
        return channels
    except up2dateErrors.Error:
        return []
예제 #6
0
def get_channels():
    """Return channels associated with a machine"""
    try:
        channels = []
        for channel in rhnChannel.getChannelDetails():
            channels.append(channel['label'])
        return channels
    except up2dateErrors.Error:
        return []
예제 #7
0
 def testGetChannelDetails(self):
     "rhnChannel.GetChannelDetails"
     res = rhnChannel.getChannelDetails()
     # the last modified will change a lot, so
     # dont bother checking it...
     write(res)
     write(self.channelListDetails)
     for i in res[0].keys():
         if i == "last_modified":
             continue
         self.assertEqual(res[0][i], self.channelListDetails[0][i])
 def testGetChannelDetails(self):
     "rhnChannel.GetChannelDetails"
     res = rhnChannel.getChannelDetails()
     # the last modified will change a lot, so
     # dont bother checking it...
     write(res)
     write(self.channelListDetails)
     for i in res[0].keys():
         if i == "last_modified":
             continue
         self.assertEqual(res[0][i], self.channelListDetails[0][i])
    def doRESOLVEURL(self, headers, body):

        spacewalk_auth_headers = ['X-RHN-Server-Id',
                                  'X-RHN-Auth-User-Id',
                                  'X-RHN-Auth',
                                  'X-RHN-Auth-Server-Time',
                                  'X-RHN-Auth-Expire-Offset']

        if not os.geteuid() == 0:
            # you can't access auth data if you are not root
            self.answer("ERROR", {}, "Can't access managed repositores without root access")
            return


        if not headers.has_key('channel'):
            self.answer("ERROR", {}, "Missing argument channel")
            return

	details = rhnChannel.getChannelDetails();

	self.channel = None
        for channel in details:
            if channel['label'] == headers['channel']:
                self.channel = channel
        if not self.channel:
            self.answer("ERROR", {}, "Can't retrieve information for channel %s" % headers['channel'])
            return

        self.auth_headers = {}
	login_info = up2dateAuth.getLoginInfo()
	for k,v in login_info.items():
	    if k in spacewalk_auth_headers:
		self.auth_headers[k] = v
	#self.answer("META", li)

	# url might be a list type, we use the 1st one
	if type(self.channel['url']) == type([]):
	    self.channel['url'] = self.channel['url'][0]
        url = "%s/GET-REQ/%s?head_requests=no" % (self.channel['url'], self.channel['label'])

        self.answer("RESOLVEDURL", self.auth_headers, url)
예제 #10
0
파일: rhndb.py 프로젝트: devzero2000/pyrpm
class RhnRepoDB(JointDB):

    def __init__(self, config, source, buildroot='', nc=None):
        JointDB.__init__(self, config, source, buildroot)
        self.comps = None
        self.reponame = "rhnrepo"
        if not use_rhn:
            return
        up2date_cfg = rhnconfig.initUp2dateConfig()
        try:
            login_info = up2dateAuth.getLoginInfo()
        except up2dateErrors.RhnServerException, e:
            raise IOError, "Failed to get login info from RHN Server."
        try:
            svrChannels = rhnChannel.getChannelDetails()
        except up2dateErrors.NoChannelsError:
            raise IOError, "Failed to get channels from RHN Server."
        sslcacert = up2date_cfg['sslCACert']
        for channel in svrChannels: 
            rcdb = RhnChannelRepoDB(config, (channel['url']+'/GET-REQ/'+channel['label'], ), buildroot, channel['label'], nc)
            self.addDB(rcdb)
sys.stdout = sys.stderr

try:
    sys.path.append("/usr/share/rhn/")
    from up2date_client import rhnChannel
    from up2date_client import up2dateErrors
    try:
        from up2date_client.rhncli import utf8_encode
    except ImportError:
        from rhn.i18n import sstr as utf8_encode
except:
    sys.stderr.write("%sPlease install package spacewalk-backend-libs.\n" % traceback.format_exc())
    sys.exit(1)

try:
    svrChannels = rhnChannel.getChannelDetails()
except up2dateErrors.NoSystemIdError, e:
    sys.stderr.write("%s\n" % e)
    sys.exit(42)
except up2dateErrors.Error, e:
    sys.stderr.write("%s\n" % e)
    sys.exit(1)
except:
    sys.exit(1)

service_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
print "# Channels for service %s" % service_name
for channel in svrChannels:
    print >>sendback
    if channel['name']:
        print >>sendback, "# Name:        %s" % utf8_encode(channel['name'])
예제 #12
0
# sending back the result.
sendback = sys.stdout
sys.stdout = sys.stderr

try:
    sys.path.append("/usr/share/rhn/")
    from up2date_client import rhnChannel
    from up2date_client import up2dateErrors
    from up2date_client.rhncli import utf8_encode
except:
    sys.stderr.write("%sPlease install package spacewalk-backend-libs.\n" %
                     traceback.format_exc())
    sys.exit(1)

try:
    svrChannels = rhnChannel.getChannelDetails()
except up2dateErrors.NoSystemIdError, e:
    sys.stderr.write("%s\n" % e)
    sys.exit(42)
except up2dateErrors.Error, e:
    sys.stderr.write("%s\n" % e)
    sys.exit(1)
except:
    sys.exit(1)

service_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
print "# Channels for service %s" % service_name
for channel in svrChannels:
    print >> sendback
    if channel['name']:
        print >> sendback, "# Name:        %s" % utf8_encode(channel['name'])