def get_entity_type(self, id: str) -> def_models.DefEntityType:
        """Get the entity type given an id.

        :param str id: Id of the interface.
        :return: Entity type
        :rtype: DefEntityType
        """
        response_body = self._cloudapi_client.do_request(
            method=RequestMethod.GET,
            cloudapi_version=CLOUDAPI_VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}/{id}")
        return def_models.DefEntityType(**response_body)
    def create_entity_type(
        self, entity_type: def_models.DefEntityType
    ) -> def_models.DefEntityType:  # noqa: E501
        """Create the Defined entity type.

        :param DefEntityType interface: body of the entity type
        :return: DefEntityType that is just created
        :rtype: DefEntityType
        """
        response_body = self._cloudapi_client.do_request(
            method=RequestMethod.POST,
            cloudapi_version=CLOUDAPI_VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}",
            payload=asdict(entity_type))
        return def_models.DefEntityType(**response_body)
Пример #3
0
    def create_entity_type(
        self, entity_type: def_models.DefEntityType
    ) -> def_models.DefEntityType:  # noqa: E501
        """Create the Defined entity type.

        :param DefEntityType interface: body of the entity type
        :return: DefEntityType that is just created
        :rtype: DefEntityType
        """
        if not self._cloudapi_client.is_sys_admin:
            raise ValueError("Cloud API Client should be sysadmin.")
        response_body = self._cloudapi_client.do_request(
            method=cse_shared_constants.RequestMethod.POST,
            cloudapi_version=CloudApiVersion.VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}",
            payload=asdict(entity_type))
        return def_models.DefEntityType(**response_body)
    def update_entity_type(
        self, entity_type: def_models.DefEntityType
    ) -> def_models.DefEntityType:  # noqa: E501
        """Update the entity type.

        As of May 2020, only name and schema of the entity type can be
        updated.

        :param entity_type: Entity type to be updated.
        :return: Updated entity type
        :rtype: DefEntityType
        """
        response_body = self._cloudapi_client.do_request(
            method=RequestMethod.PUT,
            cloudapi_version=CLOUDAPI_VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}/"
            f"{entity_type.id}",
            payload=asdict(entity_type))
        return def_models.DefEntityType(**response_body)
    def list_entity_types(self):
        """List Entity types.

        :return: Generator of entity types
        :rtype: Generator[DefEntityType]
        """
        page_num = 0
        while True:
            page_num += 1
            response_body = self._cloudapi_client.do_request(
                method=RequestMethod.GET,
                cloudapi_version=CLOUDAPI_VERSION_1_0_0,
                resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}?"
                f"page={page_num}")
            if len(response_body['values']) > 0:
                for entityType in response_body['values']:
                    yield def_models.DefEntityType(**entityType)
            else:
                break
Пример #6
0
    def update_entity_type(
        self, entity_type: def_models.DefEntityType
    ) -> def_models.DefEntityType:  # noqa: E501
        """Update the entity type.

        As of May 2020, only name and schema of the entity type can be
        updated.

        :param entity_type: Entity type to be updated.
        :return: Updated entity type
        :rtype: DefEntityType
        """
        if not self._cloudapi_client.is_sys_admin:
            raise ValueError("Cloud API Client should be sysadmin.")
        response_body = self._cloudapi_client.do_request(
            method=cse_shared_constants.RequestMethod.PUT,
            cloudapi_version=CloudApiVersion.VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}/"
            f"{entity_type.id}",
            payload=asdict(entity_type))
        return def_models.DefEntityType(**response_body)