Example #1
0
def _complete_profile_id(partial):
    partial = TurnKeyVersion.from_string(partial)
    system = TurnKeyVersion.from_system()
    if not system:
        return

    if partial.arch is None:
        partial.arch = system.arch

    if partial.release is None or system.release.startswith(partial.release):
        partial.release = system.release

    return str(partial)
Example #2
0
def _complete_profile_id(partial):
    partial = TurnKeyVersion.from_string(partial)
    system = TurnKeyVersion.from_system()
    if not system:
        return

    if partial.arch is None:
        partial.arch = system.arch

    if partial.release is None or system.release.startswith(partial.release):
        partial.release = system.release

    return str(partial)
Example #3
0
    def update_profile(self, profile_id=None):
        if profile_id is None:
            # don't attempt to update empty or custom profiles
            if self.profile and \
               (self.profile.profile_id == registry.EMPTY_PROFILE or 
                self.profile.profile_id.startswith(registry.CUSTOM_PROFILE + ":")):
                return

        try:
            # look for exact match first
            self._update_profile(profile_id)
        except self.ProfileNotFound, first_exception:
            if profile_id:
                if not re.match(r'^turnkey-', profile_id):
                    profile_id = "turnkey-" + profile_id

                if not TurnKeyVersion.from_string(profile_id).is_complete():
                    completed_profile_id = _complete_profile_id(profile_id)
                    if completed_profile_id:
                        try:
                            self._update_profile(completed_profile_id)
                            return
                        except:
                            pass

            raise first_exception
Example #4
0
    def update_profile(self, profile_id=None):
        if profile_id is None:
            # don't attempt to update empty or custom profiles
            if self.profile and \
               (self.profile.profile_id == registry.EMPTY_PROFILE or
                self.profile.profile_id.startswith(registry.CUSTOM_PROFILE + ":")):
                return

        try:
            # look for exact match first
            self._update_profile(profile_id)
        except self.ProfileNotFound, first_exception:
            if profile_id:
                if not re.match(r'^turnkey-', profile_id):
                    profile_id = "turnkey-" + profile_id

                if not TurnKeyVersion.from_string(profile_id).is_complete():
                    completed_profile_id = _complete_profile_id(profile_id)
                    if completed_profile_id:
                        try:
                            self._update_profile(completed_profile_id)
                            return
                        except:
                            pass

            raise first_exception
Example #5
0
def do_compatibility_check(backup_profile_id, interactive=True):
    # unless both backup and restore are TurnKey skip compatibility check
    try:
        backup_codename = TurnKeyVersion.from_string(
            backup_profile_id).codename
    except TurnKeyVersion.Error:
        return

    turnkey_version = TurnKeyVersion.from_system()
    if not turnkey_version:
        return

    local_codename = turnkey_version.codename

    if local_codename == backup_codename:
        return

    def fmt(s):
        return s.upper().replace("-", " ")

    backup_codename = fmt(backup_codename)
    local_codename = fmt(local_codename)

    print "WARNING: INCOMPATIBLE APPLIANCE BACKUP"
    print "======================================"
    print
    print "Restoring a %s backup to a %s appliance may create complications." % (
        backup_codename, local_codename)
    print "For best results try restoring instead to a fresh %s installation." % backup_codename

    if not interactive:
        sys.exit(ExitCode.INCOMPATIBLE)

    print
    print "(Use --force to suppress this check)"
    print

    while True:
        answer = raw_input("Do you want to continue? [yes/no] ")
        if answer:
            break

    if answer.lower() not in ('y', 'yes'):
        fatal("You didn't answer 'yes'. Aborting!")
Example #6
0
def do_compatibility_check(backup_profile_id, interactive=True):
    # unless both backup and restore are TurnKey skip compatibility check
    try:
        backup_codename = TurnKeyVersion.from_string(backup_profile_id).codename
    except TurnKeyVersion.Error:
        return

    turnkey_version = TurnKeyVersion.from_system()
    if not turnkey_version:
        return

    local_codename = turnkey_version.codename

    if local_codename == backup_codename:
        return

    def fmt(s):
        return s.upper().replace("-", " ")

    backup_codename = fmt(backup_codename)
    local_codename = fmt(local_codename)

    print "WARNING: INCOMPATIBLE APPLIANCE BACKUP"
    print "======================================"
    print
    print "Restoring a %s backup to a %s appliance may create complications." % (backup_codename, local_codename)
    print "For best results try restoring instead to a fresh %s installation." % backup_codename

    if not interactive:
        sys.exit(ExitCode.INCOMPATIBLE)

    print
    print "(Use --force to suppress this check)"
    print

    while True:
        answer = raw_input("Do you want to continue? [yes/no] ")
        if answer:
            break

    if answer.lower() not in ('y', 'yes'):
        fatal("You didn't answer 'yes'. Aborting!")