swift命令行操作

root@nova-control:~# swift -h
Usage: swift [options] [args]

Commands:
   stat [container] [object]
      Displays information for the account, container, or object depending on the  args given (if             any).
   list [options] [container]
      Lists the containers for the account or the objects for a container. -p or  --prefix is an             option that will only list items beginning with that prefix.
      -d or --delimiter is option (for container listings only) that will roll up  items with the 
      given delimiter (see Cloud Files general documentation for  what this means).
   upload [options] container file_or_directory [file_or_directory] [...]
      Uploads to the given container the files and directories specified by the  remaining args. -c 
      or --changed is an option that will only upload files  that have changed since the last 
      upload.  -S or --segment-size  and --leave-segments are options as well (see --help for more).
   post [options] [container] [object]
      Updates meta information for the account, container, or object depending on  the args given.          If  the container is not found, it will be created  automatically; but this is not true for 
      accounts and objects. Containers  also allow the -r (or --read-acl) and -w (or --write-acl) 
      options. The -m  or --meta option is allowed on all and used to define the user meta 
      data  items  to set in the form Name:Value. This option can be repeated. Example:
      post -m Color:Blue -m Size:Large
   download --all OR download container [options] [object] [object] ...
      Downloads everything in the account (with --all), or everything in a  container, or a list of 
      objects depending on the args given. For a single  object download, you may use the -o [--
      output] option to  redirect the output to a specific file or if "-" then just redirect 
      to  stdout.
   delete --all OR delete container [--leave-segments] [object] [object] ...
      Deletes everything in the account (with --all), or everything in a  container, or a list of 
      objects depending on the args given. Segments of  manifest objects will be deleted as well, 
      unless you specify the  --leave-segments option.

Example:
   swift -A https://auth.api.rackspacecloud.com/v1.0 -U user -K key stat
[ 注:可以这么理解.swift命令后跟的地址是验证地址(keystone的地址),理解为默认的去找keystone中的swift服务;想下:如果用curl,则要用到keystone返回给我们的地址(x-storage-url))]

Options:
   --version                                              show program's version number and exit
   -h, --help                                             show this help message and exit
   -s, --snet                                             Use SERVICENET internal network
   -v, --verbose                                        Print more info
   -q, --quiet                                           Suppress status output
   -A AUTH, --auth=AUTH                              URL for obtaining an auth token
   -V AUTH_VERSION, --auth-version=AUTH_VERSION
                                                               Specify a version for authentication(default: 1.0)
   -U USER, --user=USER                              User name for obtaining an auth token
   -K KEY, --key=KEY                                  Key for obtaining an auth token





 

 2.1. Authentication

Client authentication is provided via a ReST interface using the GET method, with v1.0 supplied as the path. Additionally, two headers are required, X-Auth-User and X-Auth-Key with values for the username and API Access Key respectively.

Each ReST request against the OpenStack Object Storage system requires the inclusion of a specific authorization token HTTP x-header, defined as X-Auth-Token. Clients obtain this token, along with the Cloud Servers API URL, by first using an authentication service and supplying a valid username and API access key.

 Request

To authenticate, you must supply your username and API access key in x-headers:

  • Use your OpenStack Object Storage (Swift) username as the username for the API. Place it in the X-Auth-User x-header.

  • Get your API access key from authentication service you chose when installing. You have some options for auth, including tempauth (which is included with Swift), swauth (an auth service for Swift as WSGI middleware that uses Swift itself as a backing store that is provided via download from Github), the OpenStack Identity Service (project named Keystone), or you can use your own authentication system. Place your access key in the X-Auth-Key x-header.

 

Example 2.1. Authentication HTTP Request

GET /v1.0 HTTP/1.1
Host: auth.api.yourcloud.com
X-Auth-User: jdoe
X-Auth-Key: a86850deb2742ec3cb41518e26aa2d89

 Response

When authentication is successful, an HTTP status 204 (No Content) is returned with the X-Storage-Url and X-Auth-Token headers. Any 2xx response is a good response. For example, a 202 response means the request has been accepted. Also, additional X- headers may be returned. These additional headers are related to other Rackspace services and can be ignored. An HTTP status of 401 (Unauthorized) is returned upon authentication failure. All subsequent container/object operations against OpenStack Object Storage should be made against the URI specified in X-Storage-Url and must include the X-Auth-Token header.

 

Example 2.2. Authentication HTTP Response

HTTP/1.1 204 No Content
Date: Mon, 12 Nov 2010 15:32:21 GMT
Server: Apache
X-Storage-Url: https://storage.swiftdrive.com/v1/CF_xer7_34
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
Content-Length: 0
Content-Type: text/plain; charset=UTF-8

The X-Storage-Url will need to be parsed and used in the connection and request line of all subsequent requests against Object Storage. In the example response above, users connecting to OpenStack Object Storage would send most container/object requests with a host header ofstorage.swiftdrive.com and the request line's version and account as /v1/CF_xer7_34. Note that authentication tokens are valid for a 24 hour period for many authentication configurations.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值