Loading...
Loading...
Manage Alibaba Cloud Simple Application Server (SWAS OpenAPI 2020-06-01) resources end-to-end. Use for querying instances, starting/stopping/rebooting, executing commands (cloud assistant), managing disks/snapshots/images, firewall rules/templates, key pairs, tags, monitoring, and lightweight database operations.
npx skill4agent add cinience/alicloud-skills alicloud-compute-swas-openALICLOUD_REGION_IDpython3 -m venv .venv
. .venv/bin/activate
python -m pip install alibabacloud_swas_open20200601 alibabacloud_tea_openapi alibabacloud_credentialsimport os
from alibabacloud_swas_open20200601.client import Client as SwasClient
from alibabacloud_swas_open20200601 import models as swas_models
from alibabacloud_tea_openapi import models as open_api_models
def create_client(region_id: str) -> SwasClient:
config = open_api_models.Config(
region_id=region_id,
endpoint=f"swas.{region_id}.aliyuncs.com",
)
ak = os.getenv("ALICLOUD_ACCESS_KEY_ID") or os.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
sk = os.getenv("ALICLOUD_ACCESS_KEY_SECRET") or os.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
if ak and sk:
config.access_key_id = ak
config.access_key_secret = sk
return SwasClient(config)
def list_regions():
client = create_client("cn-hangzhou")
resp = client.list_regions(swas_models.ListRegionsRequest())
return [r.region_id for r in resp.body.regions]
def list_instances(region_id: str):
client = create_client(region_id)
resp = client.list_instances(swas_models.ListInstancesRequest(region_id=region_id))
return resp.body.instances
def main():
for region_id in list_regions():
for inst in list_instances(region_id):
ip = getattr(inst, "public_ip_address", None) or getattr(inst, "inner_ip_address", None)
spec = getattr(inst, "plan_name", None) or getattr(inst, "plan_id", None)
print(inst.instance_id, ip or "-", spec or "-", region_id)
if __name__ == "__main__":
main()scripts/list_instances_all_regions.pyscripts/summary_instances_by_plan.pyscripts/summary_instances_by_status.pyscripts/fix_ssh_access.pyscripts/get_ssh_port.pyaliyunswas-openreferences/api_overview.mdListInstancesStartInstance(s)StopInstance(s)RebootInstance(s)RunCommandCreateCommandInvokeCommandDescribeInvocationsDescribeInvocationResultListFirewallRulesCreateFirewallRule(s)ModifyFirewallRuleEnableFirewallRuleDisableFirewallRuleCreateSnapshotResetDiskCreateCustomImageInstallCloudAssistantDescribeInvocationsDescribeInvocationResultreferences/command-assistant.mdoutput/compute-swas-open/references/api_overview.mdreferences/endpoints.mdreferences/command-assistant.mdreferences/sources.md