vcpsdk.plugins.abc のソースコード

#
# ABC
#
from vcpsdk.plugins.spec import VcpSpecResource

CCI_VERSION = "1.3"
BUILD_VERSION = "20190408"


[ドキュメント] class VcpSpecResourceAbc(VcpSpecResource): """ サンプルコード .. code-block:: python spec = sdk.get_spec("abc", "default") # # 変更できること # # spec.num_nodes = 1 # spec.flavor_name = 'cn000' # AIC/ABCの環境依存 # cloud上のVMイメージ設定 # spec.cloud_image = 'niivcp-20170616' # base containerにssh loginするためのssh公開鍵情報を設定 spec.set_ssh_pubkey('tmp/id_rsa.pub') """ version = CCI_VERSION + "+" + BUILD_VERSION def __init__(self, provider_name, flavor, config_dir): # flavor から spec を設定 super().__init__(provider_name, flavor, config_dir) # spec attributes名の設定チェックの回避 super().__setattr__("abc_cci_", None) # credentail情報は、vcp_config から設定 self.abc_cci_ = {"cci_version": CCI_VERSION} self.abc_cci_["user_name"] = self.vcp_config_[provider_name]["user_name"] self.abc_cci_["password"] = self.vcp_config_[provider_name]["password"] # VPNネットワーク名 self.unit_cci_["private_network"] = self.vcp_config_[provider_name][ "private_network" ] # flavorから初期化 self.abc_cci_["flavor_name"] = self.flavor_["flavor_name"] self.abc_cci_["cloud_image"] = "default" # 初期化 self.abc_cci_["ip_address_list"] = [] def __str__(self): text = """ ======================== {provider_name} ------------------------ {unit_info} """.format( provider_name=self.unit_cci_["cloud_provider"], unit_info=super().__str__() ) text += """ flavor_name: {flavor_name} cloud_image: {cloud_image} ip_address_list: {ip_address_list} ========================""".format_map( self.abc_cci_ ) return text
[ドキュメント] def cci(self, name): """ CCI生成 :param name: unit名 :return: CCI文字列 """ # yaml schema check self.cci_schema_.validate(self.abc_cci_, self.unit_cci_["cloud_provider"]) my_cci = super().cci(name) my_cci += """ cloud_provider: {provider_name} cloud_params:""".format( provider_name=self.unit_cci_["cloud_provider"] ) my_cci += """ cci_version: "{cci_version}" flavor_name: {flavor_name} user_name: "{user_name}" password: {password} ip_address_list: {ip_address_list} cloud_image: {cloud_image}""".format_map( self.abc_cci_ ) return my_cci
# property: flavor_name @property def flavor_name(self): """ AICに依存するフレーバー名 .. note:: * VCP SDK flavorで設定可能 """ return self.abc_cci_["flavor_name"] @flavor_name.setter def flavor_name(self, v): self.abc_cci_["flavor_name"] = v # property: ip_addresses @property def ip_addresses(self): return self.abc_cci_["ip_address_list"] @ip_addresses.setter def ip_addresses(self, v): """ 静的ip_address_list .. note:: `num_nodes` と `ip_addresses` は最後にセットされたほうが有効になる。 """ # num_nodesを上書きする if 0 < len(v): self.unit_cci_["num_nodes"] = len(v) self.abc_cci_["ip_address_list"] = v # property: cloud_image @property def cloud_image(self): """ ABCに依存するcloud_image """ return self.abc_cci_["cloud_image"] @cloud_image.setter def cloud_image(self, v): self.abc_cci_["cloud_image"] = v @VcpSpecResource.num_nodes.setter def num_nodes(self, v): """ 起動するnodeの個数 .. note:: `num_nodes` と `ip_addresses` は最後にセットされたほうが有効になる。 """ self.unit_cci_["num_nodes"] = v self.abc_cci_["ip_address_list"] = [] def __setattr__(self, name, value): """ spec の attributes に不正な値を設定した場合に例外を発生 :param name: attributes名 :param value: 設定値 """ if not hasattr(self, name): raise AttributeError("spec resource has no attributes!! [{}]".format(name)) super().__setattr__(name, value)