Пример #1
0
def create(s, sip):
    if len(s) == 12:
        os = OS()
        os.operatingsystem = s['operatingsystem']
        os.operatingsystemrelease = s['operatingsystemrelease']
        os.kernel = s['kernel']
        os.kernelversion = s['kernelversion']
        os.save()

        hardware = HARDWARE()
        hardware.architecture = s['architecture']
        hardware.processortype = s['processortype']
        hardware.processorcount = s['processorcount']
        hardware.memorytotal = s['memorytotal']
        hardware.uniqueid = s['uniqueid']
        hardware.is_virtual = True if s['is_virtual'] == 'True' else False
        hardware.save()

        ip = IP()
        ip.ipv4 = sip
        ip.save()

        host = Host()
        host.name = s['hostname']
        host.save()

        for u in s['user']:
            user = USER()
            user.name = u['name']
            user.group = u['group']
            user.locked = True if u['locked'] == 'true' else False
            user.save()

            res = Resource()
            res.name = 'User list'
            res.type = 'user'
            res.resource_id = user.id
            res.host = host
            res.save()

        res = Resource()
        res.name = 'OS'
        res.type = 'os'
        res.resource_id = os.id
        res.host = host
        res.save()

        res = Resource()
        res.name = 'Hardware'
        res.type = 'hardware'
        res.resource_id = hardware.id
        res.host = host
        res.save()

        res = Resource()
        res.name = 'IP Address'
        res.type = 'ip'
        res.resource_id = ip.id
        res.host = host
        res.save()
Пример #2
0
def update(hostid, s, sip):
    if len(s) == 12:
        host = Host.objects.filter(id=hostid)
        if host:
            host = host.first()
            os_rid = Resource.objects.filter(host=host, type='os')
            hw_rid = Resource.objects.filter(host=host, type='hardware')
            user_rid = Resource.objects.filter(host=host, type='user')
            for rid in os_rid:
                OS.objects.filter(id=rid.resource_id).all().delete()
                rid.delete()
            for rid in hw_rid:
                HARDWARE.objects.filter(id=rid.resource_id).all().delete()
                rid.delete()
            for rid in user_rid:
                USER.objects.filter(id=rid.resource_id).all().delete()
                rid.delete()
            os = OS()
            os.operatingsystem = s['operatingsystem']
            os.operatingsystemrelease = s['operatingsystemrelease']
            os.kernel = s['kernel']
            os.kernelversion = s['kernelversion']
            os.save()

            res = Resource()
            res.name = 'OS'
            res.type = 'os'
            res.resource_id = os.id
            res.host = host
            res.save()

            hardware = HARDWARE()
            hardware.architecture = s['architecture']
            hardware.processortype = s['processortype']
            hardware.processorcount = s['processorcount']
            hardware.memorytotal = s['memorytotal']
            hardware.uniqueid = s['uniqueid']
            hardware.is_virtual = True if s['is_virtual'] == 'True' else False
            hardware.save()

            res = Resource()
            res.name = 'Hardware'
            res.type = 'hardware'
            res.resource_id = hardware.id
            res.host = host
            res.save()

            for u in s['user']:
                user = USER()
                user.name = u['name']
                user.group = u['group']
                user.locked = True if u['locked'] == 'true' else False
                user.save()

                res = Resource()
                res.name = 'User list'
                res.type = 'user'
                res.resource_id = user.id
                res.host = host
                res.save()
Пример #3
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()
Пример #4
0
def addConfig(h, c):
    if h and c:
        res = Resource()
        res.name = 'Config'
        res.type = 'config'
        res.resource_id = c.id
        res.host = h
        res.save()
Пример #5
0
def create(cont):
    def construct_ruby_object(loader, suffix, node):
        return loader.construct_yaml_map(node)

    def construct_ruby_sym(loader, node):
        return loader.construct_yaml_str(node)

    def timestamp_constructor(loader, node):
        return dateutil.parser.parse(node.value)

    yaml.add_multi_constructor(u"!ruby/object:", construct_ruby_object)
    yaml.add_constructor(u"!ruby/sym", construct_ruby_sym)
    yaml.add_constructor(u'tag:yaml.org,2002:timestamp', timestamp_constructor)

    d = yaml.load(cont)

    certname = d['host']
    hostname = certname[0:-5]

    hosts = Host.objects.filter(name__iexact=hostname)
    if hosts:
        host = hosts.first()

        ppreport = PPREPORT()
        ppreport.status = d['status']
        ppreport.time = d['time']
        ppreport.version = d['puppet_version']
        ppreport.save()

        for m1 in d['metrics']:
            for m2 in d['metrics'][m1]['values']:
                ppmetrics = PPMETRICS()
                ppmetrics.report = ppreport
                ppmetrics.category = d['metrics'][m1]['name']
                ppmetrics.name = m2[0]
                ppmetrics.value = m2[2]
                ppmetrics.save()

        for rel in d['logs']:
            ppreportlog = PPREPORTLOG()
            ppreportlog.report = ppreport
            ppreportlog.level = rel['level']
            ppreportlog.message = rel['message']
            ppreportlog.time = rel['time']
            ppreportlog.save()

        res = Resource()
        res.host = host
        res.name = ""
        res.type = "ppreport"
        res.resource_id = ppreport.id
        res.save()
Пример #6
0
def upload(request):
    file = request.FILES['file']
    instance = Resource()
    instance.name = file.name
    instance.size = file.size
    instance.content_type = file.content_type
    instance.storage = file
    instance.save()

    return JsonResponse({
        'id': instance.id,
        'name': instance.name,
        'url': instance.storage.url
    })
Пример #7
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()
Пример #8
0
    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"


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