Exemple #1
0
    def pod_list(self, context, bay_ident):
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        try:
            resp = self.k8s_api.list_namespaced_pod(namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.PodListNotFound(bay_uuid=bay.uuid)

        pods = []
        for pod_entry in resp.items:
            pod = {}
            pod['uuid'] = pod_entry.metadata.uid
            pod['name'] = pod_entry.metadata.name
            pod['project_id'] = context.project_id
            pod['user_id'] = context.user_id
            pod['bay_uuid'] = bay.uuid
            pod['images'] = [c.image for c in pod_entry.spec.containers]
            if not pod_entry.metadata.labels:
                pod['labels'] = {}
            else:
                pod['labels'] = ast.literal_eval(pod_entry.metadata.labels)
            pod['status'] = pod_entry.status.phase
            pod['host'] = pod_entry.spec.node_name

            pod_obj = objects.Pod(context, **pod)
            pods.append(pod_obj)

        return pods
Exemple #2
0
 def test_create(self):
     with mock.patch.object(self.dbapi, 'create_pod',
                            autospec=True) as mock_create_pod:
         mock_create_pod.return_value = self.fake_pod
         pod = objects.Pod(self.context, **self.fake_pod)
         pod.create()
         mock_create_pod.assert_called_once_with(self.fake_pod)
         self.assertEqual(self.context, pod._context)
Exemple #3
0
def get_test_pod(context, **kw):
    """Return a Pod object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_pod = db_utils.get_test_pod(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_pod['id']
    pod = objects.Pod(context)
    for key in db_pod:
        setattr(pod, key, db_pod[key])
    return pod
Exemple #4
0
    def post(self, pod):
        """Create a new pod.

        :param pod: a pod within the request body.
        """
        pod.parse_manifest()
        pod_dict = pod.as_dict()
        context = pecan.request.context
        pod_dict['project_id'] = context.project_id
        pod_dict['user_id'] = context.user_id
        pod_obj = objects.Pod(context, **pod_dict)
        new_pod = pecan.request.rpcapi.pod_create(pod_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('pods', new_pod.uuid)
        return Pod.convert_with_links(new_pod)
Exemple #5
0
    def test_retrieve_k8s_api_endpoint(self, mock_bay_get_by_uuid):
        expected_context = 'context'
        expected_api_address = 'api_address'
        expected_protocol = cfg.CONF.kubernetes.k8s_protocol

        resource = objects.Pod({})
        resource.bay_uuid = 'bay_uuid'
        bay = objects.Bay({})
        bay.api_address = expected_api_address

        mock_bay_get_by_uuid.return_value = bay

        actual_api_endpoint = k8s_api.K8sAPI._retrieve_k8s_api_endpoint(
            expected_context, resource)
        self.assertEqual("%s://%s" % (expected_protocol,
                                      expected_api_address),
                         actual_api_endpoint)
Exemple #6
0
    def post(self, pod):
        """Create a new pod.

        :param pod: a pod within the request body.
        """
        if self.from_pods:
            raise exception.OperationNotPermitted

        pod.parse_manifest()
        pod_dict = pod.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        pod_dict['project_id'] = auth_token['project']['id']
        pod_dict['user_id'] = auth_token['user']['id']
        pod_obj = objects.Pod(context, **pod_dict)
        new_pod = pecan.request.rpcapi.pod_create(pod_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('pods', new_pod.uuid)
        return Pod.convert_with_links(new_pod)
Exemple #7
0
 def test_retrieve_bay_from_pod(self, mock_bay_get_by_uuid):
     pod = objects.Pod({})
     pod.bay_uuid = '5d12f6fd-a196-4bf0-ae4c-1f639a523a52'
     self._test_retrieve_bay(pod.bay_uuid, mock_bay_get_by_uuid)
 def mock_pod(self):
     return objects.Pod({})
Exemple #9
0
 def test_retrieve_bay_from_pod(self,
                                mock_bay_get_by_uuid):
     self._test_retrieve_bay(objects.Pod({}), mock_bay_get_by_uuid)