Download the PHP package epiecs/mikodo without Composer
On this page you can find all versions of the php package epiecs/mikodo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download epiecs/mikodo
More information about epiecs/mikodo
Files in epiecs/mikodo
Package mikodo
Short Description Concurrent unix compatible library on top of phpmiko with inventory management
License MIT
Informations about the package mikodo
Mikodo
Concurrent library on top of phpmiko. Speeds up the process of sending commands. There are included libraries for inventory management Libraries. Supported libraries include and are not limited to: Nornir yaml files, PhpIpam,...
Requires:
- Php >= 7.1
- ext-sockets
-
ext-pcntl
- A UNIX or BSD OS. Native windows is not supported at the moment but you can use WSL.
Installation:
Supported inventories:
Implemented
- Basic
- Nornir
- PhpIpam
Planned
- Netbox
- ...
Basic examples:
Initializing Mikodo
Buffer size
The size in bytes that is available for each worker for communicating to the parent process. Set this to a higher number if you require a lot of text to be sent (eg.) complete config files. You can set this lower to reduce memory usage but you might not receive all output.
Running commands
Mikodo uses the same 3 methods like Phpmiko to send commands to devices: cli, operation and configure.
When sending commands you can either provide the method with a string or an array consisting of commands. Either way is fine. When providing an array the commands are run in order.
For the difference between the types of commands you can refer to the Phpmiko documentation
Preparing the inventory
Mikodo makes use of an inventory to perform its magic. The most basic way is to provide the inventory() method with an array consisting of hosts:
Each host should at least include the most basic required information for Phpmiko: __device_type, username, password and hostname__.
Sending command(s)
When the inventory has been prepared you can start sending commands.
If all went well you will see output like this. Offcourse in real life you will have (pretty?) colors.
Retrieving results
Mikodo will return the values in the form of an array where you can expect a key for each host and within the key of that host another key per command that has been run.
Printing results
To output the results to the terminal you just provide the returned results to the Mikodo->print() function.
Also, in real life you should get pretty colors.
Inventories
To ease your life Mikodo includes several inventory providers.
Inventories allow you to easily select specific hosts and/or groups from your inventory. Inventories also allow you to set default values on a global and/or group level.
You can even mix and match different inventories. One example can be that you load all hosts from PhpIpam and supply a default username/password via a simpleinventory.
One caveat that you have to take into account is the order in which the settings are applied.
The order of preference is hosts > groups > defaults. Imagine a situation where you have an inventory and have set a default username and password in the default settings. Within your inventory you also have one host where there is a password set within the host config.
The password defined in the host will take precedence over the password provided in the default settings.
Writing your own inventory providers
All inventory providers can extend the base inventory class and should implement the DeviceInterface interface.
It is recommended to extend the baseInventory class and use the sethosts/setgroups/setdefaults commands. These commands will make sure that the config is merged correctly as expected.
The InventoryInterface provides you with a nice structure as how a array containing hosts, groups and defaults should function.
Base inventory
The Base inventory can be initialized in three ways
- via the constructor
- via setters
- a combination of both
example
The following methods are supported:
getGroups method
When using the getGroups method there is an optional parameter called $filterGroups.
Gets all hosts from the inventory based on the groupnames that are supplied in the $groups parameter.
When an array with filterGroups is provided the inventory will return a bisection of only those groups that are in both the $groups and $filterGroups array
The $groups array fills the resultset with all provided groups and $filterGroups helps reduce it
eg. if you request all devices within the group cisco and switches and wish to use only the devices that are also member of the nexus and europe groups
PhpIpam inventory
Mikodo can use an existing instance of PhpIpam. The inventory provider will fetch all devices from phpipam and will automatically apply some groups to each hostname as long as the corresponding value in phpipam exists and isn't null.
Afterwards if deemed neccesary you can still set group and/or default settings via the provided inventory methods.
A group will be applied for:
- each device type that is know in phpipam.
- the rack(s) known for that devices
- the section(s) known for that device
- the location(s) known for that device
- if there are custom fields set for a device.
If a custom field is supplied for username, password, port and/or device_type then this will not be applied as a group but directly to the host object. This way it is possible to set some defaults in PhpIpam
If you wish you can also provide a custom field named 'groups' containing comma delimited groups. These will be added to the groups known for that device.
The following authentication methods are supported:
- User token (unencrypted, username and password is required)
- SSL with user token (encrypted, username and password is required), provide a https api link
- SSL with app code token (encrypted, appCode is required), provide a https link
Nornir inventory
If you like Nornir you most likely already have a Nornir inventory. I have the following directory structure in my project folder:
You can load this directory with the NornirInventory provider and query it just the same way like a can with the base inventory. The only file that is required is the hosts.yaml file.
For the sake of simplicity I will use the following inventory as reference. Although brief it does suffice as an example to show you priorities of all inventory components.
default.yaml
groups.yaml
hosts.yaml
All versions of mikodo with dependencies
ext-sockets Version *
ext-pcntl Version *
epiecs/phpmiko Version ^1.0
symfony/yaml Version ^4.3
league/climate Version ^3.5
guzzlehttp/guzzle Version ^6.3