2
# Copyright (c) 2010 OpenStack, LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
18
from optparse import OptionParser
19
from os.path import basename
20
from sys import argv, exit
22
from swift.common.bufferedhttp import http_connect_raw as http_connect
23
from swift.common.utils import urlparse
26
if __name__ == '__main__':
27
gettext.install('swift', unicode=1)
28
parser = OptionParser(usage='Usage: %prog [options] <account>')
29
parser.add_option('-s', '--suffix', dest='suffix',
30
default='', help='The suffix to use with the reseller prefix as the '
31
'storage account name (default: <randomly-generated-uuid4>) Note: If '
32
'the account already exists, this will have no effect on existing '
33
'service URLs. Those will need to be updated with '
34
'swauth-set-account-service')
35
parser.add_option('-A', '--admin-url', dest='admin_url',
36
default='http://127.0.0.1:8080/auth/', help='The URL to the auth '
37
'subsystem (default: http://127.0.0.1:8080/auth/)')
38
parser.add_option('-U', '--admin-user', dest='admin_user',
39
default='.super_admin', help='The user with admin rights to add users '
40
'(default: .super_admin).')
41
parser.add_option('-K', '--admin-key', dest='admin_key',
42
help='The key for the user with admin rights to add users.')
46
(options, args) = parser.parse_args(args)
48
parser.parse_args(['-h'])
50
parsed = urlparse(options.admin_url)
51
if parsed.scheme not in ('http', 'https'):
52
raise Exception('Cannot handle protocol scheme %s for url %s' %
53
(parsed.scheme, repr(options.admin_url)))
54
parsed_path = parsed.path
57
elif parsed_path[-1] != '/':
59
path = '%sv2/%s' % (parsed_path, account)
60
headers = {'X-Auth-Admin-User': options.admin_user,
61
'X-Auth-Admin-Key': options.admin_key}
63
headers['X-Account-Suffix'] = options.suffix
64
conn = http_connect(parsed.hostname, parsed.port, 'PUT', path, headers,
65
ssl=(parsed.scheme == 'https'))
66
resp = conn.getresponse()
67
if resp.status // 100 != 2:
68
exit('Account creation failed: %s %s' % (resp.status, resp.reason))