|
@@ -3,36 +3,65 @@ from datetime import datetime
|
|
|
from resource.enums.region import Region
|
|
from resource.enums.region import Region
|
|
|
from resource.service.FeiShuService import FeiShuService
|
|
from resource.service.FeiShuService import FeiShuService
|
|
|
from resource.service.KVStoreService import KVStoreService
|
|
from resource.service.KVStoreService import KVStoreService
|
|
|
|
|
+from resource.utils.utils import value_covert, bottom_right, convert_storage_unit
|
|
|
|
|
|
|
|
kv_store_service = KVStoreService()
|
|
kv_store_service = KVStoreService()
|
|
|
fei_shu_service = FeiShuService()
|
|
fei_shu_service = FeiShuService()
|
|
|
|
|
|
|
|
-# fei_shu_spread_sheet_token = "XzQGsheQzhk74rtknKacClASnTc"
|
|
|
|
|
-# fei_shu_sheet_id = "25dce4"
|
|
|
|
|
-#
|
|
|
|
|
-# tenant_access_token = fei_shu_service.get_tenant_access_token("cli_a89702999f3c900b", "47ewnaxRqJAvHYdUR8idHgfzfeqAu0Pz")
|
|
|
|
|
|
|
+fei_shu_spread_sheet_token = "XzQGsheQzhk74rtknKacClASnTc"
|
|
|
|
|
+fei_shu_sheet_id = "25dce4"
|
|
|
|
|
+
|
|
|
|
|
+tenant_access_token = fei_shu_service.get_tenant_access_token("cli_a89702999f3c900b", "47ewnaxRqJAvHYdUR8idHgfzfeqAu0Pz")
|
|
|
|
|
+
|
|
|
|
|
+charge_type_map = {
|
|
|
|
|
+ "PrePaid": "预付费",
|
|
|
|
|
+ "PostPaid": "后付费",
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+architecture_type_map = {
|
|
|
|
|
+ "cluster": "集群版",
|
|
|
|
|
+ "standard": "标准版",
|
|
|
|
|
+ "rwsplit": "读写分离版"
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+status_map = {
|
|
|
|
|
+ "Normal": "正常",
|
|
|
|
|
+ "Creating": "创建中",
|
|
|
|
|
+ "Changing": "修改中",
|
|
|
|
|
+ "Inactive": "被禁用",
|
|
|
|
|
+ "Flushing": "清除中",
|
|
|
|
|
+ "Released": "已释放",
|
|
|
|
|
+ "Transforming": "转换中",
|
|
|
|
|
+ "Unavailable": "服务停止",
|
|
|
|
|
+ "Error": "创建失败",
|
|
|
|
|
+ "Migrating": "迁移中",
|
|
|
|
|
+ "BackupRecovering": "备份恢复中",
|
|
|
|
|
+ "MinorVersionUpgrading": "小版本升级中",
|
|
|
|
|
+ "NetworkModifying": "网络变更中",
|
|
|
|
|
+ "SSLModifying": "SSL 变更中",
|
|
|
|
|
+ "MajorVersionUpgrading": "大版本升级中,可正常访问"
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
|
- all_instances = kv_store_service.get_all_instance(region=Region.HANG_ZHOU)
|
|
|
|
|
- for instance in all_instances:
|
|
|
|
|
- dt = datetime.now().strftime('%Y-%m-%d')
|
|
|
|
|
- instance_id = instance.instance_id # 实例ID
|
|
|
|
|
- instance_name = instance.instance_name # 实例名
|
|
|
|
|
- instance_status = instance.instance_status # 实例状态
|
|
|
|
|
- instance_type = instance.instance_type # 实例类型
|
|
|
|
|
- zone_id = instance.zone_id # 可用区ID
|
|
|
|
|
- architecture_type = instance.architecture_type # 架构类型
|
|
|
|
|
- engine_version = instance.engine_version # 兼容的Redis版本
|
|
|
|
|
- charge_type = instance.charge_type # 付费类型
|
|
|
|
|
- capacity = instance.capacity / 1024 # 容量
|
|
|
|
|
- values = [[dt, zone_id, instance_id, instance_name, instance_status, instance_type, architecture_type, engine_version, charge_type, capacity]]
|
|
|
|
|
-
|
|
|
|
|
- # fei_shu_service.spreadsheet_values_prepend(tenant_access_token, fei_shu_spread_sheet_token, f"{fei_shu_sheet_id}!A2:J2", values)
|
|
|
|
|
- instance_attribute = kv_store_service.describe_instance_attribute(instance_id, Region.HANG_ZHOU)
|
|
|
|
|
- storage = instance_attribute.storage
|
|
|
|
|
- availability_value = instance_attribute.availability_value
|
|
|
|
|
- print(f"{instance_id} --> {storage} --> {availability_value}")
|
|
|
|
|
|
|
+ region_list = [Region.HANG_ZHOU, Region.HONG_KONG, Region.US_WEST, Region.SOUTHEAST]
|
|
|
|
|
+ for region in region_list:
|
|
|
|
|
+ all_instances = kv_store_service.get_all_instance(region=region)
|
|
|
|
|
+ for instance in all_instances:
|
|
|
|
|
+ dt = datetime.now().strftime('%Y-%m-%d')
|
|
|
|
|
+ instance_id = instance.instance_id # 实例ID
|
|
|
|
|
+ instance_name = instance.instance_name # 实例名
|
|
|
|
|
+ instance_status = value_covert(instance.instance_status, status_map) # 实例状态
|
|
|
|
|
+ instance_type = instance.instance_type # 实例类型
|
|
|
|
|
+ zone_id = instance.zone_id # 可用区ID
|
|
|
|
|
+ architecture_type = value_covert(instance.architecture_type, architecture_type_map) # 架构类型
|
|
|
|
|
+ engine_version = instance.engine_version # 兼容的Redis版本
|
|
|
|
|
+ charge_type = value_covert(instance.charge_type, charge_type_map) # 付费类型
|
|
|
|
|
+ capacity = convert_storage_unit(instance.capacity, "mb", "gb") # 容量
|
|
|
|
|
+ values = [[dt, region.desc, zone_id, instance_id, instance_name, instance_status, instance_type, architecture_type, engine_version, charge_type, capacity]]
|
|
|
|
|
+ start_col = "A2"
|
|
|
|
|
+ end_col = bottom_right(start_col, values)
|
|
|
|
|
+ fei_shu_service.spreadsheet_values_prepend(tenant_access_token, fei_shu_spread_sheet_token, f"{fei_shu_sheet_id}!{start_col}:{end_col}", values)
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|