On 07/01/2013 04:21 PM, Russell Doty wrote:
Jan, great start! I've attached some high level comments.
<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.>
I didn't write any of these since this script was meant to be a quick example
and the commands themselves are pretty clear. But, I agree, everything that you
listed should be there.
<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>
In this particular case, I think that they should all be in one file -- all
commands are very simple and all are related to the LogicalFile provider.
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>
Agreed, should be part of the shell.
# 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"?>
I simply return all the files (their names) in a list. I think that support for
additional parameters could be added in the scripton itself, but it really
depends on how deep we want to go before recreating the whole operating system:)
If I wanted, for example, to see the files' access rights, I would have to call
GetInstance() on every file to get its properties and that might be quite slow,
especially if the CIMOM and the scripton are not on the same host.
<What happens if there are 10,000 files in the directory?>
Currently, the provider returns an error that there are too many files in a
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.?>
An exception with a user-friendly error message is returned. The same applies
for all of your error handling related questions.
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?>
--
Jan Synacek
Software Engineer, Red Hat