RFC: Script development

Russell Doty rdoty at redhat.com
Mon Jul 1 14:21:05 UTC 2013


Jan, great start! I've attached some high level comments.

Thanks,
Russ

On Mon, 2013-07-01 at 10:53 +0200, Jan Synacek wrote:
> On 07/01/2013 10:44 AM, Jan Synacek wrote:
> > On 06/11/2013 10:52 PM, Jan Safranek wrote:
> >> Hi,
> >>
> >> I've been talking to Stephen Gallagher how to proceed with client script
> >> development in lmishell. The goal is to provide high-level functionality
> >> to manage remote systems without complete knowledge of the CIM API.
> >>
> >> <snip>
> > 
> > I created a scripton that uses the LogicalFile provider. I just wanted to be
> > sure that I understood everything that has been discussed on the list so far.
> > 
> > The script itself is not written using lmishell, see [1]. Feel free to test it
> > and criticize it;) Just don't forget to call use_exception(True) if running via
> > the shell.
> > 
> > Also, we should decide where we want to put the scriptons. We could store them
> > next to the providers' sources, but since the scriptons will probably have a
> > common module, they should be put together. Any ideas?
> > 
> > [1] https://fedorahosted.org/openlmi/ticket/109
> > 
> 
> Aha! Actually attaching the scripton...
> 
> _______________________________________________
> openlmi-devel mailing list
> openlmi-devel at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/openlmi-devel

<We should start with the name of the scripton, description, and
arguments>
<Add versioning information so we can try to tell when scriptons have
changed and what the most recent version is.>
<Need comments in the body of the scripton - a major goal is
documentation 
and example.>
<Should this be a single scripton or multiple scriptons? I would lean
toward having
separate scriptons to create a new directory and to list the files in an
existing directory>

import pywbem

# TODO rewrite this scripton using lmishell
# https://fedorahosted.org/openlmi/ticket/109
cliconn = pywbem.WBEMConnection('https://localhost', ('root', 'secret'))
NS='root/cimv2'
FS='Unknown'
<Should be handled by a session object>

# return a list of files in a directory
<List of arguments, etc.>
<How do we control the results returned? Is any filtering or wildcard 
support available? File details - "ls" vs. "ls -l"?>
<What happens if there are 10,000 files in the directory?>

def cmd_ls(path='/', ns=None):
    _ns = ns if ns else NS
    cop = pywbem.CIMInstanceName(classname='LMI_UnixDirectory',
                                 namespace=_ns,
                                 keybindings={

'CSCreationClassName':'Linux_ComputerSystem',
                                     'CSName':'rawhide-virt',

'CreationClassName':'LMI_UnixDirectory',

'FSCreationClassName':'LMI_LocalFileSystem',
                                     'FSName':FS,
                                     'Name':path
                                 })
<We should explain what this function is doing, since we want scriptons
to be 
used for documentation>
    assocs = cliconn.Associators(cop,
AssocClass='LMI_DirectoryContainsFile')
    return [a['Name'] for a in assocs]

<How do we handle errors - directory doesn't exist, don't have
permission to
read directory, no files in directory, etc.?>

def cmd_cd(path, ns=None):
    # change directory to path?
    # have a global current path variable and use it somehow for
something?
    pass
<error handling?>

def cmd_mkdir(path, ns=None):
    _ns = ns if ns else NS
    cop = pywbem.CIMInstanceName(classname='LMI_UnixDirectory',
                                 namespace=_ns,
                                 keybindings={

'CSCreationClassName':'Linux_ComputerSystem',
                                     'CSName':'rawhide-virt',

'CreationClassName':'LMI_UnixDirectory',

'FSCreationClassName':'LMI_LocalFileSystem',
                                     'FSName':FS,
                                     'Name':path
                                 })

    inst = pywbem.CIMInstance('LMI_UnixDirectory')
    inst['CSCreationClassName'] = 'Linux_ComputerSystem'
    inst['CSName'] = 'rawhide-virt'
    inst['CreationClassName'] = 'LMI_UnixDirectory'
    inst['FSCreationClassName'] = 'LMI_LocalFileSystem'
    inst['FSName'] = 'Unknown'
    inst['Name'] = path
    inst.path = cop
    cliconn.CreateInstance(inst)
<Error handling? What happens if the directory exists?>
    
def cmd_rmdir(path, ns=None):
    _ns = ns if ns else NS
    cop = pywbem.CIMInstanceName(classname='LMI_UnixDirectory',
                                 namespace=_ns,
                                 keybindings={

'CSCreationClassName':'Linux_ComputerSystem',
                                     'CSName':'rawhide-virt',

'CreationClassName':'LMI_UnixDirectory',

'FSCreationClassName':'LMI_LocalFileSystem',
                                     'FSName':FS,
                                     'Name':path
                                 })
    cliconn.DeleteInstance(cop)
<What happens if there are files in the directory?>





More information about the openlmi-devel mailing list