Exemple #1
0
 def retry_view(self, request, host_migrate_id):
     retry_from = get_object_or_404(HostMigrate, pk=host_migrate_id)
     success, redirect = self.check_status(request, retry_from, 'retry')
     if not success:
         return redirect
     TaskRegister.host_migrate(retry_from.host, retry_from.zone,
                               retry_from.environment, request.user,
                               retry_from.current_step)
     return self.redirect_to_database(retry_from)
 def retry_view(self, request, host_migrate_id):
     retry_from = get_object_or_404(HostMigrate, pk=host_migrate_id)
     success, redirect = self.check_status(request, retry_from, 'retry')
     if not success:
         return redirect
     host = retry_from.host
     database = host.instances.first().databaseinfra.databases.first()
     TaskRegister.host_migrate(retry_from.host,
                               retry_from.zone,
                               retry_from.environment,
                               request.user,
                               database,
                               retry_from.current_step,
                               step_manager=retry_from)
     return self.redirect_to_database(retry_from)
def database_migrate(request, context, database):
    if not database.is_host_migrate_available:
        messages.add_message(
            request, messages.ERROR, "This database cannot be migrated"
        )
        return database_details(request, database.id)

    environment = database.infra.environment
    if request.POST:
        can_migrate, error = database.can_migrate_host()
        if not can_migrate:
            messages.add_message(request, messages.ERROR, error)
        elif 'host_id' in request.POST:
            host = get_object_or_404(Host, pk=request.POST.get('host_id'))
            zone = request.POST["new_zone"]
            TaskRegister.host_migrate(host, zone, environment, request.user)
        elif 'new_environment' in request.POST:
            environment = get_object_or_404(
                Environment, pk=request.POST.get('new_environment')
            )
            offering = get_object_or_404(
                Offering, pk=request.POST.get('new_offering')
            )
            if environment not in offering.environments.all():
                messages.add_message(
                    request, messages.ERROR,
                    "There is no offering {} to {} environment".format(
                        offering, environment
                    )
                )
                return

            hosts_zones = OrderedDict()
            data = json.loads(request.POST.get('hosts_zones'))
            for host_id, zone in data.items():
                host = get_object_or_404(Host, pk=host_id)
                hosts_zones[host] = zone
            if not hosts_zones:
                messages.add_message(
                    request, messages.ERROR, "There is no host to migrate"
                )
            else:
                TaskRegister.database_migrate(
                    database, environment, offering, request.user, hosts_zones
                )
        return

    hosts = set()
    zones = set()
    instances = database.infra.instances.all().order_by('shard', 'id')
    for instance in instances:
        host = instance.hostname
        if host in hosts:
            continue

        hp = Provider(instance, environment)
        try:
            host_info = hp.host_info(host)
        except Exception as e:
            LOG.error("Could get host info {} - {}".format(host, e))
        else:
            host.current_zone = host_info['zone']
        hosts.add(host)
    context['hosts'] = sorted(hosts, key=lambda host: host.hostname)
    context['zones'] = sorted(zones)

    context["environments"] = set()
    for group in environment.groups.all():
        for env in group.environments.all():
            context["environments"].add(env)
    context["current_environment"] = environment
    context["current_offering"] = database.infra.offering

    from maintenance.models import HostMigrate
    migrates = HostMigrate.objects.filter(host__in=hosts)
    context["last_host_migrate"] = migrates.last()
    return render_to_response(
        "logical/database/details/migrate_tab.html", context,
        RequestContext(request)
    )
Exemple #4
0
def database_migrate(request, context, database):
    if not database.is_host_migrate_available:
        messages.add_message(request, messages.ERROR,
                             "This database cannot be migrated")
        return database_details(request, database.id)

    environment = database.infra.environment
    if request.POST:
        can_migrate, error = database.can_migrate_host()
        if not can_migrate:
            messages.add_message(request, messages.ERROR, error)
        elif 'host_id' in request.POST:
            host = get_object_or_404(Host, pk=request.POST.get('host_id'))
            zone = request.POST["new_zone"]
            TaskRegister.host_migrate(host, zone, environment, request.user)
        elif 'new_environment' in request.POST:
            environment = get_object_or_404(
                Environment, pk=request.POST.get('new_environment'))
            offering = get_object_or_404(Offering,
                                         pk=request.POST.get('new_offering'))
            if environment not in offering.environments.all():
                messages.add_message(
                    request, messages.ERROR,
                    "There is no offering {} to {} environment".format(
                        offering, environment))
                return

            hosts_zones = OrderedDict()
            data = json.loads(request.POST.get('hosts_zones'))
            for host_id, zone in data.items():
                host = get_object_or_404(Host, pk=host_id)
                hosts_zones[host] = zone
            if not hosts_zones:
                messages.add_message(request, messages.ERROR,
                                     "There is no host to migrate")
            else:
                TaskRegister.database_migrate(database, environment, offering,
                                              request.user, hosts_zones)
        return

    hosts = set()
    zones = set()
    instances = database.infra.instances.all().order_by('shard', 'id')
    for instance in instances:
        host = instance.hostname
        if host in hosts:
            continue

        hp = Provider(instance, environment)
        try:
            host_info = hp.host_info(host)
        except Exception as e:
            LOG.error("Could get host info {} - {}".format(host, e))
        else:
            host.current_zone = host_info['zone']
        hosts.add(host)
    context['hosts'] = sorted(hosts, key=lambda host: host.hostname)
    context['zones'] = sorted(zones)

    context["environments"] = set()
    for group in environment.groups.all():
        for env in group.environments.all():
            context["environments"].add(env)
    context["current_environment"] = environment
    context["current_offering"] = database.infra.offering

    from maintenance.models import HostMigrate
    migrates = HostMigrate.objects.filter(host__in=hosts)
    context["last_host_migrate"] = migrates.last()
    return render_to_response("logical/database/details/migrate_tab.html",
                              context, RequestContext(request))