def update_topology( topology_id, name=None, scale=None, panX=None, panY=None, device_id_seq=None, link_id_seq=None, group_id_seq=None, stream_id_seq=None, ): headers = {'content-type': 'application/json'} data = dict( name=name, scale=scale, panX=panX, panY=panY, device_id_seq=device_id_seq, link_id_seq=link_id_seq, group_id_seq=group_id_seq, stream_id_seq=stream_id_seq, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "" + str(topology_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def update_link( link_id, from_device=None, to_device=None, from_interface=None, to_interface=None, id=None, name=None, ): headers = {'content-type': 'application/json'} data = dict( from_device=from_device, to_device=to_device, from_interface=from_interface, to_interface=to_interface, id=id, name=name, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "" + str(link_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def create_topology( name, scale, panX, panY, device_id_seq=0, link_id_seq=0, group_id_seq=0, stream_id_seq=0, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps( dict( name=name, scale=scale, panX=panX, panY=panY, device_id_seq=device_id_seq, link_id_seq=link_id_seq, group_id_seq=group_id_seq, stream_id_seq=stream_id_seq, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def create_device( topology, name, x, y, id, device_type, interface_id_seq=0, process_id_seq=0, host_id=0, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps( dict( topology=topology, name=name, x=x, y=y, id=id, device_type=device_type, interface_id_seq=interface_id_seq, process_id_seq=process_id_seq, host_id=host_id, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def update_device( device_id, topology=None, name=None, x=None, y=None, id=None, device_type=None, interface_id_seq=None, process_id_seq=None, host_id=None, ): headers = {'content-type': 'application/json'} data = dict( topology=topology, name=name, x=x, y=y, id=id, device_type=device_type, interface_id_seq=interface_id_seq, process_id_seq=process_id_seq, host_id=host_id, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "" + str(device_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def update_group( group_id, id=None, name=None, x1=None, y1=None, x2=None, y2=None, topology=None, group_type=None, inventory_group_id=None, ): headers = {'content-type': 'application/json'} data = dict( id=id, name=name, x1=x1, y1=y1, x2=x2, y2=y2, topology=topology, group_type=group_type, inventory_group_id=inventory_group_id, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "" + str(group_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def delete_topologyinventory(topology_inventory_id): response = requests.delete(util.get_url() + "/api/v2/canvas/topologyinventory/" + str(topology_inventory_id), verify=util.get_verify(), auth=util.get_auth()) return response
def create_group( id, name, x1, y1, x2, y2, topology, group_type, inventory_group_id=0, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps( dict( id=id, name=name, x1=x1, y1=y1, x2=x2, y2=y2, topology=topology, group_type=group_type, inventory_group_id=inventory_group_id, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def create_toolbox(name, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps(dict(name=name, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def delete_organisational_unit(dhis2_url, ou_to_delete): auth = get_auth('secret') # get the data set Ids get_data_set_url = '{}/api/27/dataSets'.format(dhis2_url) r = requests.get(get_data_set_url, auth=auth) r_dict = json.loads(r.text) # get relevant organisation Ids get_org_unit_url = '{}/api/27/organisationUnits?filter=displayName:like:{}'.format( dhis2_url, ou_to_delete) organisation_units = get_pages(get_org_unit_url, auth, 'organisationUnits') # define date limits period_start = datetime.date(2010, 1, 1) today = datetime.date.today() period_start_str = period_start.strftime('%Y-%m-%d') today_str = today.strftime('%Y-%m-%d') if len(organisation_units) > 1: return for organisation_unit in organisation_units: print('Organisation unit id: {}'.format(organisation_unit['id'])) for data_set in r_dict['dataSets']: # get data values for each org unit within the date limits get_dvs_url = \ '{root_url}/api/27/dataValueSets?dataSet={dataSetId}&orgUnit={orgUnitId}&startDate={startDate}&endDate={endDate}'\ .format( root_url=dhis2_url, dataSetId=data_set['id'], orgUnitId=organisation_unit['id'], startDate=period_start_str, endDate=today_str ) dvs = requests.get(get_dvs_url, auth=auth) # loop through data values and remove them data_dict = json.loads(dvs.text) for data_point in data_dict.get('dataValues', []): delete_data_value_url = \ '{root_url}/api/27/dataValues?de={dataElementId}&ou={orgUnitId}&pe={period}&co={cat}'.format( root_url=dhis2_url, orgUnitId=organisation_unit['id'], dataElementId=data_point['dataElement'], period=data_point['period'], cat=data_point['categoryOptionCombo']) ret_delete = requests.delete(delete_data_value_url, auth=auth)
def update_toolbox( toolbox_id, name=None, ): headers = {'content-type': 'application/json'} data = dict(name=name, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "" + str(toolbox_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def create_toolboxitem( toolbox, data, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "/api/v2/canvas/toolboxitem/", data=json.dumps(dict( toolbox=toolbox, data=data, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def create_groupdevice( group, device, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps(dict( group=group, device=device, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def create_topologyinventory( topology, inventory_id, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps( dict( topology=topology, inventory_id=inventory_id, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def update_groupdevice( group_device_id, group=None, device=None, ): headers = {'content-type': 'application/json'} data = dict( group=group, device=device, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "" + str(group_device_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def create_interface( device, name, id, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps( dict( device=device, name=name, id=id, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def update_topologyinventory( topology_inventory_id, topology=None, inventory_id=None, ): headers = {'content-type': 'application/json'} data = dict( topology=topology, inventory_id=inventory_id, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "" + str(topology_inventory_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def update_toolboxitem( toolbox_item_id, toolbox=None, data=None, ): headers = {'content-type': 'application/json'} data = dict( toolbox=toolbox, data=data, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "/api/v2/canvas/toolboxitem/" + str(toolbox_item_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def create_process( device, name, process_type, id=0, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "/api/v2/canvas/process/", data=json.dumps( dict( device=device, name=name, process_type=process_type, id=id, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def create_stream( from_device, to_device, label, id=0, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "", data=json.dumps( dict( from_device=from_device, to_device=to_device, label=label, id=id, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def update_interface( interface_id, device=None, name=None, id=None, ): headers = {'content-type': 'application/json'} data = dict( device=device, name=name, id=id, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "/api/v2/canvas/interface/" + str(interface_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def update_stream( stream_id, from_device=None, to_device=None, label=None, id=None, ): headers = {'content-type': 'application/json'} data = dict( from_device=from_device, to_device=to_device, label=label, id=id, ) data = {x: y for x, y in data.items() if y is not None} response = requests.patch(util.get_url() + "/api/v2/canvas/stream/" + str(stream_id) + "/", data=json.dumps(data), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response
def create_link( from_device, to_device, from_interface, to_interface, id, name, ): headers = {'content-type': 'application/json'} response = requests.post(util.get_url() + "/api/v2/canvas/link/", data=json.dumps( dict( from_device=from_device, to_device=to_device, from_interface=from_interface, to_interface=to_interface, id=id, name=name, )), verify=util.get_verify(), auth=util.get_auth(), headers=headers) return response.json()
def delete_process(process_id): response = requests.delete(util.get_url() + "" + str(process_id), verify=util.get_verify(), auth=util.get_auth()) return response
def get_process(process_id): response = requests.get(util.get_url() + "" + str(process_id), verify=util.get_verify(), auth=util.get_auth()) return response.json()
def get_topologyinventory(topology_inventory_id): response = requests.get(util.get_url() + "" + str(topology_inventory_id), verify=util.get_verify(), auth=util.get_auth()) return response.json()
def list_topologyinventory(**kwargs): response = util.unpaginate(util.get_url(), '', util.get_verify(), util.get_auth(), kwargs) return response
def delete_toolboxitem(toolbox_item_id): response = requests.delete(util.get_url() + "" + str(toolbox_item_id), verify=util.get_verify(), auth=util.get_auth()) return response
def get_toolboxitem(toolbox_item_id): response = requests.get(util.get_url() + "" + str(toolbox_item_id), verify=util.get_verify(), auth=util.get_auth()) return response.json()
def list_toolboxitem(**kwargs): response = util.unpaginate(util.get_url(), '', util.get_verify(), util.get_auth(), kwargs) return response