示例#1
0
def create_container(request):
    form = CreateContainerForm()
    if request.method == 'POST':
        # save
        form = CreateContainerForm(request.POST)
        if form.is_valid():
            image = form.data.get('image')
            environment = form.data.get('environment')
            command = form.data.get('command')
            memory = form.data.get('memory', 0)
            volume = form.data.get('volume')
            volumes_from = form.data.get('volumes_from')
            if command.strip() == '':
                command = None
            if environment.strip() == '':
                environment = None
            else:
                environment = environment.split()
            if memory.strip() == '':
                memory = 0
            # build volumes
            if volume == '':
                volume = None
            if volume:
                volume = { volume: {}}
            # convert memory from MB to bytes
            if memory:
                memory = int(memory) * 1048576
            ports = form.data.get('ports', '').split()
            hosts = form.data.getlist('hosts')
            private = form.data.get('private')
            privileged = form.data.get('privileged')
            # convert to bool
            if privileged:
                privileged = True
            user = None
            status = False
            for i in hosts:
                host = Host.objects.get(id=i)
                if private:
                    user = request.user
                c_id, status = host.create_container(image, command, ports,
                    environment=environment, memory=memory,
                    description=form.data.get('description'), volumes=volume,
                    volumes_from=volumes_from, privileged=privileged, owner=user)
            if hosts:
                if status:
                    messages.add_message(request, messages.INFO, _('Created') + ' {0}'.format(
                        image))
                else:
                    messages.add_message(request, messages.ERROR,
                        _('Container failed to start'))
            else:
                messages.add_message(request, messages.ERROR, _('No hosts selected'))
            return redirect(reverse('containers.views.index'))
    ctx = {
        'form_create_container': form,
    }
    return render_to_response('containers/create_container.html', ctx,
        context_instance=RequestContext(request))
示例#2
0
def create_container(request):
    form = CreateContainerForm()
    if request.method == 'POST':
        # save
        form = CreateContainerForm(request.POST)
        if form.is_valid():
            image = form.data.get('image')
            environment = form.data.get('environment')
            command = form.data.get('command')
            memory = form.data.get('memory', 0)
            volume = form.data.get('volume')
            volumes_from = form.data.get('volumes_from')
            if command.strip() == '':
                command = None
            if environment.strip() == '':
                environment = None
            else:
                environment = environment.split()
            if memory.strip() == '':
                memory = 0
            # build volumes
            if volume == '':
                volume = None
            if volume:
                volume = { volume: {}}
            # convert memory from MB to bytes
            if memory:
                memory = int(memory) * 1048576
            ports = form.data.get('ports', '').split()
            hosts = form.data.getlist('hosts')
            private = form.data.get('private')
            privileged = form.data.get('privileged')
            # convert to bool
            if privileged:
                privileged = True
            user = None
            status = False
            for i in hosts:
                host = Host.objects.get(id=i)
                if private:
                    user = request.user
                c_id, status = host.create_container(image, command, ports,
                    environment=environment, memory=memory,
                    description=form.data.get('description'), volumes=volume,
                    volumes_from=volumes_from, privileged=privileged, owner=user)
            if hosts:
                if status:
                    messages.add_message(request, messages.INFO, _('Created') + ' {0}'.format(
                        image))
                else:
                    messages.add_message(request, messages.ERROR,
                        _('Container failed to start'))
            else:
                messages.add_message(request, messages.ERROR, _('No hosts selected'))
            return redirect(reverse('containers.views.index'))
    ctx = {
        'form_create_container': form,
    }
    return render_to_response('containers/create_container.html', ctx,
        context_instance=RequestContext(request))
示例#3
0
def create_container(request):
    form = CreateContainerForm()
    if request.method == 'POST':
        # save
        form = CreateContainerForm(request.POST)
        if form.is_valid():
            image = form.data.get('image')
            name = form.data.get('name')
            hostname = form.data.get('hostname')
            description = form.data.get('description')
            environment = form.data.get('environment')
            command = form.data.get('command')
            memory = form.data.get('memory', 0)
            links = form.data.get('links', None)
            volume = form.data.get('volume')
            volumes_from = form.data.get('volumes_from')
            ports = form.data.get('ports', '').split()
            hosts = form.data.getlist('hosts')
            private = form.data.get('private')
            privileged = form.data.get('privileged')
            user = None
            status = False
            for i in hosts:
                host = Host.objects.get(id=i)
                if private:
                    user = request.user
                try:
                    c_id, status = host.create_container(image, command, ports,
                        environment=environment, memory=memory,
                        description=description, volumes=volume,
                        volumes_from=volumes_from, privileged=privileged,
                        links=links, name=name, owner=user,
                        hostname=hostname)
                    messages.add_message(request, messages.INFO, _('Created') + ' {0}'.format(
                        image))
                except Exception, e:
                    print(e)
                    messages.error(request, e)
                    status = False
            if not hosts:
                messages.add_message(request, messages.ERROR, _('No hosts selected'))
            return redirect(reverse('containers.views.index'))
示例#4
0
def create_container(request):
    form = CreateContainerForm()
    if request.method == 'POST':
        # save
        form = CreateContainerForm(request.POST)
        if form.is_valid():
            image = form.data.get('image')
            name = form.data.get('name')
            hostname = form.data.get('hostname')
            description = form.data.get('description')
            environment = form.data.get('environment')
            command = form.data.get('command')
            memory = form.data.get('memory', 0)
            links = form.data.get('links', None)
            volume = form.data.get('volume')
            volumes_from = form.data.get('volumes_from')
            if command.strip() == '':
                command = None
            if environment.strip() == '':
                environment = None
            else:
                environment = shlex.split(environment)
            if memory.strip() == '':
                memory = 0
            # build volumes
            binds = None
            if volume == '':
                volume = None
            if volume:
                if volume.find(':') > -1:
                    mnt, vol = volume.split(':')
                    volume = {vol: {}}
                    binds = {mnt: vol}
                else:
                    volume = {volume: {}}
            # build links
            c_links = {}
            for link in links.split():
                l, n = link.split(':')
                c_links[l] = n
            links = c_links
            # convert memory from MB to bytes
            if memory:
                memory = int(memory) * 1048576
            ports = form.data.get('ports', '').split()
            hosts = form.data.getlist('hosts')
            private = form.data.get('private')
            privileged = form.data.get('privileged')
            # convert to bool
            if privileged:
                privileged = True
            user = None
            status = False
            for i in hosts:
                host = Host.objects.get(id=i)
                if private:
                    user = request.user
                try:
                    c_id, status = host.create_container(
                        image,
                        command,
                        ports,
                        environment=environment,
                        memory=memory,
                        description=description,
                        volumes=volume,
                        volumes_from=volumes_from,
                        privileged=privileged,
                        binds=binds,
                        links=links,
                        name=name,
                        owner=user,
                        hostname=hostname)
                    messages.add_message(request, messages.INFO,
                                         _('Created') + ' {0}'.format(image))
                except Exception, e:
                    messages.error(request, e)
                    status = False
            if not hosts:
                messages.add_message(request, messages.ERROR,
                                     _('No hosts selected'))
            return redirect(reverse('containers.views.index'))
示例#5
0
文件: views.py 项目: Humerus/shipyard
def create_container(request):
    form = CreateContainerForm()
    if request.method == 'POST':
        # save
        form = CreateContainerForm(request.POST)
        if form.is_valid():
            image = form.data.get('image')
            name = form.data.get('name')
            hostname = form.data.get('hostname')
            description = form.data.get('description')
            environment = form.data.get('environment')
            command = form.data.get('command')
            memory = form.data.get('memory', 0)
            links = form.data.get('links', None)
            volume = form.data.get('volume')
            volumes_from = form.data.get('volumes_from')
            if command.strip() == '':
                command = None
            if environment.strip() == '':
                environment = None
            else:
                environment = shlex.split(environment)
            if memory.strip() == '':
                memory = 0
            # build volumes
            binds = None
            if volume == '':
                volume = None
            if volume:
                if volume.find(':') > -1:
                    mnt, vol = volume.split(':')
                    volume = { vol: {}}
                    binds = { mnt: vol }
                else:
                    volume = { volume: {}}
            # build links
            c_links = {}
            for link in links.split():
                l,n = link.split(':')
                c_links[l] = n
            links = c_links
            # convert memory from MB to bytes
            if memory:
                memory = int(memory) * 1048576
            ports = form.data.get('ports', '').split()
            hosts = form.data.getlist('hosts')
            private = form.data.get('private')
            privileged = form.data.get('privileged')
            # convert to bool
            if privileged:
                privileged = True
            user = None
            status = False
            for i in hosts:
                host = Host.objects.get(id=i)
                if private:
                    user = request.user
                try:
                    c_id, status = host.create_container(image, command, ports,
                        environment=environment, memory=memory,
                        description=description, volumes=volume,
                        volumes_from=volumes_from, privileged=privileged,
                        binds=binds, links=links, name=name, owner=user,
                        hostname=hostname)
                    messages.add_message(request, messages.INFO, _('Created') + ' {0}'.format(
                        image))
                except Exception, e:
                    messages.error(request, e)
                    status = False
            if not hosts:
                messages.add_message(request, messages.ERROR, _('No hosts selected'))
            return redirect(reverse('containers.views.index'))