Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Class confusion

Reply
Thread Tools

Class confusion

 
 
Rodrick Brown
Guest
Posts: n/a
 
      01-09-2013
How can I make a class that has methods with attributes and other
functions?

I see a lot of code


I'm reading the documentation to Redhat's Satellite software which has a
XMLRPC interface and wrote the following code to test the api.

I would like to extend this code to support methods with methods? I see
this done a lot in python code but I'm not sure how to accomplish something
like this?

i.e.

sc = SatelliteConnect()
sc.get_systemlist().get_systemid() ?
or
sc.get_systemlist().get_running_kernel()

How does one chain methods and attributes like this with classes?

import xmlrpclib
import os
import sys

class SatelliteConnect(object):

SATELLITE_URL = "http://nebula.nydc.fxcorp.prv/rpc/api"
SATELLITE_LOGIN = os.environ['USER']
SATELLITE_PASS = os.environ.get('SATELLITE_PASS',None)

def __init__(self):
self.client = xmlrpclib.Server(self.SATELLITE_URL, verbose=0)
self._check_env('SATELLITE_PASS')
self.key = self.client.auth.login(self.SATELLITE_LOGIN,
self.SATELLITE_PASS)

def _check_env(self, env_var):
if not os.environ.get('SATELLITE_PASS'):
print("{} error please set environment varible {} and
re-run script".format(sys.argv[0], env_var))

sys.exit(-1)

def get_runningkernel(self, sysid):
self.get_systemid('somehost')
kernel = self.client.system.getRunningKernel(self.key, sysid)
if kernel:

return kernel
else:
return None


def get_systemlist(self):
systemlist = self.client.system.listSystems(self.key)
return([ system.get('name') for system in systemlist ])

self.client.auth.logout(self.key)

def get_systemid(self, host):
systemlist = self.client.system.getId(self.key, host)
for system in systemlist:
return system.get('id')

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Class Confusion Fao, Sean C++ 4 09-01-2004 11:26 PM
help needed with class and method confusion Cndistin Python 3 01-06-2004 09:56 PM



Advertisments