cpal icon indicating copy to clipboard operation
cpal copied to clipboard

changes to main.py --> device() as testing

Open yandy-r opened this issue 10 years ago • 6 comments

Not a pull request, but created a branch on my own fork to pass something by you guys. I basically deleted all the methods from device that had getXXX in the name, so getCPU, getFacts, getHostname and so on..

I made it so that in main, createDevice() calls dev.run(function) and that checks if the called manufacturer implements the function and returns it. This way, we don't have to add a method to device() every time there's a new method added to the individual manufacturer APIs.

If a function does not exist, it still runs the display() function, except it's now part of device's methods.

Like so

$ python core/main.py -m arista -n sw1 -i 10.17.31.51 -f getCPUs
********************************************************
***IP Address (-i), manufacturer (-m), AND one of*******
***the following functions (-f) are required************
***Use 'python main.py -h' for more info on proper usage
********************************************************
*** address
*** facts
*** getCPU
*** getCmd
*** getFQDN
*** getFacts
*** getHostname
*** getPlatform
*** getUptime
*** getVersion
*** getVersionInfo
*** getfreeMemory
*** getserialNumber
*** gettotalMemory
*** jconnect
*** native
*** obj
*** password
*** setLogin
*** username
*** version_info

Same if the -f or -c flags are not passed, won't paste it because it's the same output.

But if the correct arguments are passed, then it works as expected.

$ python core/main.py -m arista -n sw1 -i 10.17.31.51 -f getCPU
Cpu(s):  9.9%us
$ python core/main.py -m arista -n sw1 -i 10.17.31.51 -f getFacts
{   'connect_ip': '10.17.31.51',
    'cpu_utilization': u'Cpu(s):  9.9%us',
    'free_system_memory': 1336128,
    'hostname': u'eos-sw01',
    'platform': u'DCS-7050T-64-R',
    'serial_number': u'JPE13020644',
    'system_uptime': u' 9:47',
    'total_sytem_memory': 3990500,
    'var_name': 'sw1',
    'vendor': 'arista',
    'version': u'4.13.2F'}

Let me know what you think, the branch is called exp-run.

CHECK IT OU HERE

yandy-r avatar Apr 08 '14 02:04 yandy-r

Yandy, makes total sense. I like it a lot. This is where I wanted to take it with having API modules be independent of main. The path I was going down was going to be phase 1. What you are showing here would have been a phase 2! :+1:

But, since this is a platform, we need to make sure don't lose visibility when running from the shell.

Can you show an output of dir(sw1) or dir(dev) (whatever name you use) when you are running cpal from the python shell?

jedelman8 avatar Apr 08 '14 11:04 jedelman8

You mean this?

In [6]: sw1 = device('sw1', 'arista', '192.168.31.21')

In [7]: dir(sw1)
Out[7]:
['__doc__',
 '__init__',
 '__module__',
 '_thisdevice',
 'address',
 'connected_devices',
 'd',
 'deviceCalls',
 'display',
 'facts',
 'facts_expanded',
 'manufacturer',
 'native',
 'obj',
 'run',
 'setLogin']

yandy-r avatar Apr 08 '14 13:04 yandy-r

Yes, it's only displaying variables/methods now that are defined in main. Ideally, we still want to display all of the methods available (even in the API module).

On Tue, Apr 8, 2014 at 9:45 AM, Yandy Ramirez [email protected]:

You mean this?

In [6]: sw1 = device('sw1', 'arista', '192.168.31.21') In [7]: dir(sw1)Out[7]:['doc', 'init', 'module', '_thisdevice', 'address', 'connected_devices', 'd', 'deviceCalls', 'display', 'facts', 'facts_expanded', 'manufacturer', 'native', 'obj', 'run', 'setLogin']

Reply to this email directly or view it on GitHubhttps://github.com/jedelman8/cpal/issues/26#issuecomment-39849078 .

jedelman8 avatar Apr 08 '14 13:04 jedelman8

How about now?

In [1]: from cpal.core.main import device

In [2]: sw1 = device('sw1', 'arista', '192.168.31.21')

In [3]: dir(sw1)
Out[3]:
['address',
 'facts',
 'getCPU',
 'getCmd',
 'getFQDN',
 'getFacts',
 'getHostname',
 'getPlatform',
 'getUptime',
 'getVersion',
 'getVersionInfo',
 'getfreeMemory',
 'getserialNumber',
 'gettotalMemory',
 'jconnect',
 'native',
 'obj',
 'password',
 'setLogin',
 'username',
 'version_info']

Can still be fine tuned, to not display certain variables, but should be a good start

yandy-r avatar Apr 08 '14 14:04 yandy-r

Looking good dude...I'm short on time right now, but I'm sure the code looks good!

On Tue, Apr 8, 2014 at 10:07 AM, Yandy Ramirez [email protected]:

How about now?

In [1]: from cpal.core.main import device

In [2]: sw1 = device('sw1', 'arista', '192.168.31.21')

In [3]: dir(sw1) Out[3]: ['address', 'facts', 'getCPU', 'getCmd', 'getFQDN', 'getFacts', 'getHostname', 'getPlatform', 'getUptime', 'getVersion', 'getVersionInfo', 'getfreeMemory', 'getserialNumber', 'gettotalMemory', 'jconnect', 'native', 'obj', 'password', 'setLogin', 'username', 'version_info']

Can still be fine tuned, to not display certain variables, but

Reply to this email directly or view it on GitHubhttps://github.com/jedelman8/cpal/issues/26#issuecomment-39851663 .

jedelman8 avatar Apr 08 '14 14:04 jedelman8

Just let me know when you get some time to look it over and OK it, I'll create a pull request. All the changes are HERE, specifically the main module HERE

Thanks

yandy-r avatar Apr 08 '14 14:04 yandy-r