I have a class called
Remote. This class represents a remote machine and has properties such as
password, as well as methods for transferring files to/from the machine and running code on the machines command line.
Classes Based on Specific VM Providers
I have multiple subclasses of
Remote, such as
SLRemote, for remote machines running on SoftLayer,
VBRemote for machines running in Virtual Box, and potentially in the future I might create other subclasses like an
AWSRemote for remote machines running on Amazon Web Services, for example.
These classes have the
__init__ method set so that they can take in a few arguments specific to the VM provider and properly find an existing VM, or provision a new VM. Since this may take awhile (IE, SoftLayer takes 2-20 minutes to set up a new VM, depending on image size and network conditions), the
__init__ method runs these tasks on a separate thread, and I define a
__getattribute__ method which
joins the creation thread if it requires that the VM be finished (IE, how can you transfer files to/from the machine if it hasn't finished provisioning?)
Classes Based on Specific Software
I also have classes like
FTPServer, which represent remote machines which have specific software installed on them. It seems to me that these classes should also somehow inherit from Remote. Just like
Remote, they have an
username, and a
password. Just like you want to transfer files to a
Remote, you want to transfer files to these classes.
Solutions I've Considered
1 - So I want to subclass
Remote, right? Well, no, not really, because
DB2Server could be installed on a
SLRemote or a
VBRemote or a
AWSRemote, in addition to the generic
2 - What about multiple inheritance? Again, no, not really, because then I have to write a set of classes for inheriting from each specific VM Provider with the specific software. Plus what if you install multiple things on the same server?
3 - Currently, the design I'm going with is that the classes based on specific software being installed inherit from
object (I'm using Python 2), and the
__init__ method takes in a
remote argument. I've written
__setattr__ so that in addition to querying the object directly for attributes, it also checks the
remote object for those same attributes.
But this is annoying because it requires me to write the exact same
__setattr__ method in each of my specific software classes, and as my team is growing and more people are having to write classes like these, they're having to come to understand that I'm using these methods and they need to replicate that code, too. It has a bad code smell in it.
4 - As I was writing up what I'm currently doing, this just came to me (the benefits of writing out your problem on Stack Exchange... or a sticky note... or an email... or telling it to someone who knows nothing at all about the problem you're talking about). I could write a base
Software class which just takes in a
Remote instance and defines the
__setattr__ methods. Then
FTPServer would inherit from that instead.
Other Things that I'm vaguely aware of that might help?
Metaclasses? Aspect Oriented Programming? Mix-ins? These are all concepts that I'm vaguely aware of... would any of these help me with my problem?
What is the right way of doing this? What is the standard and correct design to apply to my situation?
Getting meta with these questions now:
How can I better summarize this problem and make a helpful title for the question with it?
Is this even the right place to ask? The question doesn't involve a single full line of code, so
CodeReviewis definitely not the right place, and
StackOverflowdoesn't seem right, either.