def hub_backups(): import sys try: hb = hub.Backups(registry.sub_apikey) except hub.Backups.NotInitialized: raise NotInitialized() return hb
def _update_profile(self, profile_id=None): """Get a new profile if we don't have a profile in the registry or the Hub has a newer profile for this appliance. If we can't contact the Hub raise an error if we don't already have profile.""" if not profile_id: if self.profile: profile_id = self.profile.profile_id else: profile_id = detect_profile_id() if profile_id == self.EMPTY_PROFILE or isdir(profile_id): self.profile = profile_id return hub_backups = hub.Backups(self.sub_apikey) if self.profile and self.profile.profile_id == profile_id: profile_timestamp = self.profile.timestamp else: # forced profile is not cached in the self profile_timestamp = None try: new_profile = hub_backups.get_new_profile(profile_id, profile_timestamp) if new_profile: self.profile = new_profile print "Downloaded %s profile" % self.profile.profile_id except hub.NotSubscribed: raise except hub_backups.Error, e: errno, errname, desc = e.args if errname == "BackupArchive.NotFound": raise self.ProfileNotFound(desc) if not self.profile or (self.profile.profile_id != profile_id): raise raise self.CachedProfile("using cached profile because of a Hub error: " + desc)
arg = args[0] if isdir(join(arg, backup.ExtrasPaths.PATH)): backup_extract_path = arg else: try: try: hbr = get_backup_record(arg) except hub.Backups.NotInitialized, e: print >> sys.stderr, "error: " + str(e) print >> sys.stderr, "tip: you can still use tklbam-restore with --address or a backup extract" sys.exit(1) credentials = hub.Backups( registry.sub_apikey).get_credentials() except Error, e: fatal(e) else: if not opt_address: usage() if backup_extract_path: for opt, val in opts: if opt[2:] in ('time', 'keyfile', 'address', 'restore-cache-size', 'restore-cache-dir'): fatal("%s is incompatible with restoring from path %s" % (opt, backup_extract_path)) else:
while True: apikey = raw_input("API-KEY: ").strip() if apikey: break if not is_valid_apikey(apikey): fatal("'%s' is an invalid API-KEY" % apikey) try: sub_apikey = hub.Backups.get_sub_apikey(apikey) except Exception, e: fatal(e) registry.registry.sub_apikey = sub_apikey hb = hub.Backups(sub_apikey) try: credentials = hb.get_credentials() registry.registry.credentials = credentials print "Linked TKLBAM to your Hub account." except hub.NotSubscribed, e: print "Linked TKLBAM to your Hub account but there's a problem:" print elif not force_profile and registry.registry.profile: fatal("already initialized") if force_profile or not registry.registry.profile: try: registry.update_profile(conf.force_profile)