#
# Chameleon
#
from vcpsdk.plugins.spec import VcpSpecResource
CCI_VERSION = "1.0"
BUILD_VERSION = "20200831"
[ドキュメント]
class VcpSpecResourceChameleon(VcpSpecResource):
"""
サンプルコード
.. code-block:: python
# chameleon の flavor は、 予約時に指定済みのため、
# "default" 固定
spec = sdk.get_chameleon_spec("chameleon", "default")
#
# 変更できること
#
# spec.num_nodes = 1
# cloud上のVMイメージ設定
# spec.cloud_image = 'CC-Ubuntu18.04'
# 予約ID
spec.reservation = "予約時に取得した予約識別子文字列"
# 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__("chameleon_cci_", None)
# credentail情報は、vcp_config から設定
self.chameleon_cci_ = {"cci_version": CCI_VERSION}
self.unit_cci_["private_network"] = self.vcp_config_["chameleon"][
"private_network"
] # VPNネットワーク名
# 初期化
self.chameleon_cci_["application_credential_id"] = self.vcp_config_[
provider_name
]["application_credential_id"]
self.chameleon_cci_["application_credential_secret"] = self.vcp_config_[
provider_name
]["application_credential_secret"]
self.chameleon_cci_["cloud_image"] = "default"
self.chameleon_cci_["ip_address_list"] = []
self.chameleon_cci_["reservation"] = ""
def __str__(self):
text = """
========================
{provider_name}
------------------------
{unit_info}""".format(
provider_name=self.unit_cci_["cloud_provider"], unit_info=super().__str__()
)
text += """
reservation: {reservation}""".format_map(
self.chameleon_cci_
)
return text
[ドキュメント]
def cci(self, name):
"""
CCI生成
:param name: unit名
:return: CCI文字列
"""
# cloud parameter 情報
my_cci = super().cci(name)
# yaml schema check
self.cci_schema_.validate(self.chameleon_cci_, "chameleon")
# cloud_params
my_cci += """
cloud_provider: chameleon
cloud_params:
cci_version: "{cci_version}"
cloud_image: "{cloud_image}"
reservation: {reservation}
application_credential_id: {application_credential_id}
application_credential_secret: {application_credential_secret}""".format_map(
self.chameleon_cci_
)
# cloud tagのcci文字列生成
# my_cci += self.cci_tags()
return my_cci
# property: reservation
@property
def reservation(self):
"""
chameleon のインスタンス予約時の予約ID
"""
return self.chameleon_cci_["reservation"]
@reservation.setter
def reservation(self, v):
self.chameleon_cci_["reservation"] = v
# property: ip_addresses
@property
def ip_addresses(self):
"""
chameleonのVPC上の静的ip_address_list
.. note::
chameleon の sharedwan1 のネットワークを使用しているときは、静的IPアドレスを指定できない
"""
return self.chameleon_cci_["ip_address_list"]
@ip_addresses.setter
def ip_addresses(self, v):
"""
chameleonのVPC上の静的ip_address_list
.. note::
`num_nodes` と `ip_addresses` は最後にセットされたほうが有効になる。
"""
if 0 < len(v):
self.unit_cci_["num_nodes"] = len(v)
self.chameleon_cci_["ip_address_list"] = v
# property: cloud_image
@property
def cloud_image(self):
"""
chameleonに依存するAMIのイメージ名
"""
return self.chameleon_cci_["cloud_image"]
@cloud_image.setter
def cloud_image(self, v):
self.chameleon_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.chameleon_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)