Pod create need filename as parameter
This is the backend change for patch I254a20a The k8s pod create only has one parameter as filename, this patch is updating magnum backend api can use filename as parameter when creating pod. Change-Id: Ibdc05415ce2cb4e30f1d5687b03f2c0761047dec
This commit is contained in:
parent
66047a39d6
commit
426009cf03
|
@ -90,6 +90,9 @@ class Pod(base.APIBase):
|
|||
status = wtypes.text
|
||||
"""Staus of this pod """
|
||||
|
||||
pod_definition_url = wtypes.text
|
||||
"""URL for pod file to create the pod"""
|
||||
|
||||
links = wsme.wsattr([link.Link], readonly=True)
|
||||
"""A list containing a self link and associated pod links"""
|
||||
|
||||
|
@ -307,6 +310,9 @@ class PodsController(rest.RestController):
|
|||
|
||||
# Update only the fields that have changed
|
||||
for field in objects.Pod.fields:
|
||||
# ignore pod_definition_url as it was used for create pod
|
||||
if field == 'pod_definition_url':
|
||||
continue
|
||||
try:
|
||||
patch_val = getattr(pod, field)
|
||||
except AttributeError:
|
||||
|
|
|
@ -96,7 +96,13 @@ class KubeClient(object):
|
|||
def pod_create(contents):
|
||||
LOG.debug("pod_create contents %s" % contents)
|
||||
try:
|
||||
out, err = utils.trycmd('kubectl', 'create', '-f', contents)
|
||||
if contents.pod_definition_url:
|
||||
out, err = utils.trycmd('kubectl', 'create', '-f',
|
||||
contents.pod_definition_url)
|
||||
else:
|
||||
# TODO(jay-lau-513) Translate the contents to a json stdin
|
||||
out, err = utils.trycmd('echo contents | kubectl', 'create',
|
||||
'-f', '-')
|
||||
if err:
|
||||
return False
|
||||
except Exception as e:
|
||||
|
|
|
@ -35,12 +35,16 @@ class Pod(base.MagnumObject):
|
|||
'images': obj_utils.list_or_none,
|
||||
'labels': obj_utils.dict_or_none,
|
||||
'status': obj_utils.str_or_none,
|
||||
'pod_definition_url': obj_utils.str_or_none,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _from_db_object(pod, db_pod):
|
||||
"""Converts a database entity to a formal object."""
|
||||
for field in pod.fields:
|
||||
# ignore pod_definition_url as it was used for create pod
|
||||
if field == 'pod_definition_url':
|
||||
continue
|
||||
pod[field] = db_pod[field]
|
||||
|
||||
pod.obj_reset_changes()
|
||||
|
|
|
@ -29,7 +29,8 @@ class TestPodController(db_base.DbTestCase):
|
|||
# Create a pod
|
||||
params = '{"name": "pod_example_A", "desc": "My Pod",' \
|
||||
'"bay_uuid": "7ae81bb3-dec3-4289-8d6c-da80bd8001ae",' \
|
||||
'"images": ["ubuntu"], "labels": {"foo": "foo1"}}'
|
||||
'"images": ["ubuntu"], "labels": {"foo": "foo1"},' \
|
||||
'"pod_definition_url": "http://172.17.1.2/pod.json"}'
|
||||
response = self.app.post('/v1/pods',
|
||||
params=params,
|
||||
content_type='application/json')
|
||||
|
|
Loading…
Reference in New Issue