botoを使用して、いくつかのEC2インスタンスを管理しています。インスタンスクラスを提供します。特定のニーズを満たすためにサブクラス化したいと思います。boto はインスタンスを取得するためのクエリ インターフェイスを提供するため、クラス間で変換するものが必要です。この解決策は機能しているように見えますが、クラス属性を変更するのは危険です。より良い方法はありますか?
from boto.ec2.instance import Instance as _Instance
class Instance(_Instance):
@classmethod
def from_instance(cls, instance):
instance.__class__ = cls
# set other attributes that this subclass cares about
return instance