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