Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: third_party/gsutil/gslib/commands/mb.py

Issue 2280023003: depot_tools: Remove third_party/gsutil (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/gsutil/gslib/commands/ls.py ('k') | third_party/gsutil/gslib/commands/mv.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2011 Google Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from gslib.command import Command
16 from gslib.command import COMMAND_NAME
17 from gslib.command import COMMAND_NAME_ALIASES
18 from gslib.command import CONFIG_REQUIRED
19 from gslib.command import FILE_URIS_OK
20 from gslib.command import MAX_ARGS
21 from gslib.command import MIN_ARGS
22 from gslib.command import PROVIDER_URIS_OK
23 from gslib.command import SUPPORTED_SUB_ARGS
24 from gslib.command import URIS_START_ARG
25 from gslib.exception import CommandException
26 from gslib.help_provider import HELP_NAME
27 from gslib.help_provider import HELP_NAME_ALIASES
28 from gslib.help_provider import HELP_ONE_LINE_SUMMARY
29 from gslib.help_provider import HELP_TEXT
30 from gslib.help_provider import HelpType
31 from gslib.help_provider import HELP_TYPE
32 from gslib.util import NO_MAX
33
34 _detailed_help_text = ("""
35 <B>SYNOPSIS</B>
36 gsutil mb [-c storage_class] [-l location] [-p proj_id] uri...
37
38
39 <B>DESCRIPTION</B>
40 The mb command creates a new bucket. Google Cloud Storage has a single
41 namespace, so you will not be allowed to create a bucket with a name already
42 in use by another user. You can, however, carve out parts of the bucket name
43 space corresponding to your company's domain name (see "gsutil help naming").
44
45 If you don't specify a project ID using the -p option, the bucket
46 will be created using the default project ID specified in your gsutil
47 configuration file (see "gsutil help config"). For more details about
48 projects see "gsutil help projects".
49
50 The -c and -l options specify the storage class and location, respectively,
51 for the bucket. Once a bucket is created in a given location and with a
52 given storage class, it cannot be moved to a different location, and the
53 storage class cannot be changed. Instead, you would need to create a new
54 bucket and move the data over and then delete the original bucket.
55
56
57 <B>BUCKET STORAGE CLASSES</B>
58 If you don't specify a -c option, the bucket will be created with the default
59 (standard) storage class.
60
61 If you specify -c DURABLE_REDUCED_AVAILABILITY (or -c DRA), it causes the data
62 stored in the bucket to use durable reduced availability storage. Buckets
63 created with this storage class have lower availability than standard storage
64 class buckets, but durability equal to that of buckets created with standard
65 storage class. This option allows users to reduce costs for data for which
66 lower availability is acceptable. Durable Reduced Availability storage would
67 not be appropriate for "hot" objects (i.e., objects being accessed frequently)
68 or for interactive workloads; however, it might be appropriate for other types
69 of applications. See the online documentation for pricing and SLA details.
70
71
72 <B>BUCKET LOCATIONS</B>
73 If you don't specify a -l option, the bucket will be created in the default
74 location (US). Otherwise, you can specify one of the available locations:
75 US (United States) or EU (Europe).
76
77
78 <B>OPTIONS</B>
79 -c storage_class Can be DRA (or DURABLE_REDUCED_AVAILABILITY) or S (or
80 STANDARD). Default is STANDARD.
81
82 -l location Can be US or EU. Default is US. Locations are case
83 insensitive.
84
85 -p proj_id Specifies the project ID under which to create the bucket.
86 """)
87
88
89 class MbCommand(Command):
90 """Implementation of gsutil mb command."""
91
92 # Command specification (processed by parent class).
93 command_spec = {
94 # Name of command.
95 COMMAND_NAME : 'mb',
96 # List of command name aliases.
97 COMMAND_NAME_ALIASES : ['makebucket', 'createbucket', 'md', 'mkdir'],
98 # Min number of args required by this command.
99 MIN_ARGS : 1,
100 # Max number of args required by this command, or NO_MAX.
101 MAX_ARGS : NO_MAX,
102 # Getopt-style string specifying acceptable sub args.
103 SUPPORTED_SUB_ARGS : 'c:l:p:',
104 # True if file URIs acceptable for this command.
105 FILE_URIS_OK : False,
106 # True if provider-only URIs acceptable for this command.
107 PROVIDER_URIS_OK : False,
108 # Index in args of first URI arg.
109 URIS_START_ARG : 0,
110 # True if must configure gsutil before running command.
111 CONFIG_REQUIRED : True,
112 }
113 help_spec = {
114 # Name of command or auxiliary help info for which this help applies.
115 HELP_NAME : 'mb',
116 # List of help name aliases.
117 HELP_NAME_ALIASES : ['createbucket', 'makebucket', 'md', 'mkdir',
118 'location', 'dra', 'dras', 'reduced_availability',
119 'durable_reduced_availability',
120 'rr', 'reduced_redundancy',
121 'standard', 'storage class' ],
122 # Type of help:
123 HELP_TYPE : HelpType.COMMAND_HELP,
124 # One line summary of this help.
125 HELP_ONE_LINE_SUMMARY : 'Make buckets',
126 # The full help text.
127 HELP_TEXT : _detailed_help_text,
128 }
129
130 # Command entry point.
131 def RunCommand(self):
132 location = ''
133 storage_class = ''
134 if self.sub_opts:
135 for o, a in self.sub_opts:
136 if o == '-l':
137 location = a
138 elif o == '-p':
139 self.proj_id_handler.SetProjectId(a)
140 elif o == '-c':
141 storage_class = self._Normalize_Storage_Class(a)
142
143 if not self.headers:
144 headers = {}
145 else:
146 headers = self.headers.copy()
147
148 for bucket_uri_str in self.args:
149 bucket_uri = self.suri_builder.StorageUri(bucket_uri_str)
150 if not bucket_uri.names_bucket():
151 raise CommandException('The mb command requires a URI that specifies a '
152 'bucket.\n"%s" is not valid.' % bucket_uri)
153 self.proj_id_handler.FillInProjectHeaderIfNeeded('mb', bucket_uri,
154 headers)
155 print 'Creating %s...' % bucket_uri
156 # Pass storage_class param only if this is a GCS bucket. (In S3 the
157 # storage class is specified on the key object.)
158 if bucket_uri.scheme == 'gs':
159 bucket_uri.create_bucket(headers=headers, location=location,
160 storage_class=storage_class)
161 else:
162 bucket_uri.create_bucket(headers=headers, location=location)
163
164 return 0
165
166 def _Normalize_Storage_Class(self, sc):
167 sc = sc.upper()
168 if sc in ('DRA', 'DURABLE_REDUCED_AVAILABILITY'):
169 return 'DURABLE_REDUCED_AVAILABILITY'
170 if sc in ('S', 'STD', 'STANDARD'):
171 return 'STANDARD'
172 return sc
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/commands/ls.py ('k') | third_party/gsutil/gslib/commands/mv.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698