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

#
# AWS SPOT
#
from vcpsdk.plugins.aws import VcpSpecResourceAws

CCI_VERSION = "1.1"
BUILD_VERSION = "20191001"


[ドキュメント] class VcpSpecResourceAwsSpot(VcpSpecResourceAws): """ サンプルコード .. code-block:: python spec = sdk.get_spec("aws_spot", "small") # # 変更できること # # spec.num_nodes = 1 # spec.params_v = ['/opt:/opt'] # spec.params_e = ['USER_NAME=test'] # spec.ip_addresses = ['起動するnodeの静的なIPアドレス'] # aws 依存パラメータ # https://www.terraform.io/docs/providers/aws/index.html # spec.instance_type = 'm4.large' # spec.volume_size = 40 # spec.volume_type = "standard" # standard|io1|gp2|sc1|st1 # spot instace専用 # spec.spot_type = 'one-time' # one-time: spotがなくなったらVcNode終了 # persistent: spotがなくなったらVcNode一時停止 # spec.spot_price = "0.5" # スポットインスタンスの1時間当たりの料金(USドル) # spec.block_duration_minutes = 300 # スポットインスタンスの継続時間 60, 120, 180, 240, 300, or 360 # 追加で使用するVolume # spec.disks = ['vol-08cbb04b35c8c9545'] # volume_id 指定 # or # my_disks = disk_unit.find_nodes() # spec.disks = [my_disks[0]] # VC disk指定 # cloud上のタグ設定(spot requestに付与) # spec.set_tag('key1', 'value1') # spec.set_tag('key2', 'value2') # cloud上のAMIイメージ設定 # 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): # VcpSpecResourceAws の初期化 super().__init__(provider_name, flavor, config_dir) # 初期化 self.aws_cci_["cci_version"] = CCI_VERSION self.aws_cci_["spot_type"] = "one-time" # default self.aws_cci_["spot_price"] = "" # 省略するとon-demand料金 self.aws_cci_["block_duration_minutes"] = 0 self.aws_cci_["cci_version"] = CCI_VERSION def __str__(self): text = """ ======================== {provider_name} ------------------------ {unit_info}""".format( provider_name=self.unit_cci_["cloud_provider"], unit_info=super().__str__() ) text += """ spot_type: {spot_type} spot_price: {spot_price} block_duration_minutes: {block_duration_minutes} instance_type: {instance_type} instance_type: {instance_type} volume_size: {volume_size} volume_type: {volume_type} volume_id: {volume_id} 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 情報 # VcpSpecResource の methodを呼出 my_cci = super(VcpSpecResourceAws, self).cci(name) # yaml schema check self.cci_schema_.validate(self.aws_cci_, "aws_spot") # cloud_params my_cci += """ cloud_provider: aws_spot cloud_params: cci_version: "{cci_version}" spot_type: {spot_type} spot_price: "{spot_price}" block_duration_minutes: {block_duration_minutes} instance_type: {instance_type} volume_size: {volume_size} volume_type: {volume_type} cloud_image: {cloud_image} ip_address_list: {ip_address_list} access_key: {access_key} volume_id: {volume_id} secret_key: {secret_key}""".format_map( self.aws_cci_ ) # cloud tagのcci文字列生成 my_cci += self.cci_tags() return my_cci
# property: spot_type @property def spot_type(self): """ AWSに依存するspot_type .. note:: * one-time | persistent """ return self.aws_cci_["spot_type"] @spot_type.setter def spot_type(self, v): self.aws_cci_["spot_type"] = v # property: spot_price @property def spot_price(self): """ AWSに依存するspot_price - スポットインスタンスの1時間当たりの料金(USドル) """ return self.aws_cci_["spot_price"] @spot_price.setter def spot_price(self, v): self.aws_cci_["spot_price"] = v # property: block_duration_minutes @property def block_duration_minutes(self): """ AWSに依存するblock_duration_minutes """ return self.aws_cci_["block_duration_minutes"] @block_duration_minutes.setter def block_duration_minutes(self, v): self.aws_cci_["block_duration_minutes"] = v