def get_interface(self, id: str) -> def_models.DefInterface:
        """Get the interface given an id.

        :param str id: Id if the interface.
        :return: Interface
        :rtype: DefInterface
        """
        response_body = self._cloudapi_client.do_request(
            method=RequestMethod.GET,
            cloudapi_version=CLOUDAPI_VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.INTERFACES}/{id}")
        return def_models.DefInterface(**response_body)
    def create_interface(
        self, interface: def_models.DefInterface
    ) -> def_models.DefInterface:  # noqa: E501
        """Create the Defined entity interface.

        :param DefInterface interface: body of the interface
        :return: Interface that is just created
        :rtype: DefInterface
        """
        response_body = self._cloudapi_client.do_request(
            method=RequestMethod.POST,
            cloudapi_version=CLOUDAPI_VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.INTERFACES}",
            payload=asdict(interface))
        return def_models.DefInterface(**response_body)
Beispiel #3
0
    def create_interface(
        self, interface: def_models.DefInterface
    ) -> def_models.DefInterface:  # noqa: E501
        """Create the Defined entity interface.

        :param DefInterface interface: body of the interface
        :return: Interface that is just created
        :rtype: DefInterface
        """
        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.INTERFACES}",
            payload=asdict(interface))
        return def_models.DefInterface(**response_body)
    def update_interface(
        self, interface: def_models.DefInterface
    ) -> def_models.DefInterface:  # noqa: E501
        """Update the Defined entity interface.

        As of May 2020, only name of the interface can be updated.

        :param DefInterface interface: Interface to be updated.
        :return: Interface that is just updated.
        :rtype: DefInterface
        """
        response_body = self._cloudapi_client.do_request(
            method=RequestMethod.PUT,
            cloudapi_version=CLOUDAPI_VERSION_1_0_0,
            resource_url_relative_path=f"{CloudApiResource.INTERFACES}/"
            f"{interface.id}",
            payload=asdict(interface))
        return def_models.DefInterface(**response_body)
    def list_interfaces(self):
        """List defined entity interfaces.

        :return: Generator of interfaces
        :rtype: Generator
        """
        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.INTERFACES}?"
                f"page={page_num}")
            if len(response_body['values']) > 0:
                for interface in response_body['values']:
                    yield def_models.DefInterface(**interface)
            else:
                break