Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat.] FunctionGraph Aliases and versions #513

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions doc/source/sdk/guides/function_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,59 @@ This API is used to update a test event.

.. literalinclude:: ../examples/function_graph/update_event.py
:lines: 16-45

Publishing a Function Version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to publish a function version.

.. literalinclude:: ../examples/function_graph/publish_version.py
:lines: 16-41

Querying the Versions of a Function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

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

Querying All Aliases of a Function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to query the versions and aliases of a function.

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

Creating an Alias for a Function Version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to create an alias for a function version.

.. literalinclude:: ../examples/function_graph/create_alias.py
:lines: 16-40

Deleting an Alias of a Function Version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to delete an alias of a function version.

.. literalinclude:: ../examples/function_graph/delete_alias.py
:lines: 16-40

Modifying the Alias of a Function Version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to modify the alias of a function version.

.. literalinclude:: ../examples/function_graph/update_alias.py
:lines: 16-47

Querying the Alias of a Function Version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to query the alias of a function version.

.. literalinclude:: ../examples/function_graph/get_alias.py
:lines: 16-42
15 changes: 15 additions & 0 deletions doc/source/sdk/proxies/function_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ Events
:noindex:
:members: create_event, delete_event, events,
get_event, update_event

Versions
^^^^^^^^

.. autoclass:: otcextensions.sdk.function_graph.v2._proxy.Proxy
:noindex:
:members: versions, publish_version

Aliases
^^^^^^^

.. autoclass:: otcextensions.sdk.function_graph.v2._proxy.Proxy
:noindex:
:members: aliases, create_alias, delete_alias,
update_alias, get_alias
2 changes: 2 additions & 0 deletions doc/source/sdk/resources/function_graph/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ FunctionGraph Resources
v2/quota
v2/dependency
v2/event
v2/alias
v2/version
13 changes: 13 additions & 0 deletions doc/source/sdk/resources/function_graph/v2/alias.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.function_graph.v2.alias
=========================================

.. automodule:: otcextensions.sdk.function_graph.v2.alias

The Alias Class
---------------

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

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

.. automodule:: otcextensions.sdk.function_graph.v2.version

The Version Class
-----------------

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

.. autoclass:: otcextensions.sdk.function_graph.v2.version.Version
:members:
40 changes: 40 additions & 0 deletions examples/function_graph/create_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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 alias
"""
import openstack
from otcextensions import sdk

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

func_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(**func_attrs)

alias_attrs = {
'name': 'a1',
'version': 'new-version'
}
alias = conn.functiongraph.create_alias(
fg.func_urn, **alias_attrs
)
40 changes: 40 additions & 0 deletions examples/function_graph/delete_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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 alias
"""
import openstack
from otcextensions import sdk

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

func_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(**func_attrs)
alias_attrs = {
'name': 'a1',
'version': 'new-version'
}
al = conn.functiongraph.create_alias(
fg.func_urn, **alias_attrs
)
conn.functiongraph.delete_aliasw(fg, al)
42 changes: 42 additions & 0 deletions examples/function_graph/get_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/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 alias
"""
import openstack
from otcextensions import sdk

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

alias_attrs = {
'name': 'a1',
'version': 'new-version'
}
func_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(**func_attrs)
al = conn.functiongraph.create_alias(
fg, **alias_attrs
)
a = conn.functiongraph.get_alias(
fg, al)
print(a)
24 changes: 24 additions & 0 deletions examples/function_graph/list_aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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 all aliases
"""
import openstack
from otcextensions import sdk

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

for a in conn.functiongraph.aliases(func_urn='urn'):
print(a)
24 changes: 24 additions & 0 deletions examples/function_graph/list_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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 all versions
"""
import openstack
from otcextensions import sdk

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

for v in conn.functiongraph.versions(func_urn='urn'):
print(v)
41 changes: 41 additions & 0 deletions examples/function_graph/publish_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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.
"""
Publish new version
"""
import openstack
from otcextensions import sdk

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

func_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(**func_attrs)

publish_attrs = {
'version': 'new-version',
'description': 'otce',
}

publish = conn.functiongraph.publish_version(
fg, **publish_attrs
)
47 changes: 47 additions & 0 deletions examples/function_graph/update_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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.
"""
Update alias
"""
import openstack
from otcextensions import sdk

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

func_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(**func_attrs)

alias_attrs = {
'name': 'a1',
'version': 'new-version'
}
alias = conn.functiongraph.create_alias(
fg.func_urn, **alias_attrs
)

new_attrs = {
'version': 'new-version',
'description': 'new',
}
updated = conn.functiongraph.update_alias(
fg, alias, **new_attrs)
Loading