Exemple #1
0
    def create(self, request, *args, **kwargs):
        """ Generates db deployment object """
        d = Deployment()
        s = DeploymentSerializer(d)
        image = request.data['image'].lower()
        image_tag = image
        cookbook = request.data['cookbook']
        user = request.user.username
        recipe = request.data['recipe'] if 'recipe' in request.data.keys() else 'default.rb'
        system = request.data['system'].lower()
        d.cookbook = CookBook.objects.get(name=cookbook, user=user)
        d.recipe = Recipe.objects.get(name=recipe, cookbook=d.cookbook, user=user)
        d.user = str(request.user.username)
        # Detect image
        if ":" in image:
            image_name, image_version = image.split(":")
            try:
                i = Image.objects.get(name=image_name.lower(), version=image_version.lower(), system=system)
                image_tag = i.tag
            except Image.DoesNotExist:
                pass
            except Image.MultipleObjectsReturned:
                return Response({'detail': 'Multiple images found for [%s]' % image}, status=status.HTTP_400_BAD_REQUEST)
        try:
            i = Image.objects.get(tag=image_tag)
        except Image.DoesNotExist:
            return Response({'detail': 'Image not found: [%s]' % image}, status=status.HTTP_400_BAD_REQUEST)
        d.image = i

        d.save()
        return Response(s.data, status=status.HTTP_201_CREATED)
Exemple #2
0
 def create_new_deployment(repo, hash, type):
     #create a new deployment and an async task to parse it
     deployment = Deployment(repo = repo, 
                             hash = hash, 
                             type = type,
                             status = DeploymentStatus.SCHEDULED)
     #save this deployment
     deployment.save()
     
     #the async task will mark this deployment as STARTED
     from async.celery import process_deploy
     process_deploy.delay(deployment)
Exemple #3
0
    def create(self, request, *args, **kwargs):
        """ Generates db deployment object """
        d = Deployment()
        s = DeploymentSerializer(d)
        image = request.data['image'].lower()
        image_tag = image
        cookbook = request.data['cookbook']
        user = request.user.username
        recipe = request.data['recipe'] if 'recipe' in request.data.keys(
        ) else 'default.rb'
        system = request.data['system'].lower()
        d.cookbook = CookBook.objects.get(name=cookbook, user=user)
        d.recipe = Recipe.objects.get(name=recipe,
                                      cookbook=d.cookbook,
                                      user=user)
        d.user = str(request.user.username)
        # Detect image
        if ":" in image:
            image_name, image_version = image.split(":")
            try:
                i = Image.objects.get(name=image_name.lower(),
                                      version=image_version.lower(),
                                      system=system)
                image_tag = i.tag
            except Image.DoesNotExist:
                pass
            except Image.MultipleObjectsReturned:
                return Response(
                    {'detail': 'Multiple images found for [%s]' % image},
                    status=status.HTTP_400_BAD_REQUEST)
        try:
            i = Image.objects.get(tag=image_tag)
        except Image.DoesNotExist:
            return Response({'detail': 'Image not found: [%s]' % image},
                            status=status.HTTP_400_BAD_REQUEST)
        d.image = i

        d.save()
        return Response(s.data, status=status.HTTP_201_CREATED)
Exemple #4
0
            },
            '/opt/techdev/deployr2/deployments/%s/frontend/www' % deployment_name:
            {
                'bind': '/usr/share/nginx/html',
                'ro': True
            }
        })

    inspect = c.inspect_container('frontend_' + deployment_name)
    frontend_port = inspect['NetworkSettings']['Ports']['80/tcp'][0][
        'HostPort']  # Help!!!

    # create an entity so we know of this deployment later
    from django.utils import timezone
    deployment = Deployment(id=deployment_name, create_date=timezone.now())
    deployment.save()

    import augeas
    a = augeas.Augeas(root='/')
    a.defvar('host', '/files/etc/apache2/sites-available/deployr.conf')
    a.defnode('newloc', '$host/VirtualHost/Location[last() + 1]', '')
    a.set('$newloc/arg', '/' + deployment_name)
    a.set('$newloc/directive', 'ProxyPass')
    a.set('$newloc/*[self::directive="ProxyPass"]/arg[1]',
          'http://localhost:' + frontend_port)
    a.save()

    return HttpResponseRedirect(
        reverse('deployr2:deployment',
                kwargs={'deployment_name': deployment_name}))