-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff -zun -glance image tag support_v1
277 lines (253 loc) · 11 KB
/
diff -zun -glance image tag support_v1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
diff --git a/zun/api/controllers/v1/containers.py b/zun/api/controllers/v1/containers.py
index 603ae12..cc68d78 100644
--- a/zun/api/controllers/v1/containers.py
+++ b/zun/api/controllers/v1/containers.py
@@ -248,6 +248,7 @@ class ContainersController(base.Controller):
# container create will fail with 400 status.
images = compute_api.image_search(context, container_dict['image'],
container_dict.get('image_driver'),
+ container_dict.get('image_tag'),
True)
if not images:
raise exception.ImageNotFound(image=container_dict['image'])
diff --git a/zun/api/controllers/v1/schemas/containers.py b/zun/api/controllers/v1/schemas/containers.py
index 7761ece..b464e15 100644
--- a/zun/api/controllers/v1/schemas/containers.py
+++ b/zun/api/controllers/v1/schemas/containers.py
@@ -28,6 +28,7 @@ _container_properties = {
'restart_policy': parameter_types.restart_policy,
'interactive': parameter_types.boolean,
'image_driver': parameter_types.image_driver,
+ 'image_tag': parameter_types.image_tag,
'security_groups': parameter_types.security_groups,
'hints': parameter_types.hints,
'nets': parameter_types.nets
diff --git a/zun/api/controllers/v1/views/containers_view.py b/zun/api/controllers/v1/views/containers_view.py
index e8bb954..f87e3a7 100644
--- a/zun/api/controllers/v1/views/containers_view.py
+++ b/zun/api/controllers/v1/views/containers_view.py
@@ -38,6 +38,7 @@ _basic_keys = (
'status_detail',
'interactive',
'image_driver',
+ 'image_tag',
'security_groups',
'auto_remove',
)
diff --git a/zun/common/validation/parameter_types.py b/zun/common/validation/parameter_types.py
index c8fa556..26e2578 100644
--- a/zun/common/validation/parameter_types.py
+++ b/zun/common/validation/parameter_types.py
@@ -49,6 +49,13 @@ image_driver = {
'enum': image_driver_list_with_none
}
+image_tag = {
+ 'type': 'string',
+ 'minLength': 2,
+ 'maxLength': 255,
+ 'pattern': '[a-zA-Z0-9][a-zA-Z0-9_.-]+$'
+}
+
container_name = {
'type': ['string', 'null'],
'minLength': 2,
diff --git a/zun/compute/api.py b/zun/compute/api.py
index fd0d6ad..7dd8ae0 100644
--- a/zun/compute/api.py
+++ b/zun/compute/api.py
@@ -130,8 +130,8 @@ class API(object):
def image_pull(self, context, image):
return self.rpcapi.image_pull(context, image)
- def image_search(self, context, image, image_driver, *args):
- return self.rpcapi.image_search(context, image, image_driver, *args)
+ def image_search(self, context, image, image_driver, image_tag, *args):
+ return self.rpcapi.image_search(context, image, image_driver, image_tag, *args)
def capsule_create(self, context, new_capsule,
requested_networks=None, extra_spec=None):
diff --git a/zun/compute/manager.py b/zun/compute/manager.py
index d9350a5..a6aa1a8 100644
--- a/zun/compute/manager.py
+++ b/zun/compute/manager.py
@@ -91,7 +91,8 @@ class Manager(periodic_task.PeriodicTasks):
def _do_container_create_base(self, context, container, requested_networks,
sandbox=None, limits=None, reraise=False):
self._update_task_state(context, container, consts.IMAGE_PULLING)
- repo, tag = utils.parse_image_name(container.image)
+ repo, tag = container.image, container.image_tag
+ #repo, tag = utils.parse_image_name(container.image)
image_pull_policy = utils.get_image_pull_policy(
container.image_pull_policy, tag)
image_driver_name = container.image_driver
@@ -644,11 +645,11 @@ class Manager(periodic_task.PeriodicTasks):
raise
@translate_exception
- def image_search(self, context, image, image_driver_name, exact_match):
+ def image_search(self, context, image, image_driver_name, image_tag, exact_match):
LOG.debug('Searching image...', image=image)
try:
return image_driver.search_image(context, image,
- image_driver_name, exact_match)
+ image_driver_name, image_tag, exact_match)
except Exception as e:
LOG.exception("Unexpected exception while searching image: %s",
six.text_type(e))
diff --git a/zun/compute/rpcapi.py b/zun/compute/rpcapi.py
index a4b272b..81dfacf 100644
--- a/zun/compute/rpcapi.py
+++ b/zun/compute/rpcapi.py
@@ -166,13 +166,14 @@ class API(rpc_service.API):
host = None
self._cast(host, 'image_pull', image=image)
- def image_search(self, context, image, image_driver, exact_match):
+ def image_search(self, context, image, image_driver, image_tag, exact_match):
# NOTE(hongbin): Image API doesn't support multiple compute nodes
# scenario yet, so we temporarily set host to None and rpc will
# choose an arbitrary host.
host = None
return self._call(host, 'image_search', image=image,
image_driver_name=image_driver,
+ image_tag=image_tag,
exact_match=exact_match)
def capsule_create(self, context, host, capsule,
diff --git a/zun/db/sqlalchemy/alembic/versions/20450295927a_add_image_tag_to_container.py b/zun/db/sqlalchemy/alembic/versions/20450295927a_add_image_tag_to_container.py
new file mode 100644
index 0000000..2deeda6
--- /dev/null
+++ b/zun/db/sqlalchemy/alembic/versions/20450295927a_add_image_tag_to_container.py
@@ -0,0 +1,22 @@
+"""Add image_tag to container
+
+Revision ID: 20450295927a
+Revises: a251f1f61217
+Create Date: 2017-08-22 13:23:56.181499
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '20450295927a'
+down_revision = 'a251f1f61217'
+branch_labels = None
+depends_on = None
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ op.add_column('container',
+ sa.Column('image_tag', sa.String(length=255),
+ nullable=True))
diff --git a/zun/db/sqlalchemy/models.py b/zun/db/sqlalchemy/models.py
index b28c9ff..43fcf6d 100644
--- a/zun/db/sqlalchemy/models.py
+++ b/zun/db/sqlalchemy/models.py
@@ -155,7 +155,7 @@ class Container(Base):
websocket_token = Column(String(255))
security_groups = Column(JSONEncodedList)
auto_remove = Column(Boolean, default=False)
-
+ image_tag = Column(String(255))
class Image(Base):
"""Represents an image. """
diff --git a/zun/image/driver.py b/zun/image/driver.py
index 308cabc..a8ea757 100644
--- a/zun/image/driver.py
+++ b/zun/image/driver.py
@@ -84,9 +84,9 @@ def pull_image(context, repo, tag, image_pull_policy='always',
return image, image_loaded
-def search_image(context, image_name, image_driver, exact_match):
+def search_image(context, image_name, image_driver, image_tag, exact_match):
images = []
- repo, tag = parse_image_name(image_name)
+ repo, tag = image_name, image_tag
if image_driver:
image_driver_list = [image_driver.lower()]
else:
diff --git a/zun/objects/container.py b/zun/objects/container.py
index eaa9c7f..5b3b3b4 100644
--- a/zun/objects/container.py
+++ b/zun/objects/container.py
@@ -38,7 +38,8 @@ class Container(base.ZunPersistentObject, base.ZunObject):
# Version 1.16: Add websocket_url and token
# Version 1.17: Add security_groups
# Version 1.18: Add auto_remove
- VERSION = '1.18'
+ # Version 1.19: Add image_tag
+ VERSION = '1.19'
fields = {
'id': fields.IntegerField(),
@@ -68,6 +69,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
'status_detail': fields.StringField(nullable=True),
'interactive': fields.BooleanField(nullable=True),
'image_driver': fields.StringField(nullable=True),
+ 'image_tag': fields.StringField(nullable=True),
'websocket_url': fields.StringField(nullable=True),
'websocket_token': fields.StringField(nullable=True),
'security_groups': fields.ListOfStringsField(nullable=True),
___________________________________
diff --git a/zunclient/v1/containers.py b/zunclient/v1/containers.py
index 16100d4..ae94101 100644
--- a/zunclient/v1/containers.py
+++ b/zunclient/v1/containers.py
@@ -22,7 +22,8 @@ from zunclient import exceptions
CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory',
'environment', 'workdir', 'labels', 'image_pull_policy',
'restart_policy', 'interactive', 'image_driver',
- 'security_groups', 'hints', 'nets', 'auto_remove']
+ 'image_tag', 'security_groups', 'hints', 'nets',
+ 'auto_remove']
class Container(base.Resource):
diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py
index 4ff19b2..45887ff 100644
--- a/zunclient/v1/containers_shell.py
+++ b/zunclient/v1/containers_shell.py
@@ -84,6 +84,12 @@ def _show_container(container):
'It can have following values: '
'"docker": pull the image from Docker Hub. '
'"glance": pull the image from Glance. ')
[email protected]('--image-tag',
+ metavar='<image_tag_name>',
+ help='The image tag to specify the additional metadata '
+ 'information about the image ex. version.'
+ 'It can have any alphanumeric values.'
+ '(optional parameter with --image-driver "glance")')
@utils.arg('--security-group',
metavar='<security-group>',
action='append', default=[],
@@ -125,6 +131,7 @@ def do_create(cs, args):
opts['labels'] = zun_utils.format_args(args.label)
opts['image_pull_policy'] = args.image_pull_policy
opts['image_driver'] = args.image_driver
+ opts['image_tag'] = args.image_tag
opts['hints'] = zun_utils.format_args(args.hint)
opts['nets'] = zun_utils.parse_nets(args.net)
--------------------------------------
(glance image_tag support)
def find_image(image_ident, image_tag):
matches = find_images(image_ident, exact_match=True)
# print('Found matches %s ', len(matches))
match = []
for i in range(len(matches)):
# for i in matches:
print(i)
print('%s......%s.., .%s...%d..'%(image_tag, matches[i]['tags'],type(matches[i]['tags']),i))
if matches[i]['tags']:
if len(image_tag) < len(matches[i]['tags']):
data1, data2 = image_tag, matches[i]['tags']
else:
data1, data2 = matches[i]['tags'], image_tag
if all(map(lambda x: x in data1, data2)):
# if image_tag == encodeutils.safe_decode(matches[i]['tags'][0]):
match.append(matches[i])
else:
match.append(matches[i])
if len(match) == 1:
print(match)
if len(match) == 0:
print("ImageNotFound")
if len(match) > 1:
msg = ("Multiple images exist with same name "
"%(image_ident)s. Please use the image id "
"instead.") % {'image_ident': image_ident}
print(msg)
#raise exception.Conflict(msg)