Ejemplo n.º 1
0
def create_detect(host_id, engine_ip, engine_port, container_id, app_name,
                  app_desc):
    containerinfo = dockerclient.detect(engine_ip, engine_port, container_id)
    if containerinfo:
        app = APPLICATION()
        app.name = app_name
        app.description = app_desc
        app.containerid = container_id
        app.containername = containerinfo['container_name']
        app.image = containerinfo['image']
        app.created = containerinfo['created']
        app.status = containerinfo['status']
        app.engineip = engine_ip
        app.engineport = engine_port
        app.save()
        hosts = Host.objects.filter(id=host_id)
        if hosts:
            host = hosts.first()
            res = Resource()
            res.type = "application"
            res.host = host
            res.resource_id = app.id
            res.save()
Ejemplo n.º 2
0
def auto_detect(engine_ip, engine_port, container_id):
    ip = IP.objects.filter(ipv4__contains=engine_ip)
    if ip:
        containerinfo = dockerclient.detect(engine_ip, engine_port,
                                            container_id)
        if containerinfo:
            app = APPLICATION()
            app.name = "[auto detect]" + containerinfo['container_name']
            app.description = "[auto detect]" + str(
                containerinfo['container_name'])
            app.containerid = container_id
            app.containername = containerinfo['container_name']
            app.image = containerinfo['image']
            app.created = containerinfo['created']
            app.status = containerinfo['status']
            app.engineip = engine_ip
            app.engineport = engine_port
            app.save()
            i = ip.first()
            res = Resource.objects.filter(type='ip', resource_id=i.id)
            host = res.first().host
            res = Resource()
            res.type = "application"
            res.host = host
            res.resource_id = app.id
            res.save()
Ejemplo n.º 3
0
def create_new(engine_ip, engine_port, host_id, name, description, imagename,
               command, entrypoint, container_name, host_name, network_mode,
               privileged, security_opt, ulimit_nofile, ulimit_noproc, ports,
               port_bindings, volume, binds, dns_server, hosts, environment):
    containerinfo = ""
    try:
        containerinfo = dockerclient.create(
            engine_ip, engine_port, imagename, command, entrypoint,
            container_name, host_name, network_mode, privileged, security_opt,
            ulimit_nofile, ulimit_noproc, ports, port_bindings, volume, binds,
            dns_server, hosts, environment)
    except Exception, ex:
        return "create failed" + str(Exception) + ":" + str(ex)
    if containerinfo:
        app = APPLICATION()
        app.name = name
        app.description = description
        app.containerid = containerinfo['container_id']
        app.containername = containerinfo['container_name']
        app.image = containerinfo['image']
        app.created = containerinfo['created']
        app.status = containerinfo['status']
        app.engineip = engine_ip
        app.engineport = engine_port
        app.save()
        hosts = Host.objects.filter(id=host_id)
        if hosts:
            host = hosts.first()
            res = Resource()
            res.type = "application"
Ejemplo n.º 4
0
def create_detect(host_id,engine_ip,engine_port,container_id,app_name,app_desc):
    containerinfo=dockerclient.detect(engine_ip, engine_port, container_id)
    if containerinfo:
        app=APPLICATION()
        app.name=app_name
        app.description=app_desc
        app.containerid=container_id
        app.containername=containerinfo['container_name']
        app.image=containerinfo['image']
        app.created=containerinfo['created']
        app.status=containerinfo['status']
        app.engineip=engine_ip
        app.engineport=engine_port
        app.save()
        hosts=Host.objects.filter(id=host_id)
        if hosts:
            host=hosts.first()
            res=Resource()
            res.type="application"
            res.host=host
            res.resource_id=app.id
            res.save()
Ejemplo n.º 5
0
def auto_detect(engine_ip,engine_port,container_id):
    ip=IP.objects.filter(ipv4__contains=engine_ip)
    if ip:
        containerinfo=dockerclient.detect(engine_ip, engine_port, container_id)
        if containerinfo:
            app=APPLICATION()
            app.name="[auto detect]"+containerinfo['container_name']
            app.description="[auto detect]"+str(containerinfo['container_name'])
            app.containerid=container_id
            app.containername=containerinfo['container_name']
            app.image=containerinfo['image']
            app.created=containerinfo['created']
            app.status=containerinfo['status']
            app.engineip=engine_ip
            app.engineport=engine_port
            app.save()
            i=ip.first()
            res=Resource.objects.filter(type='ip',resource_id=i.id)
            host=res.first().host
            res=Resource()
            res.type="application"
            res.host=host
            res.resource_id=app.id
            res.save()
Ejemplo n.º 6
0
from mydocker.models import APPLICATION
from core.models import Host,Resource,IP
import dockerclient

def create_new(engine_ip,engine_port,host_id,name,description,imagename,command,entrypoint,container_name,host_name,network_mode,privileged,security_opt,ulimit_nofile,ulimit_noproc,ports,port_bindings,volume,binds,dns_server,hosts,environment):
    containerinfo=""
    try:
        containerinfo=dockerclient.create(engine_ip, engine_port, imagename,command,entrypoint,container_name,host_name,network_mode,privileged,security_opt,ulimit_nofile,ulimit_noproc,ports,port_bindings,volume,binds,dns_server,hosts,environment)
    except Exception,ex:
        return "create failed"+str(Exception)+":"+str(ex)
    if containerinfo:
        app=APPLICATION()
        app.name=name
        app.description=description
        app.containerid=containerinfo['container_id']
        app.containername=containerinfo['container_name']
        app.image=containerinfo['image']
        app.created=containerinfo['created']
        app.status=containerinfo['status']
        app.engineip=engine_ip
        app.engineport=engine_port
        app.save()
        hosts=Host.objects.filter(id=host_id)
        if hosts:
            host=hosts.first()
            res=Resource()
            res.type="application"
            res.host=host
            res.resource_id=app.id
            res.save()
        return "create success"