Allow me to clarify. :-)

host.enableMaintenance(apiclient) is how I was invoking it. Just like a regular 
instance method.

For some reason, it wanted to invoke the class method when I did that and was 
complaining about the lack of a parameter.

That being the case, I switched my code to the following (to make use of the 
class method):

Host.enableMaintenance(apiclient, host.id)

The weird part is that it seems like Python was trying to invoke the class 
method when I had syntax specifying I wanted to invoke the instance method.

To circumvent the issue, I just switched my syntax to make use of the class 
method instead of the instance method.

Seems like I shouldn't have had to do that, though.

> On Apr 30, 2016, at 6:30 AM, Will Stevens <williamstev...@gmail.com> wrote:
> 
> You are probably getting this error because you are trying to call:
> Host.enableMaintenance(client)
> 
> Check my examples above for how to call it.
> 
> Sorry I am on my phone, so I am not very efficient with my phone and cant
> civet you better details. :)
>> On Apr 30, 2016 8:23 AM, "Will Stevens" <williamstev...@gmail.com> wrote:
>> 
>> Here is a pretty good explanation.
>> 
>> 
>> http://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod-in-python
>> 
>> I am guessing that both exist because the function is called both with a
>> host instance and with the class itself.
>> 
>> Class instance example: `h.enableMaintenance(client)`
>> 
>> Class example: `Host.enableMaintenance(client, 1)`
>> 
>> In both cases the first parameter is implicitly `h` and `Host`
>> respectively.
>> 
>> I am not sure why we need both (because I am not familiar with how this
>> code is called), but method overloading is definitely valid in python.
>> 
>> On Apr 30, 2016 1:08 AM, "Tutkowski, Mike" <mike.tutkow...@netapp.com>
>> wrote:
>>> 
>>> Hi everyone,
>>> 
>>> 
>>> I received an error when trying to invoke the instance version of
>> enableMaintenance (below).
>>> 
>>> 
>>> 'TypeError: enableMaintenance() takes exactly 3 arguments (2 given)\n']
>>> 
>>> 
>>> I looked at base.py and it has the following with regards to maintenance
>> mode for hosts:
>>> 
>>> 
>>>    def enableMaintenance(self, apiclient):
>>> 
>>>        """enables maintenance mode Host"""
>>> 
>>> 
>>>        cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
>>> 
>>>        cmd.id = self.id
>>> 
>>>        return apiclient.prepareHostForMaintenance(cmd)
>>> 
>>> 
>>>    @classmethod
>>> 
>>>    def enableMaintenance(cls, apiclient, id):
>>> 
>>>        """enables maintenance mode Host"""
>>> 
>>> 
>>>        cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
>>> 
>>>        cmd.id = id
>>> 
>>>        return apiclient.prepareHostForMaintenance(cmd)
>>> 
>>> 
>>> Now, I definitely have a lot more Java experience than Python, but - as
>> far as I know - having two methods with the same name such as this (even if
>> one is an instance method and the other is a class method) is not really
>> "permitted" in Python.
>>> 
>>> 
>>> I mean, technically it's permitted, but the second one will override the
>> first one.
>>> 
>>> 
>>> Can any of our Python people comment on this?
>>> 
>>> 
>>> I was thinking I'd remove the class method (assuming my knowledge here
>> regarding this topic is correct).
>>> 
>>> 
>>> Thanks!
>>> 
>>> Mike
>> 

Reply via email to