Пример #1
0
    def run(self, args):
        servers = dict([(x.name, x) for x in clusto.get_entities(clusto_types=['server']) if x.name != 'default']) # Don't even consider the 'default' object.

        instances = []
        reasons = {}

        http = httplib2.Http()
        http.add_credentials(*os.environ['AMAZINGHORSE_CREDS'].split(':', 1))
        for region in ('us-east-1', 'us-west-1'):
            resp, content = http.request('https://amazinghorse.simplegeo.com:4430/aws/ec2/%s/instance/' % region)
            for instance in json.loads(content):
                if instance['state'] == 'running':
                    instances.append(instance['id'])
                else:
                    if 'reason' in instance:
                        reasons[instance['id']] = instance['reason']

        output = []
        for server in servers:
            if not server in instances:
                print 'Instance: %s' % server
                print 'IP: %s' % ' '.join(servers[server].attr_values(key='ip', subkey='ipstring'))
                print 'Parents: %s' % ' '.join([x.name for x in servers[server].parents()])
                if server in reasons:
                    print 'Termination reason: %s' % reasons[server]
                clusto.delete_entity(servers[server].entity)
Пример #2
0
def ngi_delete_image(request, image_name):
    """Delete an NGI image.
    
    The specified image must not be associated with any hosts.
    
    Returns:
        None
    
    Arguments:
        image_name -- the name of the image to delete
            
    Exceptions Raised:
        JinxDataNotFoundError -- No image with the specified name exists.
        JinxInvalidStateError -- One or more hosts are associated with the
            image.
        JinxInvalidRequestError -- The specified image is not an NGI image.
    """
    
    image = _get_image(image_name)
        
    hosts = image.get_hosts_associated_with()
    if hosts:
        raise JinxInvalidStateError("%s cannot be deleted because %d hosts are associated with it." % (image_name, len(hosts)))
    
    clusto.delete_entity(image.entity)
Пример #3
0
    def delete_action(self, request, match):
        name = request.path_info.strip('/')
        if name.count('/') != 1:
            return Response(status=400, body='400 Bad Request\nYou may only delete objects, not types or actions\n')
        objtype, objname = name.split('/', 1)

        try:
            obj = clusto.get_by_name(objname)
        except LookupError:
            return Response(status=404, body='404 Not Found\n')

        clusto.delete_entity(obj.entity)
        return Response(status=200, body='200 OK\nObject deleted\n')
Пример #4
0
    def delete_action(self, request, match):
        name = request.path_info.strip('/')
        if name.count('/') != 1:
            return Response(status=400, body='400 Bad Request\nYou may only delete objects, not types or actions\n')
        objtype, objname = name.split('/', 1)

        try:
            obj = clusto.get_by_name(objname)
        except LookupError:
            return Response(status=404, body='404 Not Found\n')

        clusto.delete_entity(obj.entity)
        return Response(status=200, body='200 OK\nObject deleted\n')
Пример #5
0
    def testDeleteEntity(self):

        e1 = Entity.query().filter_by(name=u'e1').one()

        d = Driver(e1)

        d.add_attr('deltest1', 'test')
        d.add_attr('deltest1', 'testA')

        clusto.delete_entity(e1)

        self.assertEqual([], clusto.get_entities(names=['e1']))

        self.assertEqual([], Driver.do_attr_query(key='deltest*', glob=True))
Пример #6
0
    def run_delete(self, args):
        '''
        Deletes a pool
        '''

        p = self._get_pool(args.pool[0])
        if not p:
            return -1
        sys.stdout.write('Are you sure you want to delete the pool %s (yes/NO)? ' % p.name)
        answer = sys.stdin.readline()
        if answer.strip() == 'yes':
            try:
                clusto.delete_entity(p.entity)
                return 0
            except Exception, e:
                self.error(e)
                return 3
Пример #7
0
    def testDeleteEntity(self):

        e1 = Entity.query().filter_by(name=u'e1').one()

        d = Driver(e1)

        d.add_attr('deltest1', 'test')
        d.add_attr('deltest1', 'testA')



        clusto.delete_entity(e1)


        self.assertEqual([], clusto.get_entities(names=['e1']))

        self.assertEqual([], Driver.do_attr_query(key='deltest*', glob=True))
Пример #8
0
    def run_delete(self, args):
        '''
        Deletes a pool
        '''

        p = self._get_pool(args.pool[0])
        if not p:
            return -1
        sys.stdout.write(
            'Are you sure you want to delete the pool %s (yes/NO)? ' % p.name)
        answer = sys.stdin.readline()
        if answer.strip() == 'yes':
            try:
                clusto.delete_entity(p.entity)
                return 0
            except Exception, e:
                self.error(e)
                return 3