#
# AWS Disk
#
from vcpsdk.plugins.spec_disk import VcpSpecResourceDisk
CCI_VERSION = "1.0"
BUILD_VERSION = "20190408"
[ドキュメント]
class VcpSpecResourceAwsDisk(VcpSpecResourceDisk):
"""
サンプルコード
.. code-block:: python
spec = sdk.get_spec("aws_disk", "small")
#
# 変更できること
#
# aws 依存パラメータ
# https://www.terraform.io/docs/providers/aws/index.html
# spec.cloud_image = 'AMI-XXXXXX'
# spec.num_disks = 1
# spec.type = "standard" # standard|io1|gp2|sc1|st1
# spec.size = 40
# cloud上のタグ設定
# spec.set_tag('key1', 'value1')
# spec.set_tag('key2', 'value2')
# cloud上のsnapshot名
# spec.cloud_image = 'niivcp-20170616'
"""
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__("aws_cci_", None)
# credentail情報は、vcp_config から設定
self.aws_cci_ = {"cci_version": CCI_VERSION}
self.aws_cci_["access_key"] = self.vcp_config_["aws"]["access_key"]
self.aws_cci_["secret_key"] = self.vcp_config_["aws"]["secret_key"]
self.unit_cci_["private_network"] = self.vcp_config_["aws"][
"private_network"
] # VPNネットワーク名
# flavorから初期化
self.aws_cci_["type"] = self.flavor_["type"]
self.aws_cci_["size"] = self.flavor_["size"]
self.aws_cci_["cloud_image"] = "default"
self.aws_cci_["tags"] = {}
def __str__(self):
text = """
========================
{provider_name}
------------------------
{unit_info}""".format(
provider_name=self.unit_cci_["cloud_provider"], unit_info=super().__str__()
)
text += """
size: {size}
type: {type}
cloud_image: {cloud_image}""".format_map(
self.aws_cci_
)
text += """
tags: {}
========================""".format(
self.tags_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.aws_cci_, "aws_disk")
# cloud_params
my_cci += """
cloud_provider: aws
cloud_params:
cci_version: "{cci_version}"
size: {size}
type: {type}
cloud_image: {cloud_image}
access_key: {access_key}
secret_key: {secret_key}""".format_map(
self.aws_cci_
)
# cloud tagのcci文字列生成
my_cci += self.cci_tags()
return my_cci
# property: size
@property
def size(self):
"""
AWSに依存するdisk size (単位:GB)
.. note::
* VCP SDK flavorで設定可能
"""
return self.aws_cci_["size"]
@size.setter
def size(self, v):
self.aws_cci_["size"] = v
# property: type
@property
def type(self):
"""
AWSに依存するdisk type
.. note::
* VCP SDK flavorで設定可能
"""
return self.aws_cci_["type"]
@type.setter
def type(self, v):
self.aws_cci_["type"] = v
# property: cloud_image
@property
def cloud_image(self):
"""
AWSに依存するAMIのイメージ名
"""
return self.aws_cci_["cloud_image"]
@cloud_image.setter
def cloud_image(self, v):
self.aws_cci_["cloud_image"] = v
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)