bheisig / i-doit-cli

Access your CMDB on the command line interface
GNU Affero General Public License v3.0
13 stars 1 forks source link

Create/update CMDB objects and their category entries #13

Closed bheisig closed 5 years ago

bheisig commented 6 years ago

Create a new object

idoitcli set server/mylittleserver

Create/update attributes in a single-value category

idoitcli set server/mylittleserver/model --manufacturer A --title 123
idoitcli set server/mylittleserver/location --he 11

Update attributes in a multi-value category

idoitcli set server/mylittleserver/hostaddress/1 --ipv4address 192.168.42.23

Interactive mode

First, collect data:

$ idoitcli set
Create new object
Type? server
Title? mylittleserver
Add more attributes [y/N]? y
[Model] Manufacturer? A
[Model] Model? 123
[Hostaddress] Hostname? mylittleserver
[Location] Location? rackXY
[…]

Templates

Based on object type specific templates in configuration file create/update objects and their attributes.

{
    "templates":
        "server": [
            {
                "category": "C__CATG__MODEL",
                "attribute": "manufacturer"
            },
            {
                "category": "C__CATG__MODEL",
                "attribute": "title"
            },
            {
                "category": "C__CATG__IP",
                "attribute": "hostname"
            },
            {
                "category": "C__CATG__LOCATION",
                "attribute": "location"
            }
        ]
}

Common aspects

bheisig commented 5 years ago

Feature has been implemented. As you can see the usage is slightly different as specified (IMHO it's even better):

$ idoitcli save --help
Create/update CMDB objects and their category entries

USAGE
    $ idoitcli save [OPTIONS] [QUERY]

ARGUMENTS
    QUERY   Combination of type/object/category/entry

            type     is the localized name of an object type,
                     its constant or its numeric identifier
            object   title of numeric identifier
            category is the localized name of the category,
                     its contant or numeric identifier
            entry    is the numeric identifier
                     of an existing category entry

COMMAND OPTIONS
    -a ATTRIBUTE=VALUE,         Localized name or key of ATTRIBUTE
    --attribute=ATTRIBUTE=VALUE and its VALUE
                                (Use only if category is set)

COMMON OPTIONS
    -c FILE,            Include settings stored in a JSON-formatted
    --config=FILE       configuration file FILE; repeat option for more
                        than one FILE
    -s KEY=VALUE,       Add runtime setting KEY with its VALUE; separate
    --setting=KEY=VALUE nested keys with ".", for example "key1.key2=123";
                        repeat option for more than one KEY

    --no-colors         Do not print colored messages
    -q, --quiet         Do not output messages, only errors
    -v, --verbose       Be more verbose

    -h, --help          Print this help or information about a
                        specific command
    --version           Print version information

    -y, --yes           No user interaction required; answer questions
                        automatically with default values

EXAMPLES
    # Create new object with type "server" and title "mylittleserver":
    $ idoitcli save server/mylittleserver

    # Create/update attributes in a single-value category:
    $ idoitcli save server/mylittleserver/model \
        -a manufacturer=VendorA -a model=ModelA
    # Another one:
    $ idoitcli save server/mylittleserver/location \
        -a location="Data Center"

    # Update attributes in a multi-value category:
    $ idoitcli save server/mylittleserver/host\ address/1 \
        -a ipv4_address=192.168.42.23 \
        -a hostname=mylittleserver \
        -a domain=example.com

    # Use a template for an interactive mode:
    $ cat template.json
    {
        "templates": {
            "server": [
                {
                    "category": "model",
                    "attribute": "manufacturer"
                },
                {
                    "category": "model",
                    "attribute": "model"
                },
                {
                    "category": "host address",
                    "attribute": "ipv4_address"
                },
                {
                    "category": "host address",
                    "attribute": "hostname"
                },
                {
                    "category": "host address",
                    "attribute": "domain"
                },
                {
                    "category": "location",
                    "attribute": "location"
                }
            ]
        }
    }

    # Interactive mode:
    $ idoitcli save -c template.json
    Create/update CMDB objects and their category entries
    Type? server
    Title? mylittleserver
    Add more attributes? [Y/n] y
    [Model] Manufacturer? VendorA
    [Model] Model? ModelA
    [Host address] IPv4 address? 192.168.42.23
    [Host address] Hostname? mylittleserver
    [Host address] Domain? example.com
    [Location] Location? Data Center
    Link: http://cmdb.example.com/i-doit/?objID=42