示例#1
0
def save_new_ci(data):
    # see if the machine name already exists, add if not.

    ci = CmdbData.query.filter_by(machinename=data['machinename']).first()
    if not ci:
        new_assignment = CmdbData(
            id=None,
            machinename=data['machinename'],
            ipaddress=data['ipaddress'],
            network=data['network'],
            mem=data['mem'],
            cpus=data['cpus'],
            disk=data['disk'],
            os=data['os'],
            datacenter=data['datacenter'],
            owner=data['owner'],
            status=data['status']
        )
        save_changes(new_assignment)
        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'CI already exists.',
        }
        return response_object, 409
示例#2
0
def add_a_record(data):
    record = db.session.query(Records).filter_by(name=data['name']).first()
    if not record:
        if data['ttl'] == 0:
            ttl = 3600
        else:
            ttl = data['ttl']

        new_assignment = Records(
            id=None,
            domain_id=data['domain_id'],
            name=data['name'],
            type=data['type'],
            content=data['content'],
            ttl=ttl,
            prio=data['prio'],
            disabled=data['disabled'],
            auth=data['auth']
        )
        save_changes(new_assignment)
        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'Record already exists.',
        }
        return response_object, 409
示例#3
0
def save_new_pool(data):
    net = Networks.query.filter_by(id=data['owner_id']).first()
    pool = NetworkPools.query.filter_by(poolname=net.networkname + '~' +
                                        data['poolname']).first()
    ''' TODO: need to only allow the subnet range to be added to a network one time '''
    ''' could figure out gateway using ipaddress.ip_networks().netmask'''
    print(net.networkname)
    if not pool:
        ''' 
        Prepend the network to the poolname 
        to help with network to pool bind. 
        '''
        newPoolname = net.networkname + '~' + data['poolname']
        ''' use global defaults if not set in data '''
        if data['dns1'] == 'string':
            dns1 = None
        else:
            dns1 = data['dns1']

        if data['dns2'] == 'string':
            dns2 = None
        else:
            dns2 = data['dns2']

        if data['domainname'] == 'string':
            domainname = None
        else:
            domainname = data['domainname']
        new_pool = NetworkPools(id=None,
                                poolname=newPoolname,
                                poolrange=data['poolrange'],
                                subnetmask=data['subnetmask'],
                                gateway=data['gateway'],
                                dns1=dns1,
                                dns2=dns2,
                                domainname=domainname,
                                owner_id=net.id)
        save_changes(new_pool)
        ''' populate the assignments table '''
        # result = PopulateAssignmentTable(iprange=data['poolrange'], pool=new_pool, gateway=data['gateway'])

        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201

    else:
        response_object = {
            'status': 'fail',
            'message': 'Network pool already exists.',
        }
        return response_object, 409
示例#4
0
def save_new_tag(data):
    # see if the machine name already exists, add if not.
    print(data)
    tag = Tags.query.filter_by(name=data['name']).first()
    if not tag:
        new_tag = Tags(tag_id=None, name=data['name'])
        save_changes(new_tag)
        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'Tag with that name already exists.',
        }
        return response_object, 409
示例#5
0
def save_new_settings(data):
    _settings = GlobalSettings.query.first()

    if not _settings:
        new_settings = GlobalSettings(id=None,
                                      dns1=data['dns1'],
                                      dns2=data['dns2'],
                                      domainname=data['domainname'])
        save_changes(new_settings)

        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201

    else:
        response_object = {
            'status': 'fail',
            'message': 'Global settings not added.',
        }
        return response_object, 409
示例#6
0
def save_new_assignment(data):
    # see if the machine name already exists, add if not.

    assignment = PoolAssignments.query.filter_by(
        machinename=data['machinename']).first()
    if not assignment:
        new_assignment = PoolAssignments(id=data['id'],
                                         machinename=data['machinename'],
                                         status=data['status'],
                                         ipaddress=data['ipaddress'])
        save_changes(new_assignment)
        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'Network pool already exists.',
        }
        return response_object, 409
示例#7
0
def save_new_network(data):
    network = Networks.query.filter_by(key=data['key']).first()
    if not network:
        new_network = Networks(
            id=None,
            key=data['key'],
            networkname=data['networkname'],
            vlanid=data['vlanid'],
            datacenter=data['datacenter'],
            cluster=data['cluster']
        )
        save_changes(new_network)
        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'Network already exists. Please Log in.',
        }
        return response_object, 409
示例#8
0
def add_a_domain(data):
    domain = db.session.query(Domains).filter_by(name=data['name']).first()
    if not domain:
        new_assignment = Domains(
            id=None,
            name=data['name'],
            master='not set',
            last_check=1,
            type=data['type'],
            notified_serial=1,
            account='not set'
        )
        save_changes(new_assignment)
        response_object = {
            'status': 'success',
            'message': 'Successfully added.'
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'Domain already already exists.',
        }
        return response_object, 409
示例#9
0
        for method in draw_functions:
            method(screen)

        pygame.display.flip()


if __name__ == '__main__':

    path_to_map_file = "./assets/konya-map.json"
    # path_to_map_file = "default-map.json"

    buildings_data = utils.load_map(to_filename=path_to_map_file)
    buildings = City.make_buildings_from_saved_file(buildings_data)

    konya = City(buildings=buildings,
                 on_change=lambda: utils.save_changes(
                     buildings, map_name=path_to_map_file))

    # solution = Dijkstra(konya.buildings).find_shortest_path(
    #     source_node=konya.get_building_at_pos((518, 45)),
    #      destination_node=konya.get_building_at_pos((645, 772)),
    # )

    # solution = A_star(konya.buildings).find_shortest_path(
    #     source_node=konya.get_building_at_pos((518, 45)),
    #     destination_node=konya.get_building_at_pos((645, 772)),
    # )

    # konya.color_paths(solution)

    map_image = pygame.image.load(Resources.KONYA_MAP_IMAGE_PATH)
    mapmaker = MapMaker(map_image=map_image)