阿里云ros命令行工具。

aliyun-ros-cli的Python项目详细描述


准备

需要

  • python 2.7版
  • 阿里云python sdk ros

配置

首次使用ros命令时,ros cli将创建 安装ROS的默认配置。

[ACCESS]
ACCESS_KEY_ID = YOUR_KEY_ID
ACCESS_KEY_SECRET = YOUR_KEY_SECRET
REGION_ID = YOUR_REGION

[OTHER]
JSON_INDENT = 2
DEBUG = False

请使用ros set-userdata设置默认配置。

您还可以在使用ros cli时输入区域。在很多情况下, 如果不指定区域,将使用默认配置。

将debug设置为true以读取更多输出。

安装

pip install aliyun-python-sdk-ros

pip install aliyun-ros-cli

制表符完成

在bash中支持tab完成。把ros_completion文件放在/etc/bash_completion.d/ 然后运行source /etc/bash_completion.d/ros_completion

ros_completion内容:

#! /usr/bin/bash
#
# put this file at `/etc/bash_completion.d/` and run `source /etc/bash_completion.d/ros_completion`
#
# Copyright (c) 2017 Aliyun.com All right reserved. This software is the
# confidential and proprietary information of Aliyun.com ("Confidential
# Information"). You shall not disclose such Confidential Information and shall
# use it only in accordance with the terms of the license agreement you entered
# into with Aliyun.com .
#
# created by quming on 07/24/2017

_ros()
{
    # cur prev ros_father
    local cur prev opts_top opts_cmds
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts_top="-h --help --json --config --region-id"
    opts_cmds="abandon-stack \
        create-stack \
        delete-stack \
        describe-stack describe-resource \
        get-template \
        list-stacks list-resources list-regions list-events \
        preview-stack \
        resource-type resource-type-detail resource-type-template \
        set-userdata \
        update-stack \
        validate-template"

    local opt_abandon_stack="-h --help --region-id --stack-name --stack-id"

    local opt_create_stack="-h --help --region-id --stack-name \
        --template-url --parameters --disable-rollback \
        --timeout-in-minutes"

    local opt_delete_stack="-h --help --region-id --stack-name --stack-id"
    local opt_describe_stack="-h --help --stack-name --stack-id"
    local opt_describe_resource="-h --help --stack-name --stack-id --resource-name"

    local opt_get_template="-h --help --stack-name --stack-id"

    local opt_list_stacks="-h --help --stack-name --stack-id --region-id \
        --status --page-number --page-size"
    local opt_list_resources="-h --help --stack-name --stack-id"
    local opt_list_regions="-h --help"
    local opt_list_events="-h --help --stack-name --stack-id --resource-status \
        --resource-name --resource-type --page-number --page-size"

    local opt_preview_stack="-h --help --region-id --stack-name --stack-id \
        --template-url --parameters --disable-rollback \
        --timeout-in-minutes"

    local opt_resource_type="-h --help --status"
    local opt_resource_type_detail="-h --help --name"
    local opt_resource_type_template="-h --help --name"

    local opt_set_userdata="-h --help --key-id --key-secret --json --region-id"

    local opt_update_stack="-h --help --region-id --stack-name --stack-id \
        --template-url --parameters --disable-rollback \
        --timeout-in-minutes"

    local opt_validate_template="-h --help --template-url"


    # if [ -z "${cur}" ]; then
    if [ "${prev}"x = "ros"x ]; then
        ros_father=""
    fi

    if [[ ${opts_cmds} = *${prev}* ]]; then
        ros_father=${prev}
    fi

    # echo "["${cur}"]["${prev}"]["${ros_father}"]"

    case "${ros_father}" in
        abandon-stack)
            COMPREPLY=($(compgen -W "${opt_abandon_stack}" -- ${cur}))
            return 0
            ;;
        create-stack)
            COMPREPLY=($(compgen -W "${opt_create_stack}" -- ${cur}))
            return 0
            ;;
        delete-stack)
            COMPREPLY=($(compgen -W "${opt_delete_stack}" -- ${cur}))
            return 0
            ;;
        describe-stack)
            COMPREPLY=($(compgen -W "${opt_describe_stack}" -- ${cur}))
            return 0
            ;;
        describe-resource)
            COMPREPLY=($(compgen -W "${opt_describe_resource}" -- ${cur}))
            return 0
            ;;
        get-template)
            COMPREPLY=($(compgen -W "${opt_get_template}" -- ${cur}))
            return 0
            ;;
        list-stacks)
            COMPREPLY=($(compgen -W "${opt_list_stacks}" -- ${cur}))
            return 0
            ;;
        list-resources)
            COMPREPLY=($(compgen -W "${opt_list_resources}" -- ${cur}))
            return 0
            ;;
        list-regions)
            COMPREPLY=($(compgen -W "${opt_list_regions}" -- ${cur}))
            return 0
            ;;
        list-events)
            COMPREPLY=($(compgen -W "${opt_list_events}" -- ${cur}))
            return 0
            ;;
        preview-stack)
            COMPREPLY=($(compgen -W "${opt_preview_stack}" -- ${cur}))
            return 0
            ;;
        resource-type)
            COMPREPLY=($(compgen -W "${opt_resource_type}" -- ${cur}))
            return 0
            ;;
        resource-type-detail)
            COMPREPLY=($(compgen -W "${opt_resource_type_detail}" -- ${cur}))
            return 0
            ;;
        resource-type-template)
            COMPREPLY=($(compgen -W "${opt_resource_type_template}" -- ${cur}))
            return 0
            ;;
        set-userdata)
            COMPREPLY=($(compgen -W "${opt_set_userdata}" -- ${cur}))
            return 0
            ;;
        update-stack)
            COMPREPLY=($(compgen -W "${opt_update_stack}" -- ${cur}))
            return 0
            ;;
        validate-template)
            COMPREPLY=($(compgen -W "${opt_validate_template}" -- ${cur}))
            return 0
            ;;
        *)
            if [[ ${cur} == -* ]] ; then
                COMPREPLY=($(compgen -W "${opts_top}" -- ${cur}))
                return 0
            else
                COMPREPLY=($(compgen -W "${opts_cmds}" -- ${cur}))
                return 0
            fi
        ;;
    esac
}

complete -F _ros ros

帮助

如果您想了解更多详细信息,请访问ROS API

顶级命令

$ ros -h
usage: ros [-h] [--config CONFIG_FILE] [--json] [--region-id REGION_ID]  ...

optional arguments:
  -h, --help            show this help message and exit
  --config CONFIG_FILE  Location of config file
  --json                Print results as JSON format
  --region-id REGION_ID
                        Region ID, if not set, use config file's field

commands:

    set-userdata        Set default Aliyun access info
    create-stack        Creates a stack as specified in the template
    delete-stack        Deletes the specified stack
    update-stack        Update a stack as specified in the template
    preview-stack       Preview a stack as specified in the template
    abandon-stack       Abandon the specified stack
    list-stacks         Returns the summary information for stacks whose
                        status matches the specified StackStatusFilter
    describe-stack      Returns the description for the specified stack
    list-resources      Returns descriptions of all resources of the specified
                        stack
    describe-resource   Returns a description of the specified resource in the
                        specified stack
    resource-type       Returns types of resources
    resource-type-detail
                        Returns detail of the specific resource type
    resource-type-template
                        Returns template of the specific resource type
    get-template        Returns the template body for a specified stack
    validate-template   Validates a specified template
    list-regions        Returns all regions avaliable
    list-events         Returns all stack related events for a specified stack
                        in reverse chronological order

堆栈上的命令

创建堆栈

$ ros create-stack -h
usage: ros create-stack [-h] [--region-id REGION_ID] --stack-name STACK_NAME
                        --template-url TEMPLATE_URL [--parameters PARAMETERS]
                        [--disable-rollback DISABLE_ROLLBACK]
                        [--timeout-in-minutes TIMEOUT_IN_MINUTES]

optional arguments:
  -h, --help            show this help message and exit
  --region-id REGION_ID
                        The region that is associated with the stack
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --template-url TEMPLATE_URL
                        Location of file containing the template body
  --parameters PARAMETERS
                        A list of Parameter structures that specify input
                        parameters for the stack. Synatax: key=value,key=value
  --disable-rollback DISABLE_ROLLBACK
                        Set to true to disable rollback of the stack if stack
                        creation failed
  --timeout-in-minutes TIMEOUT_IN_MINUTES
                        The amount of time that can pass before the stack
                        status becomes CREATE_FAILED

删除堆栈

$ ros delete-stack -h
usage: ros delete-stack [-h] --region-id REGION_ID --stack-name STACK_NAME
                        --stack-id STACK_ID

optional arguments:
  -h, --help            show this help message and exit
  --region-id REGION_ID
                        The region that is associated with the stack
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --stack-id STACK_ID   The id that is associated with the stack

更新堆栈

$ ros update-stack -h
usage: ros update-stack [-h] --region-id REGION_ID --stack-name STACK_NAME
                        --stack-id STACK_ID --template-url TEMPLATE_URL
                        [--parameters PARAMETERS]
                        [--disable-rollback DISABLE_ROLLBACK]
                        [--timeout-in-minutes TIMEOUT_IN_MINUTES]

optional arguments:
  -h, --help            show this help message and exit
  --region-id REGION_ID
                        The region that is associated with the stack
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --stack-id STACK_ID   The id that is associated with the stack
  --template-url TEMPLATE_URL
                        Location of file containing the template body
  --parameters PARAMETERS
                        A list of Parameter structures that specify input
                        parameters for the stack. Synatax: key=value,key=value
  --disable-rollback DISABLE_ROLLBACK
                        Set to true to disable rollback of the stack if stack
                        creation failed
  --timeout-in-minutes TIMEOUT_IN_MINUTES
                        The amount of time that can pass before the stack
                        status becomes CREATE_FAILED

预览堆栈

$ ros preview-stack -h
usage: ros preview-stack [-h] [--region-id REGION_ID] --stack-name STACK_NAME
                         --template-url TEMPLATE_URL [--parameters PARAMETERS]
                         [--disable-rollback DISABLE_ROLLBACK]
                         [--timeout-in-minutes TIMEOUT_IN_MINUTES]

optional arguments:
  -h, --help            show this help message and exit
  --region-id REGION_ID
                        The region that is associated with the stack
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --template-url TEMPLATE_URL
                        Location of file containing the template body
  --parameters PARAMETERS
                        A list of Parameter structures that specify input
                        parameters for the stack. Synatax: key=value,key=value
  --disable-rollback DISABLE_ROLLBACK
                        Set to true to disable rollback of the stack if stack
                        creation failed
  --timeout-in-minutes TIMEOUT_IN_MINUTES
                        The amount of time that can pass before the stack
                        status becomes CREATE_FAILED

放弃堆栈

$ ros abandon-stack -h
usage: ros abandon-stack [-h] --region-id REGION_ID --stack-name STACK_NAME
                         --stack-id STACK_ID

optional arguments:
  -h, --help            show this help message and exit
  --region-id REGION_ID
                        The region that is associated with the stack
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --stack-id STACK_ID   The id that is associated with the stack

列出堆栈

$ ros list-stacks -h
usage: ros list-stacks [-h] [--stack-name STACK_NAME] [--stack-id STACK_ID]
                       [--status {CREATE_COMPLETE,CREATE_FAILED,CREATE_IN_PROGRESS,DELETE_COMPLETE,DELETE_FAILED,DELETE_IN_PROGRESS,ROLLBACK_COMPLETE,ROLLBACK_FAILED,ROLLBACK_IN_PROGRESS}]
                       [--region-id REGION_ID] [--page-number PAGE_NUMBER]
                       [--page-size PAGE_SIZE]

optional arguments:
  -h, --help            show this help message and exit
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --stack-id STACK_ID   The id that is associated with the stack
  --status {CREATE_COMPLETE,CREATE_FAILED,CREATE_IN_PROGRESS,DELETE_COMPLETE,DELETE_FAILED,DELETE_IN_PROGRESS,ROLLBACK_COMPLETE,ROLLBACK_FAILED,ROLLBACK_IN_PROGRESS}
                        status of stacks
  --region-id REGION_ID
                        The region of stacks
  --page-number PAGE_NUMBER
                        The page number of stack lists, start from 1, default
                        1
  --page-size PAGE_SIZE
                        Lines each page, max 100, default 10

描述堆栈

$ ros describe-stack -h
usage: ros describe-stack [-h] --stack-name STACK_NAME --stack-id STACK_ID

optional arguments:
  -h, --help            show this help message and exit
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --stack-id STACK_ID   The id that is associated with the stack

资源上的命令

列出资源

$ ros list-resources -h
usage: ros list-resources [-h] --stack-name STACK_NAME --stack-id STACK_ID

optional arguments:
  -h, --help            show this help message and exit
  --stack-name STACK_NAME
                        The name of stack
  --stack-id STACK_ID   The id of stack

描述资源

$ ros describe-resource -h
usage: ros describe-resource [-h] --stack-name STACK_NAME --stack-id STACK_ID
                             --resource-name RESOURCE_NAME

optional arguments:
  -h, --help            show this help message and exit
  --stack-name STACK_NAME
                        The name of stack
  --stack-id STACK_ID   The id of stack
  --resource-name RESOURCE_NAME
                        The name of resource

资源类型

$ ros resource-type -h
usage: ros resource-type [-h]
                         [--status {UNKNOWN,SUPPORTED,DEPRECATED,UNSUPPORTED,HIDDEN}]

optional arguments:
  -h, --help            show this help message and exit
  --status {UNKNOWN,SUPPORTED,DEPRECATED,UNSUPPORTED,HIDDEN}
                        The status of resource

资源类型详细信息
$ ros resource-type-detail -h
usage: ros resource-type-detail [-h] --name NAME

optional arguments:
  -h, --help   show this help message and exit
  --name NAME  The name of resource

资源类型模板
$ ros resource-type-template -h
usage: ros resource-type-template [-h] --name NAME

optional arguments:
  -h, --help   show this help message and exit
  --name NAME  The name of resource

模板上的命令

获取模板

$ ros get-template -h
usage: ros get-template [-h] --stack-name STACK_NAME --stack-id STACK_ID

optional arguments:
  -h, --help            show this help message and exit
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --stack-id STACK_ID   The id that is associated with the stack

验证模板

$ ros validate-template -h
usage: ros validate-template [-h] --template-url TEMPLATE_URL

optional arguments:
  -h, --help            show this help message and exit
  --template-url TEMPLATE_URL
                        Location of file containing the template body

其他命令

列出区域

列出所有区域,不需要参数。

$ ros list-regions -h
usage: ros list-regions [-h]

optional arguments:
  -h, --help  show this help message and exit

列出事件
$ ros list-events -h
usage: ros list-events [-h] --stack-name STACK_NAME --stack-id STACK_ID
                       [--resource-status {COMPLETE,FAILED,IN_PROGRESS}]
                       [--resource-name RESOURCE_NAME]
                       [--resource-type RESOURCE_TYPE]
                       [--page-number PAGE_NUMBER] [--page-size PAGE_SIZE]

optional arguments:
  -h, --help            show this help message and exit
  --stack-name STACK_NAME
                        The name that is associated with the stack
  --stack-id STACK_ID   The id that is associated with the stack
  --resource-status {COMPLETE,FAILED,IN_PROGRESS}
                        status of resources: COMPLETE\FAILED\IN_PROGRESS
  --resource-name RESOURCE_NAME
                        The name of resources
  --resource-type RESOURCE_TYPE
                        The type of resources
  --page-number PAGE_NUMBER
                        The page number of stack lists, start from 1, default
                        1
  --page-size PAGE_SIZE
                        Lines each page, max 100, default 10

设置用户数据

$ ros set-userdata -h
usage: ros set-userdata [-h] --key-id KEY_ID --key-secret KEY_SECRET
                    --region-id REGION_ID [--json-ident JSON_IDENT]
                    [--debug {False,True}]

optional arguments:
  -h, --help            show this help message and exit
  --key-id KEY_ID       The default Aliyun access key id
  --key-secret KEY_SECRET
                        The default Aliyun access key region
  --region-id REGION_ID
                        The default region
  --json-ident JSON_IDENT
                        The default json indent when output in json format
  --debug {False,True}  Whether to read debug infos

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何用java表示这个数学函数的算法   Java/Stream帮助:仅使用streams将嵌套的映射列表转换为映射   使用Selenium连接到数据库时发生java未知主机异常   java如何了解jvm内存使用:“堆内存”和“堆外内存”   java Oracle BI报告导入模板   java如何使用Spring将xml转换为bean?   java线程。join()以保证执行顺序   java从THINGSPEAK到ANDROID应用程序获取JSON数据   使用Java的stanford库中的异常   java正确使用来自其他类文件的方法   如果集合中的元素类型为接口类型,如何填充集合?(爪哇)   记录java。util。记录器创建的文件超过了应有的数量   类Java对象uniq值   尝试调用无法应用于()的方法时出现java错误