systems.models.Allocation.objects.get

Here are the examples of the python api systems.models.Allocation.objects.get taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: inventory Source File: system_handler.py
    def update(self, request, system_id=None):
        model = System
    	if request.method == 'PUT':
            try:
                try:
                    s = System.objects.get(id=system_id)
                except:
                    pass
                try:
                    s = System.objects.get(hostname=system_id)
                except:
                    pass
                if 'allocation' in request.POST:
                    try:
                        sa = Allocation.objects.get(id=request.POST['allocation'])
                        s.allocation = sa
                    except Exception, e:
                        pass
                        resp = rc.NOT_FOUND
                        resp.write("Server Not Found %s" % e) 
                if 'server_model' in request.POST:
                    try:
                        sm = ServerModel.objects.get(id=request.POST['server_model'])
                        s.server_model = sm
                    except:
                        pass
                        #resp = rc.NOT_FOUND
                        #resp.write("Server Not Found") 
                if 'system_status' in request.POST:
                    ss = None
                    try:
                        ss = SystemStatus.objects.get(status=request.POST['system_status'])
                        s.system_status = ss
                    except:
                        pass
                    if ss is None:
                        try:
                            ss = SystemStatus.objects.get(id=request.POST['system_status'])
                            s.system_status = ss
                        except:
                            pass
                if 'system_rack' in request.POST:
                    try:
                        sr = SystemRack.objects.get(id=request.POST['system_rack'])
                        s.system_rack = sr
                    except:
                        pass
                        #resp = rc.NOT_FOUND
                        #resp.write("System Rack Not Found") 
                if 'location' in request.POST:
                    s.location = request.POST['location']
                if 'asset_tag' in request.POST:
                    s.asset_tag = request.POST['asset_tag']
                if 'switch_ports' in request.POST:
                    s.switch_ports = request.POST['switch_ports']
                if 'serial' in request.POST:
                    s.serial = request.POST['serial']

                if 'rack_order' in request.POST:
                    s.rack_order = request.POST['rack_order']
                if 'purchase_price' in request.POST:
                    s.purchase_price = request.POST['purchase_price']
                if 'oob_ip' in request.POST:
                    s.oob_ip = request.POST['oob_ip']

                if 'hostname' in request.POST:
                    s.hostname = request.POST['hostname']

                if 'notes' in request.POST:
                    s.notes = request.POST['notes']
                s.save()
                resp = rc.ALL_OK
                resp.write('json = {"id":%i, "hostname":"%s"}' % (s.id, s.hostname))
            except:
                resp = rc.NOT_FOUND
                resp.write("System Updated")
            return resp

Example 2

Project: inventory Source File: system_handler.py
    def update(self, request, system_id=None):
        model = System
    	if request.method == 'PUT' or request.method == 'POST':
            try:
                try:
                    s = System.objects.get(id=system_id)
                except:
                    pass
                try:
                    s = System.objects.get(hostname=system_id)
                except:
                    pass
                if 'allocation' in request.POST:
                    if request.POST['allocation'] == '':
                        s.allocation = None
                    else:
                        try:
                            sa = Allocation.objects.get(id=request.POST['allocation'])
                            s.allocation = sa
                        except Exception, e:
                            pass
                            resp = rc.NOT_FOUND
                            resp.write("Server Not Found %s" % e) 
                if 'server_model' in request.POST:
                    if request.POST['server_model'] == '':
                        s.server_model = None
                    else:
                        try:
                            sm = ServerModel.objects.get(id=request.POST['server_model'])
                            s.server_model = sm
                        except:
                            pass
                            #resp = rc.NOT_FOUND
                            #resp.write("Server Not Found") 
                if 'operating_system' in request.POST:
                    if request.POST['operating_system'] == '':
                        s.operating_system = None
                    else:
                        try:
                            sos = OperatingSystem.objects.get(id=request.POST['operating_system'])
                            s.operating_system = sos
                        except Exception, e:
                            resp = rc.NOT_FOUND
                            resp.write(e)
                            return resp
                            #pass
                if 'system_status' in request.POST:
                    if request.POST['system_status'] == '':
                        s.system_status = None
                    else:
                        ss = None
                        try:
                            ss = SystemStatus.objects.get(status=request.POST['system_status'])
                            s.system_status = ss
                        except:
                            pass
                        if ss is None:
                            try:
                                ss = SystemStatus.objects.get(id=request.POST['system_status'])
                                s.system_status = ss
                            except:
                                pass
                if 'system_rack' in request.POST:
                    sr = None
                    if request.POST['system_rack'] == '':
                        s.system_rack = None
                    else:
                        try:
                            sr = SystemRack.objects.get(id=request.POST['system_rack'])
                            s.system_rack = sr
                        except:
                            sr = None
                        try:
                            sr_post = request.POST.get('system_rack').replace(" ","")
                            sr_location = sr_post.split("-")[0]
                            sr_rack = "%s-%s" % (sr_post.split("-")[1], sr_post.split("-")[2])
                            sr = SystemRack.objects.get(name=sr_rack, location__name=sr_location)
                            s.system_rack = sr
                        except:
                            sr = None
                        #resp = rc.NOT_FOUND
                        #resp.write("System Rack Not Found") 
                if 'location' in request.POST:
                    s.location = request.POST['location']
                if 'asset_tag' in request.POST:
                    s.asset_tag = request.POST['asset_tag']
                if 'switch_ports' in request.POST:
                    s.switch_ports = request.POST['switch_ports']
                if 'serial' in request.POST:
                    s.serial = request.POST['serial']

                if 'rack_order' in request.POST:
                    s.rack_order = request.POST['rack_order']
                if 'purchase_price' in request.POST:
                    s.purchase_price = request.POST['purchase_price']
                if 'purchase_date' in request.POST:
                    s.purchase_date = request.POST['purchase_date']
                if 'warranty_start' in request.POST:
                    s.warranty_start = request.POST['warranty_start']
                if 'warranty_end' in request.POST:
                    s.warranty_end = request.POST['warranty_end']
                if 'oob_ip' in request.POST:
                    s.oob_ip = request.POST['oob_ip']
                if 'hostname' in request.POST:
                    s.hostname = request.POST['hostname']
                if 'notes' in request.POST:
                    s.notes = request.POST['notes']
                if 'notes_append' in request.POST:
                    s.notes = "%s\n%s" % (s.notes, request.POST['notes_append'])
                if 'oob_switch_port' in request.POST:
                    s.oob_switch_port = request.POST['oob_switch_port']

                s.save()
                resp = rc.ALL_OK
                resp.write('json = {"id":%i, "hostname":"%s"}' % (s.id, s.hostname))
            except Exception, e:
                resp = rc.NOT_FOUND
                resp.write("System Updated")
            return resp