I want to talk about a young, but promising library, born in the Redhat company, designed to make life easier for sysadmins of large and heterogeneous data centers. The library works with data stores from different manufacturers (currently Linux, NetApp, Nexenta, EMC) using the same commands. For example, to create a file system on any of the repositories, it is enough to run:
LSMCLI_URI is the destination address of the command. Depending on the “protocol” (nstor: //), lsmcli understands with what type of storage it is necessary to communicate and download the appropriate plugin. The plugin does all the necessary work.
All lsm commands can be divided into 3 categories:
- Work with file systems (creation, listing, deletion)
- create, delete, delete NFS exports
- work with volumes (iSCSI), assignment of rights for initiators
LibStorageMgmt is designed so that it does not store inside any states and values. This is done because of possible actions on the repository itself bypassing the library. Running the command performs a full cycle of necessary operations on the storage and immediately gives the result (a timeout is provided).
At the request of Nexenta, I developed a plugin for this library. I want to share my experience, and most importantly, to call for developing plug-ins for other repositories!
')
It is quite simple to do this, and is described in detail in the documentation. I will not repeat the texts, I will give only a couple of links:
I will give an example of a template in Python (you can also write in C), filling in which you can get a full-fledged plugin:
File number 1. lsm / anystorage_plugin:
import sys from lsm.anystorage import AnyStorage from lsm.pluginrunner import PluginRunner if __name__ == '__main__': PluginRunner(AnyStorage, sys.argv).run()
File number 2. lsm / lsm / anystorage.py:
import urllib2 import urlparse import simplejson as json import base64 from iplugin import INfs, IStorageAreaNetwork from data import Pool, FileSystem, Snapshot, Capabilities, System, \ NfsExport, Volume, Initiator, AccessGroup from common import LsmError, ErrorNumber, md5 class AnyStorage(INfs, IStorageAreaNetwork): def __init__(self): self.password = None self.timeout = None def startup(self, uri, password, timeout, flags = 0): self.password = password or 'default_pass' self.timeout = timeout def pools(self, flags = 0): pools = []
The plugin will return a list of pools. The pools () function must return a list of pool class objects. Next, lsm processes the list itself and displays it (for lsmcli -l POOLS). Similar classes exist for file systems, snapshots, etc.
Description of all other functions can be found in the declaration INfs, IStorageAreaNetwork (file lsm / lsm / iplugin.py).
If you need to crash, you must create an exception based on the LsmError class:
raise LsmError(ErrorNumber.INVALID_SS, "Cant'create snapshot %s" % snapshot_name)
Most functions must return None upon successful completion, or job_id upon long execution. An example of a lengthy command: replication, which can take minutes and hours. In the case of using job_id, you will need to implement a couple of functions that will allow you to monitor job'ami (job_status (), job_free ()).
In general, the lsm library code is well documented and has a very clear structure.
libStorageMgmt is so young that not even all the functions of working with LVM Linux are implemented. It's only the beginning!