예제 #1
0
def request_pool(request):
    if not request.user.is_authenticated():
        return go_home(request)
    try:
        group = request.POST["stream"]
        version = request.POST["version"]
        if version == "latest":
            version = None
        date = request.POST["date"]
        if date == "latest":
            date = None
        provider = request.POST["provider"]
        if provider == "any":
            provider = None
        preconfigured = request.POST.get("preconfigured",
                                         "false").lower() == "true"
        yum_update = request.POST.get("yum_update", "false").lower() == "true"
        count = int(request.POST["count"])
        lease_time = 60
        pool_id = AppliancePool.create(request.user, group, version, date,
                                       provider, count, lease_time,
                                       preconfigured, yum_update).id
        messages.success(request, "Pool requested - id {}".format(pool_id))
    except Exception as e:
        messages.error(
            request,
            "Exception {} happened: {}".format(type(e).__name__, str(e)))
    return go_back_or_home(request)
예제 #2
0
def request_pool(request):
    try:
        group = request.POST["stream"]
        version = request.POST["version"]
        if version == "latest":
            version = None
        date = request.POST["date"]
        if date == "latest":
            date = None
        provider = request.POST["provider"]
        if provider == "any":
            provider = None
        preconfigured = request.POST.get("preconfigured", "false").lower() == "true"
        yum_update = request.POST.get("yum_update", "false").lower() == "true"
        container = request.POST.get("container", "false").lower() == "true"
        if container:
            # Container is preconfigured only
            # We need to do this as the disabled checkbox for Preconfigured seems to not return
            # the proper value.
            preconfigured = True
        count = int(request.POST["count"])
        lease_time = int(request.POST.get("expiration", 60))
        pool_id = AppliancePool.create(
            request.user, group, version, date, provider, count, lease_time, preconfigured,
            yum_update, container).id
        messages.success(request, "Pool requested - id {}".format(pool_id))
    except Exception as e:
        messages.warning(request, "{}: {}".format(type(e).__name__, e))
    return go_back_or_home(request)
예제 #3
0
파일: views.py 프로젝트: jaryn/cfme_tests
def request_pool(request):
    if not request.user.is_authenticated():
        return go_home(request)
    try:
        group = request.POST["stream"]
        version = request.POST["version"]
        if version == "latest":
            version = None
        date = request.POST["date"]
        if date == "latest":
            date = None
        provider = request.POST["provider"]
        if provider == "any":
            provider = None
        preconfigured = request.POST.get("preconfigured", "false").lower() == "true"
        yum_update = request.POST.get("yum_update", "false").lower() == "true"
        count = int(request.POST["count"])
        lease_time = int(request.POST.get("expiration", 60))
        pool_id = AppliancePool.create(
            request.user, group, version, date, provider, count, lease_time, preconfigured,
            yum_update).id
        messages.success(request, "Pool requested - id {}".format(pool_id))
    except Exception as e:
        messages.error(request, "Exception {} happened: {}".format(type(e).__name__, str(e)))
    return go_back_or_home(request)
예제 #4
0
def request_appliances(
        user, group, count=1, lease_time=60, version=None, date=None, provider=None,
        preconfigured=True, yum_update=False):
    """Request a number of appliances."""
    if date:
        date = datetime.strptime(date, "%y%m%d")
    return AppliancePool.create(
        user, group, version, date, provider, count, lease_time, preconfigured, yum_update).id
예제 #5
0
파일: api.py 프로젝트: vprusa/cfme_tests
def request_appliances(
        user, group, count=1, lease_time=60, version=None, date=None, provider=None,
        preconfigured=True, yum_update=False):
    """Request a number of appliances."""
    if date:
        date = datetime.strptime(date, "%y%m%d")
    return AppliancePool.create(
        user, group, version, date, provider, count, lease_time, preconfigured, yum_update).id
예제 #6
0
def request_appliances(
        user, group, count=1, lease_time=60, version=None, date=None, provider=None,
        preconfigured=True, yum_update=False, ram=None, cpu=None,
        provider_type=None, template_type=Template.DEFAULT_TEMPLATE_TYPE):
    """Request a number of appliances."""
    if date:
        date = datetime.strptime(date, "%y%m%d")
    return AppliancePool.create(
        user, group, version, date, provider, count, lease_time, preconfigured, yum_update,
        ram, cpu, provider_type, template_type).id
예제 #7
0
파일: api.py 프로젝트: akarol/cfme_tests
def request_appliances(
        user, group, count=1, lease_time=60, version=None, date=None, provider=None,
        preconfigured=True, yum_update=False, ram=None, cpu=None,
        provider_type=None, template_type=Template.DEFAULT_TEMPLATE_TYPE):
    """Request a number of appliances."""
    if date:
        date = datetime.strptime(date, "%y%m%d")
    return AppliancePool.create(
        user, group, version, date, provider, count, lease_time, preconfigured, yum_update,
        ram, cpu, provider_type, template_type).id
예제 #8
0
파일: admin.py 프로젝트: seandst/cfme_tests
 def request_pool(self, request, groups):
     number_appliances = int(request.POST.get('number_appliances', 1))
     if number_appliances < 1:
         self.message_user(request, "Number of appliances should >= 1!")
         return
     for group in groups:
         pool = AppliancePool.create(request.user, group, num_appliances=number_appliances)
         self.message_user(request, "Appliance pool {} was requested!".format(pool.id))
         self.logger.info(
             "User {}/{} requested appliance pool {}".format(
                 request.user.pk, request.user.username, pool.id))
예제 #9
0
 def request_pool(self, request, groups):
     number_appliances = int(request.POST.get('number_appliances', 1))
     if number_appliances < 1:
         self.message_user(request, "Number of appliances should >= 1!")
         return
     for group in groups:
         pool = AppliancePool.create(request.user,
                                     group,
                                     num_appliances=number_appliances)
         self.message_user(
             request, "Appliance pool {} was requested!".format(pool.id))
         self.logger.info("User {}/{} requested appliance pool {}".format(
             request.user.pk, request.user.username, pool.id))
예제 #10
0
def request_pool(request):
    try:
        group = request.POST["stream"]
        version = request.POST["version"]
        if version == "latest":
            version = None
        date = request.POST["date"]
        if date == "latest":
            date = None
        provider = request.POST["provider"]
        if provider == "any":
            provider = None
        preconfigured = request.POST.get("preconfigured", "false").lower() == "true"
        yum_update = request.POST.get("yum_update", "false").lower() == "true"
        container = request.POST.get("container", "false").lower() == "true"
        provider_type = request.POST.get("provider_type", "any").lower()
        if not provider_type or provider_type == 'any':
            provider_type = None
        if container:
            # Container is preconfigured only
            # We need to do this as the disabled checkbox for Preconfigured seems to not return
            # the proper value.
            preconfigured = True
        count = int(request.POST["count"])
        lease_time = int(request.POST.get("expiration", 60))
        ram = None
        cpu = None
        if request.user.has_perm('appliances.can_modify_hw'):
            if 'ram' in request.POST:
                ram = int(request.POST['ram'])
            if 'cpu' in request.POST:
                cpu = int(request.POST['cpu'])
        pool_id = AppliancePool.create(
            request.user, group, version, date, provider, count, lease_time, preconfigured,
            yum_update, container, ram, cpu, provider_type).id
        messages.success(request, "Pool requested - id {}".format(pool_id))
    except Exception as e:
        messages.warning(request, "{}: {}".format(type(e).__name__, e))
    return go_back_or_home(request)
예제 #11
0
def request_pool(request):
    try:
        group = request.POST["stream"]
        version = request.POST["version"]
        template_type = request.POST["template_type"]
        if version == "latest":
            version = None
        date = request.POST["date"]
        if date == "latest":
            date = None
        provider = request.POST["provider"]
        if provider == "any":
            provider = None
        preconfigured = request.POST.get("preconfigured", "false").lower() == "true"
        yum_update = request.POST.get("yum_update", "false").lower() == "true"
        provider_type = request.POST.get("provider_type", "any").lower()
        if not provider_type or provider_type == 'any':
            provider_type = None

        count = int(request.POST["count"])
        lease_time = int(request.POST.get("expiration", 60))
        ram = None
        cpu = None
        if request.user.has_perm('appliances.can_modify_hw'):
            if 'ram' in request.POST:
                ram = int(request.POST['ram'])
            if 'cpu' in request.POST:
                cpu = int(request.POST['cpu'])

        pool_id = AppliancePool.create(
            request.user, group, version, date, provider, count, lease_time, preconfigured,
            yum_update, ram, cpu, provider_type, template_type).id
        messages.success(request, "Pool requested - id {}".format(pool_id))
    except Exception as e:
        messages.warning(request, "{}: {}".format(type(e).__name__, e))
    return go_back_or_home(request)
예제 #12
0
def synchronize_untracked_vms_in_provider(self, provider_id):
    """'re'-synchronizes any vms that might be lost during outages."""
    provider = Provider.objects.get(id=provider_id, working=True, disabled=False)
    provider_api = provider.api
    if not hasattr(provider_api, 'list_vms'):
        # This provider does not have VMs
        return
    for vm in sorted(provider_api.list_vms(), key=lambda pvm: getattr(pvm, 'name', pvm)):
        if (
                Appliance.objects.filter(name=getattr(vm, 'name', vm),
                                         template__provider=provider).count() != 0
        ):
            continue
        # We have an untracked VM. Let's investigate
        try:
            appliance_id = vm.get_meta_value('sprout_id')
        except KeyError:
            continue
        except (AttributeError, NotImplementedError):
            # Do not bother if not implemented in the VM object's API
            return

        # just check it again ...
        if Appliance.objects.filter(id=appliance_id).count() == 1:
            # For some reason it is already in
            continue

        # Now it appears that this is a VM that was in Sprout
        construct = {'id': appliance_id}
        # Retrieve appliance data
        try:
            self.logger.info('Trying to reconstruct appliance %d/%s', appliance_id, vm.name)
            construct['name'] = vm.name
            template_id = vm.get_meta_value('sprout_source_template_id')
            # Templates are not deleted from the DB so this should be OK.
            construct['template'] = Template.objects.get(id=template_id)
            construct['name'] = vm.name
            construct['ready'] = vm.get_meta_value('sprout_ready')
            construct['description'] = vm.get_meta_value('sprout_description')
            construct['lun_disk_connected'] = vm.get_meta_value('sprout_lun_disk_connected')
            construct['swap'] = vm.get_meta_value('sprout_swap')
            construct['ssh_failed'] = vm.get_meta_value('sprout_ssh_failed')
            # Time fields
            construct['datetime_leased'] = parsedate(vm.get_meta_value('sprout_datetime_leased'))
            construct['leased_until'] = parsedate(vm.get_meta_value('sprout_leased_until'))
            construct['status_changed'] = parsedate(vm.get_meta_value('sprout_status_changed'))
            construct['created_on'] = parsedate(vm.get_meta_value('sprout_created_on'))
            construct['modified_on'] = parsedate(vm.get_meta_value('sprout_modified_on'))
        except KeyError as e:
            self.logger.error('Failed to reconstruct %d/%s', appliance_id, vm.name)
            self.logger.exception(e)
            continue
        # Retrieve pool data if applicable
        try:
            pool_id = vm.get_meta_value('sprout_pool_id')
            pool_construct = dict(id=pool_id)
            pool_construct['total_count'] = vm.get_meta_value('sprout_pool_total_count')
            group_id = vm.get_meta_value('sprout_pool_group')
            pool_construct['group'] = Group.objects.get(id=group_id)
            try:
                construct_provider_id = vm.get_meta_value('sprout_pool_provider')
                pool_construct['provider'] = Provider.objects.get(id=construct_provider_id)
            except (KeyError, ObjectDoesNotExist):
                # optional
                pool_construct['provider'] = None
            pool_construct['version'] = vm.get_meta_value('sprout_pool_version')
            pool_construct['date'] = parsedate(vm.get_meta_value('sprout_pool_appliance_date'))
            owner_id = vm.get_meta_value('sprout_pool_owner_id')
            try:
                owner = User.objects.get(id=owner_id)
            except ObjectDoesNotExist:
                owner_username = vm.get_meta_value('sprout_pool_owner_username')
                owner = User(id=owner_id, username=owner_username)
                owner.save()
            pool_construct['owner'] = owner
            pool_construct['preconfigured'] = vm.get_meta_value('sprout_pool_preconfigured')
            pool_construct['description'] = vm.get_meta_value('sprout_pool_description')
            pool_construct['not_needed_anymore'] = vm.get_meta_value(
                'sprout_pool_not_needed_anymore')
            pool_construct['finished'] = vm.get_meta_value('sprout_pool_finished')
            pool_construct['yum_update'] = vm.get_meta_value('sprout_pool_yum_update')
            try:
                construct['appliance_pool'] = AppliancePool.objects.get(id=pool_id)
            except ObjectDoesNotExist:
                pool = AppliancePool(**pool_construct)
                pool.save()
                construct['appliance_pool'] = pool
        except KeyError:
            pass

        appliance = Appliance(**construct)
        appliance.save()

        # And now, refresh!
        refresh_appliances_provider.delay(provider.id)