Beispiel #1
0
    def send(self,
             uuiddb,
             uuid,
             user_agent=user_agent,
             smoonURL=smoonURL,
             timeout=timeout,
             proxies=proxies,
             batch=False):
        def serialize(object, human=False):
            if human:
                indent = 2
                sort_keys = True
            else:
                indent = None
                sort_keys = False
            return JSONEncoder(indent=indent,
                               sort_keys=sort_keys).encode(object)

        reset_resolver()
        grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent,
                                                timeout=timeout,
                                                proxies=proxies)
        #first find out the server desired protocol
        try:
            token = grabber.urlopen(
                urljoin(smoonURL + "/",
                        '/tokens/token_json?uuid=%s' % self.host.UUID, False))
        except urlgrabber.grabber.URLGrabError, e:
            error(_('Error contacting Server: %s') % e)
            return (1, None, None)
Beispiel #2
0
 def regenerate_pub_uuid(self, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout):
     grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout)
     try:
         new_uuid = grabber.urlopen(urljoin(smoonURL + "/", '/client/regenerate_pub_uuid?uuid=%s' % self.host.UUID))
     except urlgrabber.grabber.URLGrabError, e:
         error(_('Error contacting Server: %s') % e)
         sys.exit(0)
Beispiel #3
0
def read_pub_uuid(uuiddb,
                  uuid,
                  user_agent=user_agent,
                  smoonURL=smoonURL,
                  timeout=timeout,
                  silent=False):
    smoonURLparsed = urlparse(smoonURL)
    res = uuiddb.get_pub_uuid(uuid, smoonURLparsed[1])
    if res:
        return res

    grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent,
                                            timeout=timeout,
                                            proxies=proxies)
    try:
        o = grabber.urlopen(
            urljoin(smoonURL + "/", '/client/pub_uuid/%s' % uuid))
        pudict = json.loads(o.read())
        o.close()
        uuiddb.set_pub_uuid(uuid, smoonURLparsed[1], pudict["pub_uuid"])
        return pudict["pub_uuid"]
    except Exception, e:
        if not silent:
            error(_('Error determining public UUID: %s') % e)
            sys.stderr.write(
                _("Unable to determine Public UUID!  This could be a network error or you've\n"
                  ))
            sys.stderr.write(_("not submitted your profile yet.\n"))
        raise PubUUIDError, 'Could not determine Public UUID!\n'
Beispiel #4
0
def _preprocessStateMachine(lineIter):
    l = None
    lineno = 0

    # Now open an output kickstart file that we are going to write to one
    # line at a time.
    (outF, outName) = tempfile.mkstemp("-ks.cfg", "", "/tmp")

    while True:
        try:
            l = lineIter.next()
        except StopIteration:
            break

        # At the end of the file?
        if l == "":
            break

        lineno += 1
        url = None

        ll = l.strip()
        if not ll.startswith("%ksappend"):
            os.write(outF, l)
            continue

        # Try to pull down the remote file.
        try:
            ksurl = ll.split(' ')[1]
        except:
            raise KickstartParseError, formatErrorMsg(
                lineno, msg=_("Illegal url for %%ksappend: %s") % ll)

        try:
            url = grabber.urlopen(ksurl)
        except grabber.URLGrabError, e:
            raise KickstartError, formatErrorMsg(
                lineno,
                msg=_("Unable to open %%ksappend file: %s") % e.strerror)
        else:
            # Sanity check result.  Sometimes FTP doesn't catch a file
            # is missing.
            try:
                if url.size < 1:
                    raise KickstartError, formatErrorMsg(
                        lineno, msg=_("Unable to open %%ksappend file"))
            except:
                raise KickstartError, formatErrorMsg(
                    lineno, msg=_("Unable to open %%ksappend file"))

        # If that worked, write the remote file to the output kickstart
        # file in one burst.  Then close everything up to get ready to
        # read ahead in the input file.  This allows multiple %ksappend
        # lines to exist.
        if url is not None:
            os.write(outF, url.read())
            url.close()
Beispiel #5
0
def urlretrieve(location, file, callback=None):
    """Downloads from location and saves to file."""
    if callback is not None:
        callback(_("Connecting..."), 0)

    try:
        url = grabber.urlopen(location)
    except grabber.URLGrabError, e:
        raise IOError(e.errno, e.strerror)
Beispiel #6
0
def urlretrieve(location, file, callback=None):
    """Downloads from location and saves to file."""
    if callback is not None:
	callback(_("Connecting..."), 0)

    try:
	url = grabber.urlopen(location)
    except grabber.URLGrabError, e:
	raise IOError (e.errno, e.strerror)
Beispiel #7
0
def main():
    profile = smolt.get_profile()
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    #first find out the server desired protocol
    try:
        #fli is a file like item
        pub_uuid_fli = grabber.urlopen(urljoin(opts.smoonURL + "/", '/client/pub_uuid?uuid=%s' % profile.host.UUID, False))
    except urlgrabber.grabber.URLGrabError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
    def _download_rpm(self, nvr, arch):
        if nvr is None or arch is None:
            raise ValueError("Invalid option passed to connector")

        filename = '%s.%s.rpm' % (nvr, arch)
        file_path = os.path.split(filename)
        if file_path[0] != '':
            raise ValueError("Nvr can not contain path elements")
        if len(arch.split('/')) != 1 or os.path.split(arch)[0] != '':
            raise ValueError("Arch can not contain path elements")

        rpm_file_path = os.path.join(self._rpm_cache, filename)
        if os.path.exists(rpm_file_path):
            return rpm_file_path

        lockfile = LockFile(file_path)
        if lockfile.is_locked():
            # block until the lock is released and then assume other
            # thread was successful
            lockfile.acquire()
            lockfile.release()
            return rpm_file_path

        # acquire the lock and release when done
        lockfile.acquire()
        try:
            info = self.call('getBuild', {'buildInfo': nvr})
            if info is None:
                return {'error': 'No such build (%s)' % filename}

            if not os.path.exists(self._rpm_cache):
                os.mkdir(self._rpm_cache, )

            url = '%s/%s/%s/%s/%s/%s' % (self._koji_pkg_url, info['name'],
                                         info['version'], info['release'],
                                         arch, filename)

            url_file = grabber.urlopen(url, text=filename)
            out = os.open(rpm_file_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
                          0666)
            try:
                while 1:
                    buf = url_file.read(4096)
                    if not buf:
                        break
                    os.write(out, buf)
            except Exception as e:
                raise e
            finally:
                os.close(out)
                url_file.close()
        finally:
            lockfile.release()

        return rpm_file_path
Beispiel #9
0
    def _download_rpm(self, nvr, arch):
        if nvr is None or arch is None:
            raise ValueError("Invalid option passed to connector")

        filename = '%s.%s.rpm' % (nvr, arch)
        file_path = os.path.split(filename)
        if file_path[0] != '':
            raise ValueError("Nvr can not contain path elements")
        if len(arch.split('/')) != 1 or os.path.split(arch)[0] != '':
            raise ValueError("Arch can not contain path elements")

        rpm_file_path = os.path.join(self._rpm_cache, filename)
        if os.path.exists(rpm_file_path):
            return rpm_file_path

        lockfile = LockFile(file_path)
        if lockfile.is_locked():
            # block until the lock is released and then assume other
            # thread was successful
            lockfile.acquire()
            lockfile.release()
            return rpm_file_path

        # acquire the lock and release when done
        lockfile.acquire()
        try:
            info = self.call('getBuild', {'buildInfo': nvr})
            if info is None:
                return {'error': 'No such build (%s)' % filename}

            if not os.path.exists(self._rpm_cache):
                os.mkdir(self._rpm_cache,)

            url = '%s/%s/%s/%s/%s/%s' % (
                self._koji_pkg_url, info['name'], info['version'],
                info['release'], arch, filename)

            url_file = grabber.urlopen(url, text=filename)
            out = os.open(
                rpm_file_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0666)
            try:
                while 1:
                    buf = url_file.read(4096)
                    if not buf:
                        break
                    os.write(out, buf)
            except Exception as e:
                raise e
            finally:
                os.close(out)
                url_file.close()
        finally:
            lockfile.release()

        return rpm_file_path
Beispiel #10
0
def main():
    from gate import create_default_gate
    profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    #first find out the server desired protocol
    try:
        #fli is a file like item
        pub_uuid_fli = grabber.urlopen(urljoin(opts.smoonURL + "/", '/client/pub_uuid?uuid=%s' % profile.host.UUID, False))
    except urlgrabber.grabber.URLGrabError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
Beispiel #11
0
def _preprocessStateMachine (lineIter):
    l = None
    lineno = 0

    # Now open an output kickstart file that we are going to write to one
    # line at a time.
    (outF, outName) = tempfile.mkstemp("-ks.cfg", "", "/tmp")

    while True:
        try:
            l = lineIter.next()
        except StopIteration:
            break

        # At the end of the file?
        if l == "":
            break

        lineno += 1
        url = None

        ll = l.strip()
        if not ll.startswith("%ksappend"):
            os.write(outF, l)
            continue

        # Try to pull down the remote file.
        try:
            ksurl = ll.split(' ')[1]
        except:
            raise KickstartParseError, formatErrorMsg(lineno, msg=_("Illegal url for %%ksappend: %s") % ll)

        try:
            url = grabber.urlopen(ksurl)
        except grabber.URLGrabError, e:
            raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file: %s") % e.strerror)
        else:
            # Sanity check result.  Sometimes FTP doesn't catch a file
            # is missing.
            try:
                if url.size < 1:
                    raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file"))
            except:
                raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file"))

        # If that worked, write the remote file to the output kickstart
        # file in one burst.  Then close everything up to get ready to
        # read ahead in the input file.  This allows multiple %ksappend
        # lines to exist.
        if url is not None:
            os.write(outF, url.read())
            url.close()
Beispiel #12
0
def preprocessKickstart(f):
    """Preprocess the kickstart file, given by the filename file.  This
        method is currently only useful for handling %ksappend lines,
        which need to be fetched before the real kickstart parser can be
        run.  Returns the location of the complete kickstart file.
    """
    try:
        fh = grabber.urlopen(f)
    except grabber.URLGrabError, e:
        raise KickstartError(
            formatErrorMsg(0,
                           msg=_("Unable to open input kickstart file: %s") %
                           e.strerror))
Beispiel #13
0
def main():
    from gate import create_default_gate

    profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    # first find out the server desired protocol
    try:
        # fli is a file like item
        pub_uuid_fli = grabber.urlopen(
            urljoin(opts.smoonURL + "/", "/client/pub_uuid?uuid=%s" % profile.host.UUID, False)
        )
    except urlgrabber.grabber.URLGrabError, e:
        error(_("Error contacting Server: %s") % e)
        return 1
Beispiel #14
0
def _downloadURL(url, destf):
    """Download a url and save it to a file"""
    file = grabber.urlopen(url, progress_obj = pg, text = "%s" % (destf))

    out = os.open(destf, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666)
    try:
        while 1:
            buf = file.read(4096)
            if not buf:
                break
            os.write(out, buf)
    finally:
        os.close(out)
        file.close()
Beispiel #15
0
def _downloadURL(url, destf):
    """Download a url and save it to a file"""
    file = grabber.urlopen(url, progress_obj=pg, text="%s" % (destf))

    out = os.open(destf, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0666)
    try:
        while 1:
            buf = file.read(4096)
            if not buf:
                break
            os.write(out, buf)
    finally:
        os.close(out)
        file.close()
Beispiel #16
0
 def regenerate_pub_uuid(self,
                         uuiddb,
                         uuid,
                         user_agent=user_agent,
                         smoonURL=smoonURL,
                         timeout=timeout):
     grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent,
                                             timeout=timeout)
     try:
         new_uuid = grabber.urlopen(
             urljoin(smoonURL + "/", '/client/regenerate_pub_uuid?uuid=%s' %
                     self.host.UUID))
     except urlgrabber.grabber.URLGrabError, e:
         raise ServerError, str(e)
Beispiel #17
0
def pullRemainingKickstartConfig(ksfile):
    import tempfile

    # Open the input kickstart file and read it all into a list.
    try:
        inF = open(ksfile, "r")
    except:
        raise KickstartError("Unable to open ks file %s for reading" % ksfile)

    lines = inF.readlines()
    inF.close()

    # Now open an output kickstart file that we are going to write to one
    # line at a time.
    (outF, outName) = tempfile.mkstemp("-ks.cfg", "", "/tmp")

    for l in lines:
        url = None

        ll = l.strip()
        if not ll.startswith("%ksappend"):
            os.write(outF, l)
            continue

        # Try to pull down the remote file.
        try:
            ksurl = string.split(ll, ' ')[1]
        except:
            raise KickstartError("Illegal url for %%ksappend: %s" % ll)

        log.info("Attempting to pull additional part of ks.cfg from url %s" %
                 ksurl)

        try:
            url = grabber.urlopen(ksurl)
        except grabber.URLGrabError, e:
            raise KickstartError("IOError: %s" % e.strerror)
        else:
            # sanity check result - sometimes FTP doesnt
            # catch a file is missing
            try:
                clen = url.info()['content-length']
            except Exception, e:
                clen = 0

            if clen < 1:
                raise KickstartError("IOError: -1:File not found")
Beispiel #18
0
def getPubUUID(user_agent=user_agent, smoonURL=smoonURL, timeout=timeout):
	smoonURLparsed=urlparse(smoonURL)
	res = UuidDb().get_pub_uuid(getUUID(), smoonURLparsed.hostname)
	if res:
		return res

	grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout, proxies=proxies)
	try:
		o = grabber.urlopen(urljoin(smoonURL + "/", '/client/pub_uuid/%s' % getUUID()))
		pudict = simplejson.loads(o.read())
		o.close()
		UuidDb().set_pub_uuid(getUUID(), smoonURLparsed.hostname, pudict["pub_uuid"])
		return pudict["pub_uuid"]
	except Exception, e:
		error(_('Error determining public UUID: %s') % e)
		sys.stderr.write(_('Unable to determine Public UUID!\n'))
		raise PubUUIDError, 'Could not determine Public UUID!\n'
def pullRemainingKickstartConfig(ksfile):
    import tempfile

    # Open the input kickstart file and read it all into a list.
    try:
        inF = open(ksfile, "r")
    except:
        raise KickstartError ("Unable to open ks file %s for reading" % ksfile)

    lines = inF.readlines()
    inF.close()

    # Now open an output kickstart file that we are going to write to one
    # line at a time.
    (outF, outName) = tempfile.mkstemp("-ks.cfg", "", "/tmp")

    for l in lines:
        url = None

        ll = l.strip()
        if not ll.startswith("%ksappend"):
            os.write(outF, l)
            continue

        # Try to pull down the remote file.
        try:
            ksurl = string.split(ll, ' ')[1]
        except:
            raise KickstartError ("Illegal url for %%ksappend: %s" % ll)

	log.info("Attempting to pull additional part of ks.cfg from url %s" % ksurl)

        try:
            url = grabber.urlopen (ksurl)
        except grabber.URLGrabError, e:
            raise KickstartError ("IOError: %s" % e.strerror)
	else:
	    # sanity check result - sometimes FTP doesnt
	    # catch a file is missing
	    try:
		clen = url.info()['content-length']
	    except Exception, e:
		clen = 0

	    if clen < 1:
		raise KickstartError ("IOError: -1:File not found")
Beispiel #20
0
    def acquireFile(self, filename):
        # URLGrabber works for all network and local cases

        f = None
        try:
            path = self._make_path(filename)
            base = os.path.basename(filename)
            logging.debug("Fetching URI: %s", path)

            try:
                f = grabber.urlopen(path, progress_obj=self.meter, text=_("Retrieving file %s...") % base)
            except Exception, e:
                raise ValueError(_("Couldn't acquire file %s: %s") % (path, str(e)))

            tmpname = self.saveTemp(f, prefix=base + ".")
            logging.debug("Saved file to " + tmpname)
            return tmpname
Beispiel #21
0
    def send(self, uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, proxies=proxies, batch=False):
        def serialize(object, human=False):
            if human:
                indent = 2
                sort_keys = True
            else:
                indent = None
                sort_keys = False
            return JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)

        reset_resolver()
        grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout, proxies=proxies)
        #first find out the server desired protocol
        try:
            token = grabber.urlopen(urljoin(smoonURL + "/", '/tokens/token_json?uuid=%s' % self.host.UUID, False))
        except urlgrabber.grabber.URLGrabError, e:
            error(_('Error contacting Server: %s') % e)
            return (1, None, None)
Beispiel #22
0
def read_pub_uuid(uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, silent=False):
	smoonURLparsed=urlparse(smoonURL)
	res = uuiddb.get_pub_uuid(uuid, smoonURLparsed[1])
	if res:
		return res

	grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout, proxies=proxies)
	try:
		o = grabber.urlopen(urljoin(smoonURL + "/", '/client/pub_uuid/%s' % uuid))
		pudict = simplejson.loads(o.read())
		o.close()
		uuiddb.set_pub_uuid(uuid, smoonURLparsed[1], pudict["pub_uuid"])
		return pudict["pub_uuid"]
	except Exception, e:
		if not silent:
			error(_('Error determining public UUID: %s') % e)
			sys.stderr.write(_("Unable to determine Public UUID!  This could be a network error or you've\n"))
			sys.stderr.write(_("not submitted your profile yet.\n"))
		raise PubUUIDError, 'Could not determine Public UUID!\n'
Beispiel #23
0
    def acquireFile(self, filename):
        # URLGrabber works for all network and local cases

        f = None
        try:
            path = self._make_path(filename)
            base = os.path.basename(filename)
            logging.debug("Fetching URI: %s", path)

            try:
                f = grabber.urlopen(path,
                                    progress_obj=self.meter,
                                    text=_("Retrieving file %s...") % base)
            except Exception, e:
                raise ValueError(_("Couldn't acquire file %s: %s") %
                                   (path, str(e)))

            tmpname = self.saveTemp(f, prefix=base + ".")
            logging.debug("Saved file to " + tmpname)
            return tmpname
Beispiel #24
0
def main():
    sys.path.append('/usr/share/smolt/client')

    from i18n import _
    import smolt
    from smolt import error, debug, get_profile_link, PubUUIDError
    from uuiddb import create_default_uuiddb

    def serverMessage(page):
        for line in page.split("\n"):
            if 'ServerMessage:' in line:
                error(_('Server Message: "%s"') % line.split('ServerMessage: ')[1])
                if 'Critical' in line:
                    sys.exit(3)

    parser = OptionParser(version = smolt.smoltProtocol)

    parser.add_option('-d', '--debug',
                    dest = 'DEBUG',
                    default = False,
                    action = 'store_true',
                    help = _('enable debug information'))
    parser.add_option('-s', '--server',
                    dest = 'smoonURL',
                    default = smolt.smoonURL,
                    metavar = 'smoonURL',
                    help = _('specify the URL of the server (default "%default")'))
    parser.add_option('-p', '--printOnly',
                    dest = 'printOnly',
                    default = False,
                    action = 'store_true',
                    help = _('print information only, do not send'))
    parser.add_option('-u', '--useragent',
                    dest = 'user_agent',
                    default = smolt.user_agent,
                    metavar = 'USERAGENT',
                    help = _('specify HTTP user agent (default "%default")'))
    parser.add_option('-t', '--timeout',
                    dest = 'timeout',
                    type = 'float',
                    default = smolt.timeout,
                    help = _('specify HTTP timeout in seconds (default %default seconds)'))
    parser.add_option('--uuidFile',
                    dest = 'uuidFile',
                    default = smolt.hw_uuid_file,
                    help = _('specify which uuid to use, useful for debugging and testing mostly.'))


    (opts, args) = parser.parse_args()

    smolt.DEBUG = opts.DEBUG
    smolt.hw_uuid_file = opts.uuidFile

    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)

    uuid = smolt.read_uuid()
    delHostString = 'uuid=%s' % uuid

    # Try retrieving current pub_uuid  (from cache or remotely if necessary)
    pub_uuid = None
    try:
        pub_uuid = smolt.read_pub_uuid(create_default_uuiddb(), uuid, silent=True)
    except PubUUIDError:
        pass


    try:
        o=grabber.urlopen(urljoin(opts.smoonURL + '/', '/client/delete'), data=delHostString, http_headers=(
                        ('Content-length', '%i' % len(delHostString)),
                        ('Content-type', 'application/x-www-form-urlencoded')))
    except urlgrabber.grabber.URLGrabError, e:
        sys.stderr.write(_('Error contacting Server:'))
        sys.stderr.write(str(e))
        sys.stderr.write('\n')
        sys.exit(1)
Beispiel #25
0
        send_host_obj['smolt_protocol'] = prefered_protocol

        debug('smoon server URL: %s' % smoonURL)

        serialized_host_obj_machine = serialize(send_host_obj, human=False)
        send_host_str = ('uuid=%s&host=' + \
                         serialized_host_obj_machine + \
                         '&token=%s&smolt_protocol=%s') % \
                         (self.host.UUID, tok, smoltProtocol)

        debug('sendHostStr: %s' % serialized_host_obj_machine)
        debug('Sending Host')

        try:
            o = grabber.urlopen(urljoin(smoonURL + "/", "/client/add_json", False), data=send_host_str,
                                http_headers=(
                            ('Content-length', '%i' % len(send_host_str)),
                            ('Content-type', 'application/x-www-form-urlencoded')))
        except urlgrabber.grabber.URLGrabError, e:
            error(_('Error contacting Server: %s') % e)
            return (1, None, None)
        else:
            pub_uuid = serverMessage(o.read())
            o.close()
            self.write_pub_uuid(smoonURL,pub_uuid)

            try:
                admin_token = grabber.urlopen(urljoin(smoonURL + "/", '/tokens/admin_token_json?uuid=%s' % self.host.UUID, False))
            except urlgrabber.grabber.URLGrabError, e:
                error(_('An error has occured while contacting the server: %s' % e))
                sys.exit(1)
            admin_str = admin_token.read()
Beispiel #26
0

(opts, args) = parser.parse_args()

smolt.DEBUG = opts.DEBUG
smolt.hw_uuid_file = opts.uuidFile
# read the profile
profile = smolt.Hardware()

grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)

delHostString = 'uuid=%s' % profile.host.UUID

try:
    o=grabber.urlopen(urljoin(opts.smoonURL + '/', '/client/delete'), data=delHostString, http_headers=(
                    ('Content-length', '%i' % len(delHostString)),
                    ('Content-type', 'application/x-www-form-urlencoded')))
except urlgrabber.grabber.URLGrabError, e:
    sys.stderr.write(_('Error contacting Server:'))
    sys.stderr.write(str(e))
    sys.stderr.write('\n')
    sys.exit(1)
else:
    serverMessage(o.read())
    o.close()

sys.stdout.write(_('Profile removed, please verify at'))
sys.stdout.write(' ')
sys.stdout.write(urljoin(opts.smoonURL + '/', '/client/show?%s\n' % delHostString))

Beispiel #27
0
                continue
    rpms = remotekojisession.listRPMs(build_id)
    if isNoarch(rpms):
        buildinfo = remotekojisession.getBuild(build_id)
        importBuild(nvr, rpms, buildinfo, tag=tag)
        continue
    request = remotekojisession.getTaskRequest(task_id)
    #localkojisession.build(request[0], request[1], opts=None, priority=2)

    fname = "%s.src.rpm" % nvr
    fpath = "%s/%s.src.rpm" % (workpath, nvr)
    url = "%s/packages/%s/%s/%s/src/%s" % (PACKAGEURL, name, version, release,
                                           fname)

    if not os.path.isfile(fpath):
        file = grabber.urlopen(url, progress_obj=pg, text="%s" % (fname))
        out = os.open(fpath, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0666)
        try:
            while 1:
                buf = file.read(4096)
                if not buf:
                    break
                os.write(out, buf)
        finally:
            os.close(out)
            file.close()

    serverdir = _unique_path('cli-build')
    localkojisession.uploadWrapper(fpath, serverdir, blocksize=65536)
    source = "%s/%s" % (serverdir, fname)
    target = request[1]
 def get(self):
     try:
         url = grabber.urlopen(self.url)
     except grabber.URLGrabError, e:
         raise CasNetworkException(e.errno, e.strerror)
Beispiel #29
0
                server_response = serverMessage(o.read())
            except ServerError, e:
                error(_('Error contacting server: %s') % e)
                return (1, None, None)

            o.close()
            if batch:
                pub_uuid = None
            else:
                pub_uuid = server_response
            self.write_pub_uuid(uuiddb, smoonURL, pub_uuid, uuid)

            try:
                admin_token = grabber.urlopen(
                    urljoin(
                        smoonURL + "/",
                        '/tokens/admin_token_json?uuid=%s' % self.host.UUID,
                        False))
            except urlgrabber.grabber.URLGrabError, e:
                error(
                    _('An error has occured while contacting the server: %s' %
                      e))
                sys.exit(1)
            admin_str = admin_token.read()
            admin_obj = json.loads(admin_str)
            if admin_obj['prefered_protocol'] in supported_protocols:
                prefered_protocol = admin_obj['prefered_protocol']
            else:
                error(
                    _('Wrong version, server incapable of handling your client'
                      ))
Beispiel #30
0
        else:
            try:
                server_response = serverMessage(o.read())
            except ServerError, e:
                error(_('Error contacting server: %s') % e)
                return (1, None, None)

            o.close()
            if batch:
                pub_uuid = None
            else:
                pub_uuid = server_response
            self.write_pub_uuid(uuiddb, smoonURL, pub_uuid, uuid)

            try:
                admin_token = grabber.urlopen(urljoin(smoonURL + "/", '/tokens/admin_token_json?uuid=%s' % self.host.UUID, False))
            except urlgrabber.grabber.URLGrabError, e:
                error(_('An error has occured while contacting the server: %s' % e))
                sys.exit(1)
            admin_str = admin_token.read()
            admin_obj = simplejson.loads(admin_str)
            if admin_obj['prefered_protocol'] in supported_protocols:
                prefered_protocol = admin_obj['prefered_protocol']
            else:
                error(_('Wrong version, server incapable of handling your client'))
                return (1, None, None)
            admin = admin_obj['token']

            if  not admin_token_file == '' :
                self.write_admin_token(smoonURL,admin,admin_token_file)
        return (0, pub_uuid, admin)
Beispiel #31
0
 def regenerate_pub_uuid(self, uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout):
     grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout)
     try:
         new_uuid = grabber.urlopen(urljoin(smoonURL + "/", '/client/regenerate_pub_uuid?uuid=%s' % self.host.UUID))
     except urlgrabber.grabber.URLGrabError, e:
         raise ServerError, str(e)
Beispiel #32
0
(opts, args) = parser.parse_args()

smolt.DEBUG = opts.DEBUG
smolt.hw_uuid_file = opts.uuidFile
# read the profile
profile = smolt.Hardware()

grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent,
                                        timeout=opts.timeout)

delHostString = 'uuid=%s' % profile.host.UUID

try:
    o = grabber.urlopen(urljoin(opts.smoonURL + '/', '/client/delete'),
                        data=delHostString,
                        http_headers=(('Content-length',
                                       '%i' % len(delHostString)),
                                      ('Content-type',
                                       'application/x-www-form-urlencoded')))
except urlgrabber.grabber.URLGrabError, e:
    sys.stderr.write(_('Error contacting Server:'))
    sys.stderr.write(str(e))
    sys.stderr.write('\n')
    sys.exit(1)
else:
    serverMessage(o.read())
    o.close()

sys.stdout.write(_('Profile removed, please verify at'))
sys.stdout.write(' ')
sys.stdout.write(
    urljoin(opts.smoonURL + '/', '/client/show?%s\n' % delHostString))
Beispiel #33
0
                continue
    rpms = remotekojisession.listRPMs(build_id)
    if isNoarch(rpms):
        buildinfo = remotekojisession.getBuild(build_id)
        importBuild(nvr, rpms, buildinfo, tag=tag)
        continue
    request = remotekojisession.getTaskRequest(task_id)
    #localkojisession.build(request[0], request[1], opts=None, priority=2)
        
    fname = "%s.src.rpm" %  nvr
    fpath = "%s/%s.src.rpm" % (workpath, nvr)
    url = "%s/packages/%s/%s/%s/src/%s" % (PACKAGEURL, name, version, release, fname)


    if not os.path.isfile(fpath):
        file = grabber.urlopen(url, progress_obj = pg, text = "%s" % (fname))
        out = os.open(fpath, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666)
        try:
            while 1:
                buf = file.read(4096)
                if not buf:
                    break
                os.write(out, buf)
        finally:
            os.close(out)
            file.close()
        
    serverdir = _unique_path('cli-build')
    localkojisession.uploadWrapper(fpath, serverdir, blocksize=65536)
    source = "%s/%s" % (serverdir, fname)
    target = request[1]