Esempio n. 1
0
 def form_valid(self, *args, **kwargs):
     try:
         form=kwargs['form']
         user=self.request.user
         ec2_pool = EC2Pool.objects.get(id=kwargs['pool_id'])
         assert ec2_pool.vpc.access_key.user == self.request.user
         ec2_tools.refresh_pool(ec2_pool)
         
         nodes_to_terminate = form.cleaned_data['nodes_to_terminate']
         instance_type = form.cleaned_data['instance_type']
         if instance_type == '-': instance_type = None
         pricing = form.cleaned_data['pricing']
         spot_price_order = form.cleaned_data['spot_price_order']
         spot_price_custom = form.cleaned_data['spot_price_custom']
         
         
         errors = ec2_tools.scale_down(ec2_pool, nodes_to_terminate, instance_type, pricing, spot_price_order, spot_price_custom)
         ec2_pool.save()
         if errors:
             self.request.session['errors'] = aws_tools.process_errors(errors)
         self.success_url = reverse_lazy('pool_details', kwargs={'pool_id':ec2_pool.id})
     except Exception, e:
         self.request.session['errors'] = aws_tools.process_errors([e])
         log.exception(e)
         return HttpResponseRedirect(reverse_lazy('pool_details', kwargs={'pool_id':ec2_pool.id}))
def get_local_resources(user, key=None):
    
    overview = ResourceOverview()
    
    ec2_pools = EC2Pool.objects.filter(vpc__access_key__user=user) | EC2Pool.objects.filter(vpc__access_key__copy_of__user=user)
    
    for ec2_pool in ec2_pools:
        ec2_tools.refresh_pool(ec2_pool)
    
    if key:
        keys=[key]
    else:
        keys=AWSAccessKey.objects.filter(user=user) | AWSAccessKey.objects.filter(copy_of__user=user)
    
    for key in keys:
        #EC2 instances
        ec2_instances = EC2Instance.objects.all()#filter(ec2_pool__vpc__access_key=key) | EC2Instance.objects.filter(ec2_pool__vpc__access_key__copy_of=key)
        #ec2_instances = EC2Instance.objects.filter(ec2_pool__id__in=ec2_pool_ids)
        running_instances = ec2_instances.filter(state='pending') | ec2_instances.filter(state='running')# | ec2_instances.filter(state='shutting-down')
        
        for instance in running_instances:
            overview.add_ec2_instance(key, instance.instance_id)
        
        
        #Elastic IPs
        elastic_ips = ElasticIP.objects.all()
        
        for elastic_ip in elastic_ips:
            overview.add_elastic_ip(key, elastic_ip.allocation_id, elastic_ip.association_id, None)
        
    return overview
Esempio n. 3
0
    def form_valid(self, *args, **kwargs):
        try:
            form=kwargs['form']
            user=self.request.user
            ec2_pool = EC2Pool.objects.get(id=kwargs['pool_id'])
            assert ec2_pool.vpc.access_key.user == self.request.user
            ec2_tools.refresh_pool(ec2_pool)
            
            nodes_to_terminate = form.cleaned_data['nodes_to_terminate']
            instance_type = form.cleaned_data['instance_type']
            if instance_type == '-': instance_type = None
            pricing = form.cleaned_data['pricing']
            spot_price_order = form.cleaned_data['spot_price_order']
            spot_price_custom = form.cleaned_data['spot_price_custom']
            
            
            errors = ec2_tools.scale_down(ec2_pool, nodes_to_terminate, instance_type, pricing, spot_price_order, spot_price_custom)
            ec2_pool.save()
            if errors:
                self.request.session['errors'] = aws_tools.process_errors(errors)
            self.success_url = reverse_lazy('pool_details', kwargs={'pool_id':ec2_pool.id})
        except Exception as e:
            self.request.session['errors'] = aws_tools.process_errors([e])
            log.exception(e)
            return HttpResponseRedirect(reverse_lazy('pool_details', kwargs={'pool_id':ec2_pool.id}))

        
        
        return super(EC2PoolScaleDownView, self).form_valid(*args, **kwargs)
Esempio n. 4
0
    def form_valid(self, *args, **kwargs):
        try:
            form=kwargs['form']
            user=self.request.user
            ec2_pool = EC2Pool.objects.get(id=kwargs['pool_id'])
            assert ec2_pool.vpc.access_key.user == self.request.user
            ec2_tools.refresh_pool(ec2_pool)
            extra_nodes=form.cleaned_data['instances_to_add']
            spot_price = form.cleaned_data['pricing'] == 'spot'
            spot_bid_price = form.cleaned_data['spot_bid_price']
            instance_type = form.cleaned_data['initial_instance_type']
            
            errors = ec2_tools.scale_up(ec2_pool=ec2_pool,
                               extra_nodes=extra_nodes,
                               instance_type=instance_type,
                               spot=spot_price,
                               spot_bid_price=spot_bid_price)
            ec2_pool.save()
            self.request.session['errors'] = aws_tools.process_errors(errors)

        except Exception as e:
            self.request.session['errors'] = aws_tools.process_errors([e])
            log.exception(e)
            return HttpResponseRedirect(reverse_lazy('pool_details', kwargs={'pool_id':ec2_pool.id}))

        
        self.success_url = reverse_lazy('pool_details', kwargs={'pool_id':ec2_pool.id})
        return super(EC2PoolScaleUpView, self).form_valid(*args, **kwargs)
Esempio n. 5
0
def refresh_all_ec2_pools():
    """Refresh all ec2 pools
    """
    log.debug('Refreshing all EC2 pools')
    pools = EC2Pool.objects.all() #Get all pools indiscriminately
    
    for ec2_pool in pools:
        try:
            ec2_tools.refresh_pool(ec2_pool)
        except Exception, e:
            log.exception(e)
Esempio n. 6
0
 def dispatch(self, request, *args, **kwargs):
     kwargs['show_loading_screen'] = True
     kwargs['loading_title'] = 'Scaling pool'
     kwargs['loading_description'] = 'Please be patient and do not navigate away from this page. This process can take several minutes'
     kwargs['scale_up']=True
     ec2_pool = EC2Pool.objects.get(id=kwargs['pool_id'])
     kwargs['pool'] = ec2_pool 
     assert ec2_pool.vpc.access_key.user == request.user
     ec2_tools.refresh_pool(ec2_pool)
     
     return super(EC2PoolScaleUpView, self).dispatch(request, *args, **kwargs)
Esempio n. 7
0
def refresh_all_ec2_pools():
    """Refresh all ec2 pools
    """
    log.debug('Refreshing all EC2 pools')
    pools = EC2Pool.objects.all()  #Get all pools indiscriminately

    for ec2_pool in pools:
        try:
            ec2_tools.refresh_pool(ec2_pool)
        except Exception as e:
            log.exception(e)
Esempio n. 8
0
 def dispatch(self, request, *args, **kwargs):
     kwargs['show_loading_screen'] = True
     kwargs['loading_title'] = 'Scaling pool'
     kwargs['loading_description'] = 'Please be patient and do not navigate away from this page. This process can take several minutes'
     kwargs['scale_up']=True
     ec2_pool = EC2Pool.objects.get(id=kwargs['pool_id'])
     kwargs['pool'] = ec2_pool 
     assert ec2_pool.vpc.access_key.user == request.user
     ec2_tools.refresh_pool(ec2_pool)
     
     return super(EC2PoolScaleUpView, self).dispatch(request, *args, **kwargs)
Esempio n. 9
0
 def dispatch(self, request, *args, **kwargs):
     
     
     ec2_pools = EC2Pool.objects.filter(user=request.user, copy_of__isnull=True)
     
     for ec2_pool in ec2_pools:
         ec2_tools.refresh_pool(ec2_pool)
     
     kwargs['ec2_pools'] = ec2_pools
     
     
     bosco_pools = BoscoPool.objects.filter(user=request.user, copy_of__isnull=True)
     kwargs['bosco_pools'] = bosco_pools
     
     
     shared_pools = CondorPool.objects.filter(user=request.user, copy_of__isnull=False)
     kwargs['shared_pools'] = shared_pools
     
     
     return RestrictedView.dispatch(self, request, *args, **kwargs)
Esempio n. 10
0
 def dispatch(self, request, *args, **kwargs):
     
     
     ec2_pools = EC2Pool.objects.filter(user=request.user, copy_of__isnull=True)
     
     for ec2_pool in ec2_pools:
         ec2_tools.refresh_pool(ec2_pool)
     
     kwargs['ec2_pools'] = ec2_pools
     
     
     bosco_pools = BoscoPool.objects.filter(user=request.user, copy_of__isnull=True)
     kwargs['bosco_pools'] = bosco_pools
     
     
     shared_pools = CondorPool.objects.filter(user=request.user, copy_of__isnull=False)
     kwargs['shared_pools'] = shared_pools
     
     
     return RestrictedView.dispatch(self, request, *args, **kwargs)
def get_local_resources(user, key=None):

    overview = ResourceOverview()

    ec2_pools = EC2Pool.objects.filter(
        vpc__access_key__user=user) | EC2Pool.objects.filter(
            vpc__access_key__copy_of__user=user)

    for ec2_pool in ec2_pools:
        ec2_tools.refresh_pool(ec2_pool)

    if key:
        keys = [key]
    else:
        keys = AWSAccessKey.objects.filter(
            user=user) | AWSAccessKey.objects.filter(copy_of__user=user)

    for key in keys:
        #EC2 instances
        ec2_instances = EC2Instance.objects.all(
        )  #filter(ec2_pool__vpc__access_key=key) | EC2Instance.objects.filter(ec2_pool__vpc__access_key__copy_of=key)
        #ec2_instances = EC2Instance.objects.filter(ec2_pool__id__in=ec2_pool_ids)
        running_instances = ec2_instances.filter(
            state='pending') | ec2_instances.filter(
                state='running'
            )  # | ec2_instances.filter(state='shutting-down')

        for instance in running_instances:
            overview.add_ec2_instance(key, instance.instance_id)

        #Elastic IPs
        elastic_ips = ElasticIP.objects.all()

        for elastic_ip in elastic_ips:
            overview.add_elastic_ip(key, elastic_ip.allocation_id,
                                    elastic_ip.association_id, None)

    return overview
Esempio n. 12
0
    def form_valid(self, *args, **kwargs):
        try:
            form=kwargs['form']
            user=self.request.user
            ec2_pool = EC2Pool.objects.get(id=kwargs['pool_id'])
            assert ec2_pool.vpc.access_key.user == self.request.user
            ec2_tools.refresh_pool(ec2_pool)
            extra_nodes=form.cleaned_data['instances_to_add']
            spot_price = form.cleaned_data['pricing'] == 'spot'
            spot_bid_price = form.cleaned_data['spot_bid_price']
            instance_type = form.cleaned_data['initial_instance_type']
            
            errors = ec2_tools.scale_up(ec2_pool=ec2_pool,
                               extra_nodes=extra_nodes,
                               instance_type=instance_type,
                               spot=spot_price,
                               spot_bid_price=spot_bid_price)
            ec2_pool.save()
            self.request.session['errors'] = aws_tools.process_errors(errors)

        except Exception, e:
            self.request.session['errors'] = aws_tools.process_errors([e])
            log.exception(e)
            return HttpResponseRedirect(reverse_lazy('pool_details', kwargs={'pool_id':ec2_pool.id}))
Esempio n. 13
0
    def dispatch(self, request, *args, **kwargs):
        
        pool = CondorPool.objects.get(id=kwargs['pool_id'])
        
        #Recast the pool type
        if pool.get_pool_type() == 'ec2':
            pool = EC2Pool.objects.get(id=pool.id)
        elif pool.get_pool_type() == 'bosco':
            pool = BoscoPool.objects.get(id=pool.id)
        
        kwargs['pool'] = pool
        
        
        assert isinstance(pool, CondorPool)
        assert pool.user == self.request.user
        
        if pool.copy_of != None:
            pool_type = 'shared'
            #Recast the original pool type to be the same as the current pool type
            original_pool = pool.__class__.objects.get(id=pool.copy_of.id)
            kwargs['original_pool'] = original_pool
        elif pool.get_pool_type() == 'ec2':
            pool_type = 'ec2'
            kwargs['original_pool'] = pool
        else:
            pool_type = 'bosco'
            
        kwargs['pool_type'] = pool_type
        
        tasks = Task.objects.filter(condor_pool=pool)
        kwargs['tasks']=tasks

        
        #Decide on which buttons to display
        buttons = {}
        #All pools have the following:
        buttons[0] = {'button_text': 'Remove pool', #Rename this later for EC2 pools
                      'url': reverse_lazy('pool_remove', kwargs={'pool_id' : kwargs['pool_id']}),
                      'class':'button button-narrow button-alt',
                      }
        
        buttons[1] = {'button_text' : 'Test pool',
                      'url': reverse_lazy('pool_test_result', kwargs={'pool_id' : kwargs['pool_id']}),
                      'loading_screen': True,
                      }
        
        if pool_type != 'shared':
            buttons[2] = {'button_text' : 'Share pool',
                          'url': reverse_lazy('pool_share', kwargs={'pool_id' : kwargs['pool_id']}),
                          }
        
        buttons[3] = {'button_text' : 'Rename pool',
                      'url': reverse_lazy('pool_rename', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
        
        if pool_type != 'shared' and pool_type != 'bosco':
            buttons[4] = {'button_text' : 'Scale up',
                      'url': reverse_lazy('ec2_pool_scale_up', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
            buttons[5] = {'button_text' : 'Scale down',
                      'url': reverse_lazy('ec2_pool_scale_down', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
            
            buttons[6] = {'button_text' : 'Change termination settings',
                      'url': reverse_lazy('pool_termination_settings', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
        if pool_type != 'shared' and pool_type == 'bosco':
            buttons[4] = {'button_text' : 'Change status page link',
                          'url': reverse_lazy('pool_link_change',
                          kwargs={'pool_id' : kwargs['pool_id']})}
        
        if pool_type == 'shared':
            kwargs['shared'] = True
            
            if original_pool.get_pool_type() == 'ec2':
                kwargs['shared_pool_type'] = 'ec2'
                instances=EC2Instance.objects.filter(ec2_pool=original_pool)
            
                try:
                    master_id = original_pool.master.id
                except:
                    master_id=None
            
                compute_instances = instances.exclude(id=master_id)
        
                kwargs['instances'] = instances
                kwargs['compute_instances'] = compute_instances
    #            kwargs['ec2_pool'] = ec2_pool
                
            else:
                kwargs['shared_pool_type'] = 'bosco'
            
        
        
        elif pool_type == 'ec2':
            #Recast the pool as an EC2 object
            pool = EC2Pool.objects.get(id=pool.id)
            kwargs['pool'] = pool
            buttons[0]['button_text'] = 'Terminate pool'
            
            try:
                assert pool.vpc.access_key.user == request.user
                ec2_tools.refresh_pool(pool)
            except EC2ResponseError, e:
                request.session['errors'] = [error for error in e.errors]
                log.exception(e)
                return HttpResponseRedirect(reverse_lazy('pool_list'))
            except Exception, e:
                self.request.session['errors'] = [e]
                log.exception(e)
                return HttpResponseRedirect(reverse_lazy('pool_list'))
Esempio n. 14
0
    def dispatch(self, request, *args, **kwargs):
        
        pool = CondorPool.objects.get(id=kwargs['pool_id'])
        
        #Recast the pool type
        if pool.get_pool_type() == 'ec2':
            pool = EC2Pool.objects.get(id=pool.id)
        elif pool.get_pool_type() == 'bosco':
            pool = BoscoPool.objects.get(id=pool.id)
        
        kwargs['pool'] = pool
        
        
        assert isinstance(pool, CondorPool)
        assert pool.user == self.request.user
        
        if pool.copy_of != None:
            pool_type = 'shared'
            #Recast the original pool type to be the same as the current pool type
            original_pool = pool.__class__.objects.get(id=pool.copy_of.id)
            kwargs['original_pool'] = original_pool
        elif pool.get_pool_type() == 'ec2':
            pool_type = 'ec2'
            kwargs['original_pool'] = pool
        else:
            pool_type = 'bosco'
            
        kwargs['pool_type'] = pool_type
        
        tasks = Task.objects.filter(condor_pool=pool)
        kwargs['tasks']=tasks

        
        #Decide on which buttons to display
        buttons = {}
        #All pools have the following:
        buttons[0] = {'button_text': 'Remove pool', #Rename this later for EC2 pools
                      'url': reverse_lazy('pool_remove', kwargs={'pool_id' : kwargs['pool_id']}),
                      'class':'button button-narrow button-alt',
                      }
        
        buttons[1] = {'button_text' : 'Test pool',
                      'url': reverse_lazy('pool_test_result', kwargs={'pool_id' : kwargs['pool_id']}),
                      'loading_screen': True,
                      }
        
        if pool_type != 'shared':
            buttons[2] = {'button_text' : 'Share pool',
                          'url': reverse_lazy('pool_share', kwargs={'pool_id' : kwargs['pool_id']}),
                          }
        
        buttons[3] = {'button_text' : 'Rename pool',
                      'url': reverse_lazy('pool_rename', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
        
        if pool_type != 'shared' and pool_type != 'bosco':
            buttons[4] = {'button_text' : 'Scale up',
                      'url': reverse_lazy('ec2_pool_scale_up', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
            buttons[5] = {'button_text' : 'Scale down',
                      'url': reverse_lazy('ec2_pool_scale_down', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
            
            buttons[6] = {'button_text' : 'Change termination settings',
                      'url': reverse_lazy('pool_termination_settings', kwargs={'pool_id' : kwargs['pool_id']}),
                       }
        if pool_type != 'shared' and pool_type == 'bosco':
            buttons[4] = {'button_text' : 'Change status page link',
                          'url': reverse_lazy('pool_link_change',
                          kwargs={'pool_id' : kwargs['pool_id']})}
        
        if pool_type == 'shared':
            kwargs['shared'] = True
            
            if original_pool.get_pool_type() == 'ec2':
                kwargs['shared_pool_type'] = 'ec2'
                instances=EC2Instance.objects.filter(ec2_pool=original_pool)
            
                try:
                    master_id = original_pool.master.id
                except:
                    master_id=None
            
                compute_instances = instances.exclude(id=master_id)
        
                kwargs['instances'] = instances
                kwargs['compute_instances'] = compute_instances
    #            kwargs['ec2_pool'] = ec2_pool
                
            else:
                kwargs['shared_pool_type'] = 'bosco'
            
        
        
        elif pool_type == 'ec2':
            #Recast the pool as an EC2 object
            pool = EC2Pool.objects.get(id=pool.id)
            kwargs['pool'] = pool
            buttons[0]['button_text'] = 'Terminate pool'
            
            try:
                assert pool.vpc.access_key.user == request.user
                ec2_tools.refresh_pool(pool)
            except EC2ResponseError as e:
                request.session['errors'] = [error for error in e.errors]
                log.exception(e)
                return HttpResponseRedirect(reverse_lazy('pool_list'))
            except Exception as e:
                self.request.session['errors'] = [e]
                log.exception(e)
                return HttpResponseRedirect(reverse_lazy('pool_list'))
            
            instances=EC2Instance.objects.filter(ec2_pool=pool)
            active_instances = instances.filter(state='running')
            not_terminated_instances = instances.exclude(state='terminated').exclude(instance_role='master')
            terminated_instances = instances.filter(state='terminated')
            
            spot_requests = SpotRequest.objects.filter(ec2_pool=pool)
            fulfilled_spot_requests = spot_requests.filter(status_code='fulfilled')
            
            try:
                master_id = pool.master.id
            except:
                master_id=None
            
            compute_instances = instances.exclude(id=master_id)
            
            kwargs['instances'] = instances
            kwargs['active_instances']= active_instances
            kwargs['not_terminated_instances'] = not_terminated_instances
            kwargs['terminated_instances'] = terminated_instances
            kwargs['compute_instances'] = compute_instances
            kwargs['spot_requests'] = spot_requests
            kwargs['fulfilled_spot_requests'] = fulfilled_spot_requests
        else:
            #Pool type is bosco
            pass
        
        
        
        
        #Text for pool test screen
        kwargs['show_loading_screen'] = True
        kwargs['loading_title'] = 'Testing pool'
        kwargs['loading_description'] = 'Please be patient and do not navigate away from this page. Testing a pool can take several minutes.'
        kwargs['buttons'] = buttons
        
        return super(PoolDetailsView, self).dispatch(request, *args, **kwargs)