diff --git a/magnum/api/controllers/v1/pod.py b/magnum/api/controllers/v1/pod.py index 503dd2d6f7..28b337063b 100644 --- a/magnum/api/controllers/v1/pod.py +++ b/magnum/api/controllers/v1/pod.py @@ -55,6 +55,9 @@ class Pod(v1_base.K8sResourceBase): links = wsme.wsattr([link.Link], readonly=True) """A list containing a self link and associated pod links""" + host = wtypes.text + """The host of this pod""" + def __init__(self, **kwargs): super(Pod, self).__init__() @@ -70,7 +73,7 @@ class Pod(v1_base.K8sResourceBase): def _convert_with_links(pod, url, expand=True): if not expand: pod.unset_fields_except(['uuid', 'name', 'desc', 'bay_uuid', - 'images', 'labels', 'status']) + 'images', 'labels', 'status', 'host']) pod.links = [link.Link.make_link('self', url, 'pods', pod.uuid), @@ -94,6 +97,7 @@ class Pod(v1_base.K8sResourceBase): images=['MyImage'], labels={'name': 'foo'}, status='Running', + host='10.0.0.3', manifest_url='file:///tmp/rc.yaml', manifest = '''{ "metadata": { diff --git a/magnum/conductor/handlers/k8s_conductor.py b/magnum/conductor/handlers/k8s_conductor.py index 0f049138ed..2b65a268ba 100644 --- a/magnum/conductor/handlers/k8s_conductor.py +++ b/magnum/conductor/handlers/k8s_conductor.py @@ -176,6 +176,7 @@ class Handler(object): message = ast.literal_eval(err.read())['message'] raise exception.KubernetesAPIFailed(code=err.code, message=message) pod.status = resp.status.phase + pod.host = resp.spec.host # call the pod object to persist in db # TODO(yuanying): parse pod file and, # - extract pod name and set it diff --git a/magnum/db/sqlalchemy/alembic/versions/53882537ac57_add_host_column_to_pod.py b/magnum/db/sqlalchemy/alembic/versions/53882537ac57_add_host_column_to_pod.py new file mode 100644 index 0000000000..8056a3f2e9 --- /dev/null +++ b/magnum/db/sqlalchemy/alembic/versions/53882537ac57_add_host_column_to_pod.py @@ -0,0 +1,32 @@ +# Copyright 2015 Huawei Technologies Co.,LTD. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +"""add host column to pod + +Revision ID: 53882537ac57 +Revises: 1c1ff5e56048 +Create Date: 2015-06-25 16:52:47.159887 + +""" + +# revision identifiers, used by Alembic. +revision = '53882537ac57' +down_revision = '1c1ff5e56048' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('pod', + sa.Column('host', sa.Text, nullable=True)) diff --git a/magnum/db/sqlalchemy/models.py b/magnum/db/sqlalchemy/models.py index a0f3b480b8..71cd1d173e 100644 --- a/magnum/db/sqlalchemy/models.py +++ b/magnum/db/sqlalchemy/models.py @@ -229,6 +229,7 @@ class Pod(Base): status = Column(String(255)) project_id = Column(String(255)) user_id = Column(String(255)) + host = Column(String(255)) class Service(Base): diff --git a/magnum/objects/pod.py b/magnum/objects/pod.py index 430116276f..68c3c5bc6a 100644 --- a/magnum/objects/pod.py +++ b/magnum/objects/pod.py @@ -40,6 +40,7 @@ class Pod(base.MagnumPersistentObject, base.MagnumObject, 'status': fields.StringField(nullable=True), 'manifest_url': fields.StringField(nullable=True), 'manifest': fields.StringField(nullable=True), + 'host': fields.StringField(nullable=True), } @staticmethod diff --git a/magnum/tests/unit/api/controllers/v1/test_pod.py b/magnum/tests/unit/api/controllers/v1/test_pod.py index 35b75ba10b..81f10b6985 100644 --- a/magnum/tests/unit/api/controllers/v1/test_pod.py +++ b/magnum/tests/unit/api/controllers/v1/test_pod.py @@ -48,7 +48,8 @@ class TestListPod(api_base.FunctionalTest): self.assertEqual([], response['pods']) def _assert_pod_fields(self, pod): - pod_fields = ['name', 'bay_uuid', 'desc', 'images', 'labels', 'status'] + pod_fields = ['name', 'bay_uuid', 'desc', 'images', 'labels', + 'status', 'host'] for field in pod_fields: self.assertIn(field, pod) diff --git a/magnum/tests/unit/conductor/handlers/test_k8s_conductor.py b/magnum/tests/unit/conductor/handlers/test_k8s_conductor.py index a63e2a775e..4d1f8d39c6 100644 --- a/magnum/tests/unit/conductor/handlers/test_k8s_conductor.py +++ b/magnum/tests/unit/conductor/handlers/test_k8s_conductor.py @@ -136,10 +136,13 @@ class TestK8sConductor(base.TestCase): return_value = mock.MagicMock() return_value.status = mock.MagicMock() return_value.status.phase = 'Pending' + return_value.spec = mock.MagicMock() + return_value.spec.host = '10.0.0.3' mock_kube_api.return_value.createPod.return_value = return_value self.kube_handler.pod_create(self.context, expected_pod) self.assertEqual('Pending', expected_pod.status) + self.assertEqual('10.0.0.3', expected_pod.host) expected_pod.create.assert_called_once_with(self.context) @patch('magnum.conductor.handlers.k8s_conductor._retrieve_k8s_master_url') diff --git a/magnum/tests/unit/db/utils.py b/magnum/tests/unit/db/utils.py index eae387ed6b..11d3a1ebd6 100644 --- a/magnum/tests/unit/db/utils.py +++ b/magnum/tests/unit/db/utils.py @@ -97,6 +97,7 @@ def get_test_pod(**kw): 'images': kw.get('images', ['MyImage']), 'labels': kw.get('labels', {'name': 'foo'}), 'status': kw.get('status', 'Running'), + 'host': kw.get('host', '10.0.0.3'), 'created_at': kw.get('created_at'), 'updated_at': kw.get('updated_at'), }