UNPKG

@yuntools/ali-ecs

Version:

阿里云 ECS 模块封装,支持 ESM,CJS 导入,提供 TypeScript 类型定义

96 lines (92 loc) 3.49 kB
import * as Ecs from '@alicloud/ecs20140526'; import Ecs__default, { DescribeInstancesResponseBodyInstancesInstance } from '@alicloud/ecs20140526'; type GetNodeMap<T> = Map<string, T>; type EcsNodeDetail = DescribeInstancesResponseBodyInstancesInstance; declare enum Action { /** 获取指定 Ecs 节点信息 */ DescribeInstances = "DescribeInstances" } declare enum EcsStatusKey { deviceAvailable = "deviceAvailable", expiredTime = "expiredTime", instanceId = "instanceId", instanceName = "instanceName", regionId = "regionId", startTime = "startTime", status = "status" } /** 阿里云 ECS 实例基础状态信息 */ type EcsNodeStatus = { [key in EcsStatusKey]: EcsNodeDetail[key] | undefined; }; declare enum EcsInfoKey { deviceAvailable = "deviceAvailable", expiredTime = "expiredTime", instanceId = "instanceId", instanceName = "instanceName", regionId = "regionId", startTime = "startTime", status = "status", autoReleaseTime = "autoReleaseTime", clusterId = "clusterId", cpu = "cpu", creationTime = "creationTime", description = "description", eipAddress = "eipAddress", hostName = "hostName", innerIpAddress = "innerIpAddress", instanceChargeType = "instanceChargeType", instanceNetworkType = "instanceNetworkType", instanceType = "instanceType", instanceTypeFamily = "instanceTypeFamily", internetChargeType = "internetChargeType", internetMaxBandwidthIn = "internetMaxBandwidthIn", internetMaxBandwidthOut = "internetMaxBandwidthOut", memory = "memory", OSName = "OSName", OSType = "OSType", publicIpAddress = "publicIpAddress", resourceGroupId = "resourceGroupId", serialNumber = "serialNumber", zoneId = "zoneId" } /** 阿里云 ECS 实例信息 */ type EcsNodeInfo = { [key in EcsInfoKey]: EcsNodeDetail[key] | undefined; }; /** * 阿里云 ECS 服务接口 * 最多支持 100 个实例 */ declare class EcsClient { protected readonly id: string; protected readonly secret: string; endpoint: string; client: Ecs__default; debug: boolean; nextToken: string; /** ip -> instanceId */ nodeIp2IdCache: Map<string, string>; /** instanceId -> node */ id2NodeCache: Map<string, Ecs.DescribeInstancesResponseBodyInstancesInstance>; cacheTime: number; cacheTTLSec: number; constructor(id: string, secret: string, endpoint?: string); /** 根据公网 IP 数组获取 Ecs 实例状态信息 */ getNodeStatusByIps(ips: string[], regionId?: string): Promise<GetNodeMap<EcsNodeStatus>>; /** 根据公网 IP 数组获取 Ecs 实例信息 */ getNodeInfoByIps(ips: string[], regionId?: string): Promise<GetNodeMap<EcsNodeInfo>>; /** 根据公网 IP 获取 Ecs 实例 ID */ getInstanceIdByIp(ip: string): Promise<string | undefined>; /** 根据公网 IP 数组获取 Ecs 实例信息 */ getInstancesByIps(ips: string[], regionId?: string): Promise<GetNodeMap<EcsNodeDetail>>; /** 根据公网 IP 获取 Ecs 实例信息 */ getInstanceByIp(ip: string, regionId?: string): Promise<EcsNodeDetail | undefined>; cleanCache(force?: boolean): void; updateInstancedCache(instances: EcsNodeDetail[]): void; private _cleanCache; private _getInstanceByIpFromCache; private createClient; private saveNodesToCache; } export { Action, EcsClient, EcsInfoKey, EcsNodeDetail, EcsNodeInfo, EcsNodeStatus, EcsStatusKey, GetNodeMap };