6. CLI手册

uos.cli是从官方的 python-openstackclient fork 而来,部分命令输出有修改。为了避免和官方的CLI冲突,重命名为uos.cli,命令为 uos

Note

python-openstackclient是官方的统一CLI项目,项目本身依赖于各个client(keystoneclient, novaclient, cinderclient....)。原先各个client项目中的命令行部分会不再进行维护,各个client只作为sdk使用。

uos.cli与官方的python-openstackclient项目无法同时安装在一个环境里,要想同时安装,可使用virtualenv等工具进行隔离。

6.1. 安装

6.1.1. 准备工作

uos.cli安装包依赖于cryptography,如果本机没有安装过cryptography,则需要先安装相应的基础包。

Note

不需要执行 pip install cryptography,在安装uos.cli的会自动安装cryptography。

For Debian and Ubuntu:

$ sudo apt-get install build-essential libssl-dev libffi-dev python-dev

For Fedora and RHEL-derivatives:

$ sudo yum install gcc libffi-devel python-devel openssl-devel

关于cryptography的安装指南可参考: https://cryptography.io/en/latest/installation/

6.1.2. 安装

pip install uos.cli

6.1.3. 升级

pip install -U uos.cli

6.1.4. 常见安装问题

  1. 安装cryptography失败

    请参考上文,确认依赖包都安装成功。

  2. pbr包冲突

    出现类似以下错误:

    pkg_resources.VersionConflict: (pbr 0.10.0 (/Library/Python/2.7/site-packages), Requirement.parse('pbr>=1.3'))

    执行以下命令手动升级pbr包,然后重新安装uos.cli:

    pip install -U pbr
  3. 提示ImportError: No module named xmlrpc_client

    这是由于OSX自带six包不满足要求导致,执行:

    pip uninstall six
    easy_install six
  4. 在Mac OSX环境安装遇到问题

    Mac下在安装一些python的c扩展依赖时可能会遇到以下错误:

    clang: error: unknown argument: '-mno-fused-madd'
    [-Wunused-command-line-argument-hard-error-in-future]

    修复:

    export CFLAGS=-Qunused-arguments
    export CPPFLAGS=-Qunused-arguments

6.2. 配置

本地需要一份类似官方openrc的文件, 修改最后一行OS_PASSWORD的值:

export OS_IDENTITY_API_VERSION=3
export OS_COMPUTE_API_VERSION=2
export OS_IMAGE_API_VERSION=2
export OS_NETWORK_API_VERSION=2
export OS_VOLUME_API_VERSION=1

export OS_AUTH_URL=https://identity.api.ustack.com

export OS_PROJECT_DOMAIN_ID=de08ac4e8db04c4b954a333c259f7b31
export OS_USER_DOMAIN_ID=de08ac4e8db04c4b954a333c259f7b31

export OS_PROJECT_NAME=shaoguojian_project
export OS_PROJECT_ID=2d3e2084c73f4a188f5052200c270030
export OS_REGION_NAME=bj1

export OS_USERNAME=shaoguojian
export OS_USER_ID=db41ba321e4c4311b4ec74390da0ffa1

export OS_PASSWORD=your_password

Note

这份openrc可以在标准部署的openstack下工作,只是需要注意的是UOS环境的keystone 只开放v3版本的认证接口。

6.3. 使用

在bash中:

>> source openrc
>> uos
(uos)          # you enter interactive shell
(uos) help

Shell commands (type help <topic>):
===================================
cmdenvironment  edit  hi       l   list  pause  r    save  shell      show
ed              help  history  li  load  py     run  set   shortcuts

Undocumented commands:
======================
EOF  eof  exit  q  quit

Application commands (type help <topic>):
=========================================
access token create         mapping list                  volume qos set
aggregate add host          mapping set                   volume qos show
aggregate create            mapping show                  volume qos unset
aggregate delete            module list                   volume set
aggregate list              network create                volume show
aggregate remove host       network delete                volume type create
aggregate set               network list                  volume type delete
aggregate show              network set                   volume type list
availability zone list      network show                  volume type set
backup create               policy create                 volume type show
backup delete               policy delete                 volume type unset
backup list                 policy list                   volume unset
backup restore              policy set
backup show                 policy show
catalog list                project create
catalog show                project delete
command list                project list
complete                    project set
compute agent create        project show
compute agent delete        project usage list
compute agent list          quota set
compute agent set           quota show
compute service list        region create
compute service set         region delete
configuration show          region list
console log show            region set
console url show            region show
consumer create             request token authorize
consumer delete             request token create
consumer list               role add
consumer set                role assignment list
consumer show               role create
credential create           role delete
credential delete           role list
credential list             role remove
credential set              role set
credential show             role show
domain create               security group create
domain delete               security group delete
domain list                 security group list
domain set                  security group rule create
domain show                 security group rule delete
ec2 credentials create      security group rule list
ec2 credentials delete      security group set
ec2 credentials list        security group show
ec2 credentials show        server add security group
endpoint create             server add volume
endpoint delete             server create
endpoint list               server delete
endpoint set                server image create
endpoint show               server list
extension list              server lock
federation domain list      server migrate
federation project list     server pause
federation protocol create  server reboot
federation protocol delete  server rebuild
federation protocol list    server remove security group
federation protocol set     server remove volume
federation protocol show    server rescue
flavor create               server resize
flavor delete               server resume
flavor list                 server set
flavor set                  server show
flavor show                 server ssh
flavor unset                server suspend
group add user              server unlock
group contains user         server unpause
group create                server unrescue
group delete                server unset
group list                  service create
group remove user           service delete
group set                   service list
group show                  service provider create
help                        service provider delete
host list                   service provider list
host show                   service provider set
hypervisor list             service provider show
hypervisor show             service set
hypervisor stats show       service show
identity provider create    snapshot create
identity provider delete    snapshot delete
identity provider list      snapshot list
identity provider set       snapshot set
identity provider show      snapshot show
image add project           snapshot unset
image delete                token issue
image list                  trust create
image remove project        trust delete
image save                  trust list
image set                   trust show
image show                  usage list
ip fixed add                usage show
ip fixed remove             user create
ip floating add             user delete
ip floating create          user list
ip floating delete          user password set
ip floating list            user set
ip floating pool list       user show
ip floating remove          volume create
keypair create              volume delete
keypair delete              volume list
keypair list                volume qos associate
keypair show                volume qos create
limits show                 volume qos delete
mapping create              volume qos disassociate
mapping delete              volume qos list

(uos) image list
+--------------------------------------+--------------------------------------------------------------+
| ID                                   | Name                                                         |
+--------------------------------------+--------------------------------------------------------------+
| 89528110-2380-4473-a075-01b391cee93e | Fedora 22 64bit                                              |
| dd544f1f-9d7a-4c7e-9a1c-fbe5cf543a0b | Fedora Cloud Atomic 22 64bit                                 |
| c9c04c16-d1f5-47c0-9a6c-d5b334f62997 | CoreOS Stable 681.0.0                                        |
.....

(uos) flavor list
+--------------------------------------+-------------+-------+------+-----------+-------+-----------+
| ID                                   | Name        |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+-------------+-------+------+-----------+-------+-----------+
| 215ea357-2d56-4387-9991-0c083806e3f8 | compute-12  | 12288 |   20 |         0 |    12 | True      |
| 21c0cf18-d0dc-43ab-8fdb-40ba8b0935d9 | memory-2    |  8192 |   20 |         0 |     2 | True      |
| 270a6d65-d1da-4a15-ad3a-7bcf969839e5 | compute-8   |  8192 |   20 |         0 |     8 | True      |
| 3332c026-533a-43d0-b415-abd3fdab09bf | micro-2     |  1024 |   20 |         0 |     1 | True      |
....

(uos) net list
+--------------------------------------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| ID                                   | Name        | Subnets                                                                                                                                                |
+--------------------------------------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| 04ab3521-9f61-4dfc-8000-85a233670209 | adsf        | 2cbb3f78-0c9a-4070-af29-6bd19868c4c7, ea06814e-e402-4128-b6fd-5931ffd30f0e                                                                             |
| 502b0717-751c-4d05-a7e3-d0f76ea9c2c7 | private-net | 74a5352d-be2a-4f07-95a2-056a1964f38d                                                                                                                   |
| ba05e057-1eb8-4cb2-af58-9b99a72df5ed | shared      | 0383c257-d730-4bbc-bd20-c7482bc925e8, 1efecef6-7a35-4b20-8ff8-c8f8761b131d, 3b426a5f-db56-4e56-a57d-5e493c5957ff, acc52025-1a74-474d-baea-9cea335b682a |
| ddabcc63-8617-465c-8a6d-f534000887e3 | BGP         | 293eff08-7d94-4335-bc2f-5ab9313b9f16, c869445a-ae60-44bd-acdf-ef947ee932f4, f9eafd3e-e6f6-4c20-9a8a-15ad061f2840                                       |
+--------------------------------------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
...