Skip to content

Commit

Permalink
[Feat.] New FunctionGraph Function resource (#506)
Browse files Browse the repository at this point in the history
[Feat.] New FunctionGraph Function resource

Implementation of Function lifecycle endpoints into sdk (https://docs.otc.t-systems.com/function-graph/api-ref/apis/function_lifecycle_management/index.html)
Part of #438

Reviewed-by: RusselSand
  • Loading branch information
anton-sidelnikov authored Jan 23, 2025
1 parent 7061969 commit 6be3050
Show file tree
Hide file tree
Showing 26 changed files with 1,157 additions and 1 deletion.
107 changes: 107 additions & 0 deletions doc/source/sdk/guides/function_graph.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
FunctionGraph Service (FGS)
===========================

.. contents:: Table of Contents
:local:

FunctionGraph hosts and computes event-driven functions in a serverless
context while ensuring high availability, high scalability,
and zero maintenance. All you need to do is write your code and set conditions.

Function
--------

Function is a combination of code, runtime, resources,
and settings required to achieve a specific purpose.
It is the minimum unit that can run independently.
A function can be triggered by triggers and automatically schedule
required resources and environments to achieve expected results.


Create Function
^^^^^^^^^^^^^^^

This API is used to create a function.

.. literalinclude:: ../examples/function_graph/create_function.py
:lines: 16-32

Delete Function
^^^^^^^^^^^^^^^

This API is used to delete a function.

.. literalinclude:: ../examples/function_graph/delete_function.py
:lines: 16-33

List Functions
^^^^^^^^^^^^^^

This API is used to query all functions.

.. literalinclude:: ../examples/function_graph/list_functions.py
:lines: 16-24

Get Function Code
^^^^^^^^^^^^^^^^^

This API is used to query the code of a function.

.. literalinclude:: ../examples/function_graph/get_function_code.py
:lines: 16-23

Get Function Metadata
^^^^^^^^^^^^^^^^^^^^^

This API is used to query the metadata of a function.

.. literalinclude:: ../examples/function_graph/get_function_metadata.py
:lines: 16-23

Get Resource Tags
^^^^^^^^^^^^^^^^^

This API is used to query resource tags.

.. literalinclude:: ../examples/function_graph/get_resource_tags.py
:lines: 16-23

Create Resource Tags
^^^^^^^^^^^^^^^^^^^^

This API is used to create resource tags.

.. literalinclude:: ../examples/function_graph/create_resource_tags.py
:lines: 16-36

Delete Resource Tags
^^^^^^^^^^^^^^^^^^^^

This API is used to delete resource tags.

.. literalinclude:: ../examples/function_graph/delete_resource_tags.py
:lines: 16-31

Update Function Code
^^^^^^^^^^^^^^^^^^^^

This API is used to modify the code of a function.

.. literalinclude:: ../examples/function_graph/update_function_code.py
:lines: 16-37

Update Function Metadata
^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to modify the metadata of a function.

.. literalinclude:: ../examples/function_graph/update_function_metadata.py
:lines: 16-35

Update Function Instances
^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to update the maximum number of instances of a function.

.. literalinclude:: ../examples/function_graph/update_function_metadata.py
:lines: 16-23
1 change: 1 addition & 0 deletions doc/source/sdk/guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Open Telekom Cloud related User Guides
dms
dns
dws
function_graph
kms
lts
mrs
Expand Down
23 changes: 23 additions & 0 deletions doc/source/sdk/proxies/function_graph.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FunctionGraph API
=================

.. automodule:: otcextensions.sdk.function_graph.v2._proxy

Function Service Class
----------------------

The nat high-level interface is available through the ``functiongraph``
member of a :class:`~openstack.connection.Connection` object. The
``functiongraph`` member will only be added if the
``otcextensions.sdk.register_otc_extensions(conn)`` method is called.

Function Operations
^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.function_graph.v2._proxy.Proxy
:noindex:
:members: create_function, delete_function, functions,
get_function_code, get_function_metadata, get_resource_tags,
create_resource_tags, delete_resource_tags, update_pin_status,
update_function_code, update_function_metadata, update_max_instances

1 change: 1 addition & 0 deletions doc/source/sdk/proxies/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Service Proxies
Distributed Message Service (DMS) <dms>
Document Database Service (DDS) <dds_v3>
Domain Name Server Service (DNS) <dns>
FunctionGraph Service (FGS) <function_graph>
Identity Service (IAM) <identity_v3>
Key Management Service (KMS) <kms>
Log Tank Service (LTS) <lts>
Expand Down
7 changes: 7 additions & 0 deletions doc/source/sdk/resources/function_graph/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FunctionGraph Resources
=======================

.. toctree::
:maxdepth: 1

v2/function
13 changes: 13 additions & 0 deletions doc/source/sdk/resources/function_graph/v2/function.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.function_graph.v2.function
============================================

.. automodule:: otcextensions.sdk.function_graph.v2.function

The Function Class
------------------

The ``Function`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.function_graph.v2.function.Function
:members:
1 change: 1 addition & 0 deletions doc/source/sdk/resources/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Open Telekom Cloud Resources
Distributed Message Service (DMS) <dms/index>
Document Database Service (DDS) <dds/index>
Domain Name Service (DNS) <dns/index>
FunctionGraph Service (FGS) <function_graph/index>
Identity Service (IAM) <identity/index>
Key Management Service (KMS) <kms/index>
Log Tank Service (LTS) <lts/index>
Expand Down
32 changes: 32 additions & 0 deletions examples/function_graph/create_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
# 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.
"""
Create new function
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

attrs = {
'func_name': 'test-function',
'package': 'default',
'runtime': 'Python3.9',
'handler': 'index.handler',
'timeout': 30,
'memory_size': 128,
'code_type': 'inline',
}
fg = conn.functiongraph.create_function(**attrs)
36 changes: 36 additions & 0 deletions examples/function_graph/create_resource_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# 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.
"""
Create resource tags
"""

import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

conn.functiongraph.create_resource_tags(
'func_urn',
tags=[
{
'key': 'key',
'value': 'value'
},
{
'key': 'testKey2',
'value': 'testValue2'
}
]
)
33 changes: 33 additions & 0 deletions examples/function_graph/delete_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# 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.
"""
Delete function
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

attrs = {
'func_name': 'test-function',
'package': 'default',
'runtime': 'Python3.9',
'handler': 'index.handler',
'timeout': 30,
'memory_size': 128,
'code_type': 'inline',
}
fg = conn.functiongraph.create_function(**attrs)
conn.functiongraph.delete_function(fg)
31 changes: 31 additions & 0 deletions examples/function_graph/delete_resource_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
# 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.
"""
Delete resource tags
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

conn.functiongraph.delete_resource_tags(
'func_urn',
tags=[
{
'key': 'testKey2',
'value': 'testValue2'
}
]
)
23 changes: 23 additions & 0 deletions examples/function_graph/get_function_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# 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.
"""
Get function code
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

code = conn.functiongraph.get_function_code(function='func_urn')
23 changes: 23 additions & 0 deletions examples/function_graph/get_function_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# 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.
"""
Get function metadata
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

meta = conn.functiongraph.get_function_metadata(function='func_urn')
23 changes: 23 additions & 0 deletions examples/function_graph/get_resource_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# 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.
"""
Get resource tags
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

ft = conn.functiongraph.get_resource_tags(function='func_urn')
Loading

0 comments on commit 6be3050

Please sign in to comment.