LoginSignup
4
2

More than 5 years have passed since last update.

aliyuncliでimage_idを調べてみた

Last updated at Posted at 2018-11-19

初めに

Alibaba Cloud で Teffaform に対応している記事 があったので、試してみようと思ったらimage_idをaliyuncliで探してくるといいよって書いてあって、どうやんだろと悩んだので記録を残しておく。

image_id = "m-6wec065ood8fic52mh6v" # image_idはaliyuncli使って調べるといいです

aliyuncli という CLI があるらしいので、まずそれをセットアップしてみます。

aliyuncli を使ってAlibaba Cloudを操作してみた

dockerでインストールすると楽なのでこの記事を参考にしてみた。アクセスキーを指定しろと言われるので以下のページを参考にして作成。

AccessKey の作成

無事、aliyuncli の環境は完成

aliyuncli を使ってみる

# aliyuncli help
ALIYUNCLI()

NAME
        aliyuncli -
DESCRIPTION
        The Aliyun Command Line Interface is a unified tool to manage your aliyun services.
SYNOPSIS
        aliyuncli <command> <operation> [options and parameters]
        aliyuncli has supported command completion now. The detail you can check our site.
OPTIONS
        configure
        This option will help you save the key and secret and your favorite output format (text, json or table)
        --output (string)
        The formatting style for command output.
        o json
        o text
        o table
        --secure
        Making secure requests(HTTPS) to service
AVAILABLE SERVICES
        o ecs
        o ess
        o mts
        o rds
        o slb

これを見ると、ecs /ess /mts /rds /slb がコントロールできそうです。

コマンド 機能
ecs Elastic Compute Service
ess Auto Scaring
mts これってなんだろ
rds RDS
slb Server Load Balancer

調べてたら、LogやCDNは別のCLIがあるみたいですね。
Log Service CLI
CDN command line interface

オンラインヘルプコマンド

使い方は、オンラインヘルプコマンドで見ていける。わからなくなったところでhelpを入力して実行すると、そのあと選べるオプションなどの選択肢が出てくる。

# aliyuncli ecs help

サーバのイメージが知りたいのでecsでhelpを打ってみる。めっちゃある。あんまり構造化されてない感じですね。

# aliyuncli ecs help
usage: aliyuncli <command> <operation> [options and parameters]
[ecs] valid operations as follows:

ActivateRouterInterface                         | AddBandwidthPackageIps
AddIpRange                                      | AddTags
AllocateDedicatedHosts                          | AllocateEipAddress
AllocatePublicIpAddress                         | ApplyAutoSnapshotPolicy
AssignIpv6Addresses                             | AssignPrivateIpAddresses
AssociateEipAddress                             | AssociateHaVip
AttachClassicLinkVpc                            | AttachDisk
AttachInstanceRamRole                           | AttachKeyPair
AttachNetworkInterface                          | AttachVolume
AuthorizeSecurityGroup                          | AuthorizeSecurityGroupEgress
BindIpRange                                     | CancelAgreement
CancelAutoSnapshotPolicy                        | CancelCopyImage
CancelPhysicalConnection                        | CancelSimulatedSystemEvents
....

Imageに関するものを絞ってみる

# aliyuncli ecs help | grep -i image
CancelAutoSnapshotPolicy                        | CancelCopyImage
ConvertNatPublicIpToEip                         | CopyImage
CreateHpcCluster                                | CreateImage
DeleteHpcCluster                                | DeleteImage
DescribeImageSharePermission                    | DescribeImageSupportInstanceTypes
DescribeImages                                  | DescribeInstanceAttribute
EnablePhysicalConnection                        | ExportImage
GetInstanceScreenshot                           | ImportImage
ModifyHpcClusterAttribute                       | ModifyImageAttribute
ModifyImageShareGroupPermission                 | ModifyImageSharePermission

ここまでくれば、なんとなくわかります。

Describe が、「…を述べる, 記述する」という意味なので、DescribeImages これがそれっぽそうだ。

# aliyuncli ecs DescribeImages | head
{
    "PageSize": 10,
    "RegionId": "ap-northeast-1",
    "TotalCount": 32,
    "PageNumber": 1,
    "RequestId": "7CE39A36-F876-4F40-8745-F48D2970CF42",
    "Images": {
        "Image": [
            {
                "IsSubscribed": false,

高度なフィルター

たくさん出てくるので、フィルター で表示内容を絞り込みをしてみる。

–filter Images

Images 要素の中だけが表示される。

–filter Images.Image[*]

Imagesの中のImageの中にそれぞれの要素が表示されている。Images.Image[*] で、Image要素すべてが表示される。

–filter Images.Image[*].ImageId

ここでほしいのはImageの選択肢なので、とりあえず、ImageIdだけ表示してみる。

--filter Images.Image[*].[Status,ImageId,OSName]

必要な項目だけ表示してみる。配列のように[]でくくり、カンマで区切るとよい。

必要な ImageIdをゲット

# aliyuncli ecs DescribeImages --filter Images.Image[*].[Status,ImageId,OSName]
[
    [
        "Available",
        "m-6wehphr9vdvmrra14iuk",
        "CentOS  7.4 64\u4f4d"
    ],
    [
        "Available",
        "coreos_1745_7_0_64_30G_alibase_20180705.vhd",
        "CoreOS  1745.7.0 64\u4f4d"
    ],
    [
        "Available",
        "centos_6_09_64_20G_alibase_20180326.vhd",
        "CentOS  6.9 64\u4f4d"
    ],
    [
        "Available",
        "ubuntu_16_0402_32_20G_alibase_20180409.vhd",
        "Ubuntu  16.04 32\u4f4d"
    ],
    [
        "Available",
        "ubuntu_16_0402_64_20G_alibase_20180409.vhd",
        "Ubuntu  16.04 64\u4f4d"
    ],
    [
        "Available",
        "alinux_17_01_64_20G_cloudinit_20171222.vhd",
        "Aliyun Linux  17.1 64\u4f4d"
    ],
    [
        "Available",
        "winsvr_64_dtcC_1709_zh-cn_40G_alibase_20171115.vhd",
        "Windows Server  Version 1709 \u6570\u636e\u4e2d\u5fc3\u7248 64\u4f4d\u4e2d\u6587\u7248\uff08\u4e0d\u542bUI\uff09"
    ],
    [
        "Available",
        "winsvr_64_dtcC_1709_ja-jp_40G_alibase_20171115.vhd",
        "Windows Server  Version 1709 \u6570\u636e\u4e2d\u5fc3\u7248 64\u4f4d\u65e5\u6587\u7248\uff08\u4e0d\u542bUI\uff09"
    ],
    [
        "Available",
        "winsvr_64_dtcC_1709_en-us_40G_alibase_20171115.vhd",
        "Windows Server  Version 1709 \u6570\u636e\u4e2d\u5fc3\u7248 64\u4f4d\u82f1\u6587\u7248\uff08\u4e0d\u542bUI\uff09"
    ],
    [
        "Available",
        "opensuse_42_03_64_20G_alibase_20171031.vhd",
        "OpenSUSE  42.3 64\u4f4d"
    ]
]

2番目の項目がImageIDになっている。これで必要なImageをTerraformに指定することができる。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2