Calling container.delete() then calling sync() results in an AttributeError
Example:
>>> new.delete()
>>> new.status
'Stopped'
>>> new.sync()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/paul/.virtualenvs/demoer/lib/python3.5/site-packages/pylxd/models/_model.py", line 151, in sync
response = self.api.get()
File "/home/paul/.virtualenvs/demoer/lib/python3.5/site-packages/pylxd/models/_model.py", line 119, in __getattribute__
return super(Model, self).__getattribute__(name)
File "/home/paul/.virtualenvs/demoer/lib/python3.5/site-packages/pylxd/models/container.py", line 71, in api
return self.client.api.containers[self.name]
AttributeError: 'NoneType' object has no attribute 'api'
hmm, I guess pylxd could throw a nicer error than just AttributeError, maybe explicitly tell that the container was deleted.
On the code side whenever a container is deleted the client attribute is set to None. This could be fixed by just creating a boolean "deleted" and setting it to True. So the next time someone tries to do an operation on a deleted container, it could throw a nicer complain.
I can cook something up if the maintainers think that's an acceptable solution, though I am not fully sure if this project is being maintained or not. @stgraber do you know ?
@om26er yes, the project is definitely being maintained; sorry if we've been a bit slow to get around to this.
It's probably better to leave the client being set to None and catch the AttributeError as non recoverable, and provide something a bit more useful (such as adding something like a ModelDeleted exception to exceptions.py)
I'll tag this as an enhancement. If you've already got something then please do submit a PR.