Skip to main content

Python Library for handling Jira Service Manager asset. Provides a class to read, modify and add objects to asset schema.

Project description

py-jsm-asset

Name

py-jsm-asset

Description

Python Library for handling Jira Service Manager asset. Provides a class to read, modify and add objects to asset schema. In app some practical example.

Confluence

https://confluence.infn.it/display/LDCG/JIRA+Asset+Management

Installation

It requires python >= 3.9

First: Check the Requirements If you need to install requests, just do it running

pip3 install -r requirements.txt

Import the py_jsm_asset.py into your code: Put the py_jsm_asset.py file in the same folder of your application. Import the file into the code:

from py_jsm_asset  import RestAssetCommunicator

Test

Go into py_jsm_asset/tests . You must have a token.txt where there is the asset token.

python3.9 test_api.py 

API examples

You can find in tests and app directories. A snippet here below:

from py_jsm_asset  import RestAssetCommunicator
import json
Tester=RestAssetCommunicator("https://servicedesk.infn.it/rest/",Put Your Token,"1.0","LNFMAC")
answer=Tester.GetIcon(133)
print(json.dumps(answer))

Applications

csv_import.py

This application import a csv file into a preesistent type. example of remapping, in the following case Num Inventario is duplicated as Inventory and Name (it's a system key that must be always present)


app/csv_import.py -t Inventory -i token.txt -d ";" -c app/inventario.csv -v -s "LNF Divisione Acceleratori"

or simply with configuration file :
app/csv_import.py --conf <myconfig>.json

and << myconfig >>.json:


{
    "dest": "Inventory",
    "src": "app/inventario.csv",
    "token": "",
    "schema": "LNF Divisione Acceleratori",
    "delimiter": ";",
    "token":"MY API TOKEN",
    "mapping": {
        "Num Inventario": [ <<-- put the Num Inventario both on 'Name' and in 'Inventory'
            "Inventory",
            "Name"
        ],
        "Utilizzatore": "Owner",
        "Ruolo": "Ruolo",
        "Fornitore": "Fornitore",
        "Classe": "Classe",
        "Descrizione": "Descrizione",
        "Ub. Migr.": "Ub Migr",
        "Ubicazione": "Ubicazione",
        "Ubicazione Descr.": "Ubicazione Descr",
        "Tipo Bene": "Tipo Bene",
        "BP": "BP",
        "N. Nota": "Nota",
        "Anno Nota": "Anno Nota",
        "Valore Originario": "Valore Originario",
        "Decremento": "Decremento",
        "Incremento": "Incremento",
        "Valore Realizzo": "Valore Realizzo"
    },
    "filter" : []
}

dhcp_import.py

This application imports DHCP configuration file (dhcp.conf) into an existing object type (let's call TestDHCP) with predefined attribute. The following attributes must be present in TestDHCP

  • hostname the DHCP host entry
  • mac the DHCP hardware ethernet entry
  • ip the DHCP fixed-addres entry
  • router the DHCP option routers entry
  • serverip the DHCP server-identifier entry
  • nserver the DHCP next-server entry
  • filename the DHCP filename entry

The application will insert new entry if not existent or will update if existent. The application can generate an equivalent CSV list. A token file must be present with a preallocated API key with WRITE/READ capabilities.

A command line example:

python3.9 app/dhcp_import.py -c dhcpd.conf -s "LNF Divisione Acceleratori" -t "TestDHCP" -i token.txt 

Further import operators example in configuration

In app/example-conf there are real examples of operators use.

regexp operator

to include in the import just matching key value add to the json config:

will include just CSV that have a Column 'Ref. code' = 'VAC'

"regexp":{
        "Ref. code":"VAC"

    }

matchgen operator

will match a list of key and replace a value (or subvalue)

will match the key 'Name' against the regexp 'match' and put the regexp group as value of the attribute 'Type'. This function is useful to extract from a string some pattern.

    "matchgen":[{"src":"Name","match":".+(VGC|VPC).+","dst":"Type"},
    {"src":"Name","match":".+VAC-([A-Z]{3,}).+","dst":"Type"},
    {"src":"Name","match":".+VAC-.*IONP\\d+$","then":"IONP","dst":"Type"} <-- just set IONP if match
    {"src":"Name","match":".+[:-](\\w+)$","dst":"NameIndexed","postfix":"-CAB","counter":0,"digit":3}
    ]

    src: is the the source CSV column
    dst: is the destination attribute
    postfix: append a string (optional)
    counter: append an incrementing number starting from  (optional)
    digit: number of digit (optional)
autoincrement operator

To append a numeric sequence to a src and create new values

    "autoincrement":[{"src":"Module","relcounter":true,"separator":"-","dst":"Name","counter":0,"step":1,"digit":3}]

    src: is the the source CSV column
    relcounter:true|false  (il relcounter the counter will restart each time the value will change)
    separator: separator between value and counter
    dst: is the destination attribute
    counter:0 start from 0 (optional)
    step: increment (optional)
    digit: number of digits (optional)

chain operator

To concatenate previous and/or next row, the following example will put previous 'Equipment Name' into 'Previous Element' and 'Next Element'

    "chain":[{"prev":"Equipment Name","dst":"Previous Element"},{"next":"Equipment Name","dst":"Next Element"}]

    prev/next: source column name
    dst: destination attribute




appendgen operator

To concatenate a list of column into a single attribute with a given separator

    "appendgen":[{"src":["SISTEMA","IOC"],"separator":"\n\r","dst":"Description"}],

    src: list of columns
    separator: separator applied
    dst: destination attribute

aql_object_dump.py

Perform a search and dump of asset objects in json and csv (this case the keys to dump must be provided) formats.

Links and object references are still not handled

python3.9 app/aql_object_dump.py -t TestDHCP -d "Key,Name,mac" -i token.txt --aql "label LIKE pldante" -j dump.json -c dump.csv -v -s "LNF Divisione Acceleratori" 

aql_object_delete.py

Starting from an aql query the application delete objects of a given type (-t) in a given schema (-s)

A command line example:

## cancel all the object matching _alim*_ of the type _TestDHCP_ in the schema _LNF Divisione Acceleratori_
python3.9 app/aql_object_delete.py  -s "LNF Divisione Acceleratori" -t "TestDHCP" -i token.txt --aql "label LIKE alim" -v

create_cross_references.py

This application create a cross reference between object types, let's call source type and destination type. The relation is triggered by a common attribute name. For example if we have to types that have a MAC attribute defined and the MAC is identical in two objects beloging respectively to a source type and a destination type a relation between this two objects can be created by this application in a thierd attribute devoted to host the relation. Here below an example that search for identical MAC in the objects of type "DHCP Nodes" (source type) and object of type "ADC" (destination type) if the match is found a reference of the source object "DHCP Nodes" is created in the attribute "SW Configuration" of the destination type (ADC).

 python3.9 app/create_cross_references.py -st "DHCP Nodes -dt ADC -i token.txt -s "LNF Divisione Acceleratori" -a MAC -l "SW Configuration"

License

For open source projects, say how it is licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_jsm_asset-1.0.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_jsm_asset-1.0.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file py_jsm_asset-1.0.0.tar.gz.

File metadata

  • Download URL: py_jsm_asset-1.0.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.29.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.5

File hashes

Hashes for py_jsm_asset-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6a86583fbc11a8c5e1cab21387476de6f52ef1c6017c19248735d4b81bf86a54
MD5 2ca1fe2906e1d7615f2f893db7252452
BLAKE2b-256 9661b01e3f01e1dc72432787e7f3e725aecc2447c2c36f83397d7686a485a823

See more details on using hashes here.

File details

Details for the file py_jsm_asset-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_jsm_asset-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.29.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.5

File hashes

Hashes for py_jsm_asset-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b71f7239ed9c24ba8c672f3bd6f4283de3f86aaad02ed3db08521b5b0890046
MD5 e0c49050aaee639f4f69c9d000cfd01a
BLAKE2b-256 70a5d3018e4af5b3847f5c41b8a2523e61661ef3a29ce4b4a33273e839fb9909

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page