Skip to content

Commit

Permalink
docs: update python examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aszs committed Sep 26, 2024
1 parent 1cb4a12 commit 3a9dedb
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 323 deletions.
94 changes: 6 additions & 88 deletions docs/configurators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,34 +329,8 @@ Example

.. tab-set-code::

.. code-block:: YAML
apiVersion: unfurl/v1alpha1
kind: Ensemble
spec:
service_template:
imports:
- repository: unfurl
file: tosca_plugins/artifacts.yaml
topology_template:
node_templates:
terraform-example:
type: unfurl.nodes.Installer.Terraform
interfaces:
defaults:
inputs:
tfvars:
tag: test
main: |
variable "tag" {
type = string
}
output "name" {
value = var.tag
}
.. literalinclude:: ./examples/configurators-6.yaml
:language: yaml

.. literalinclude:: ./examples/configurators-6.py
:language: python
Expand Down Expand Up @@ -504,32 +478,8 @@ Example

.. tab-set-code::

.. code-block:: YAML
apiVersion: unfurl/v1alpha1
kind: Ensemble
spec:
service_template:
imports:
- repository: unfurl
file: configurators/templates/docker.yaml
topology_template:
node_templates:
hello-world-container:
type: unfurl.nodes.Container.Application.Docker
requirements:
- host: compute
artifacts:
image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: busybox
interfaces:
Standard:
inputs:
configuration:
command: ["echo", "hello world"]
detach: no
output_logs: yes
.. literalinclude:: ./examples/configurators-7.yaml
:language: yaml

.. literalinclude:: ./examples/configurators-7.py
:language: python
Expand Down Expand Up @@ -577,40 +527,8 @@ Example

.. tab-set-code::

.. code-block:: YAML
apiVersion: unfurl/v1alpha1
kind: Ensemble
spec:
service_template:
imports:
- repository: unfurl
file: configurators/templates/dns.yaml
topology_template:
node_templates:
example_com_zone:
type: unfurl.nodes.DNSZone
properties:
name: example.com.
provider:
# Amazon Route53 (Note: this provider requires that the zone already exists.)
class: octodns.provider.route53.Route53Provider
test_app:
type: tosca.nodes.WebServer
requirements:
- host: compute
- dns:
node: example_com_zone
relationship:
type: unfurl.relationships.DNSRecords
properties:
records:
www:
type: A
value:
# get the ip address of the Compute instance that this is hosted on
eval: .source::.requirements::[.name=host]::.target::public_address
.. literalinclude:: ./examples/configurators-8.yaml
:language: yaml

.. literalinclude:: ./examples/configurators-8.py
:language: python
Expand Down
47 changes: 1 addition & 46 deletions docs/examples/configurators-5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unfurl
import tosca
from unfurl.tosca_plugins.artifacts import *
from unfurl.tosca_plugins.artifacts import artifact_AsdfTool

@tosca.operation(name="configure")
def terraform_example_configure(**kw):
Expand All @@ -18,48 +18,3 @@ def terraform_example_configure(**kw):
file="ripgrep",
)
terraform_example.configure = terraform_example_configure

configurator_artifacts = unfurl.nodes.LocalRepository(
"configurator-artifacts",
_directives=["default"],
)
configurator_artifacts.terraform = artifact_AsdfTool(
"terraform",
version="1.1.4",
file="terraform",
)
configurator_artifacts.gcloud = artifact_AsdfTool(
"gcloud",
version="398.0.0",
file="gcloud",
)
configurator_artifacts.kompose = artifact_AsdfTool(
"kompose",
version="1.26.1",
file="kompose",
)
configurator_artifacts.google_auth = artifact_PythonPackage(
"google-auth",
file="google-auth",
)
configurator_artifacts.octodns = artifact_PythonPackage(
"octodns",
version="==0.9.14",
file="octodns",
)
configurator_artifacts.kubernetes_core = artifact_AnsibleCollection(
"kubernetes.core",
version="2.4.0",
file="kubernetes.core",
)
configurator_artifacts.community_docker = artifact_AnsibleCollection(
"community.docker",
version="1.10.2",
file="community.docker",
)
configurator_artifacts.ansible_utils = artifact_AnsibleCollection(
"ansible.utils",
version="2.10.3",
file="ansible.utils",
)

68 changes: 21 additions & 47 deletions docs/examples/configurators-6.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,24 @@
import tosca
import unfurl
from unfurl.tosca_plugins.artifacts import *
from unfurl.tosca_plugins.artifacts import unfurl_nodes_Installer_Terraform
import unfurl.configurators.terraform

terraform_example = unfurl_nodes_Installer_Terraform(
"terraform-example",
)

configurator_artifacts = unfurl.nodes.LocalRepository(
"configurator-artifacts",
_directives=["default"],
)
configurator_artifacts.terraform = artifact_AsdfTool(
"terraform",
version="1.1.4",
file="terraform",
)
configurator_artifacts.gcloud = artifact_AsdfTool(
"gcloud",
version="398.0.0",
file="gcloud",
)
configurator_artifacts.kompose = artifact_AsdfTool(
"kompose",
version="1.26.1",
file="kompose",
)
configurator_artifacts.google_auth = artifact_PythonPackage(
"google-auth",
file="google-auth",
)
configurator_artifacts.octodns = artifact_PythonPackage(
"octodns",
version="==0.9.14",
file="octodns",
)
configurator_artifacts.kubernetes_core = artifact_AnsibleCollection(
"kubernetes.core",
version="2.4.0",
file="kubernetes.core",
)
configurator_artifacts.community_docker = artifact_AnsibleCollection(
"community.docker",
version="1.10.2",
file="community.docker",
)
configurator_artifacts.ansible_utils = artifact_AnsibleCollection(
"ansible.utils",
version="2.10.3",
file="ansible.utils",
)
@tosca.operation(
name="default", apply_to=["Install.check", "Standard.configure", "Standard.delete"]
)
def terraform_example_default(**kw):
return unfurl.configurators.terraform.TerraformConfigurator(
tfvars={"tag": "test"},
main="""
variable "tag" {
type = string
}
output "name" {
value = var.tag
}""",
)


terraform_example = unfurl_nodes_Installer_Terraform()
terraform_example.default = terraform_example_default
29 changes: 29 additions & 0 deletions docs/examples/configurators-6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: unfurl/v1alpha1
kind: Ensemble
spec:
service_template:
imports:
- repository: unfurl
file: tosca_plugins/artifacts.yaml
topology_template:
node_templates:

terraform-example:
type: unfurl.nodes.Installer.Terraform
interfaces:
defaults:
inputs:
tfvars:
tag: test
main: |
variable "tag" {
type = string
}
output "name" {
value = var.tag
}
Standard:
operations:
configure:

49 changes: 1 addition & 48 deletions docs/examples/configurators-7.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import unfurl
import tosca
from unfurl.configurators.templates.docker import (
unfurl_nodes_Container_Application_Docker,
)
from unfurl.tosca_plugins.artifacts import *
import tosca

hello_world_container = unfurl_nodes_Container_Application_Docker(
"hello-world-container",
Expand All @@ -12,48 +10,3 @@
file="busybox",
),
)
hello_world_container.host = tosca.find_node("compute")

configurator_artifacts = unfurl.nodes.LocalRepository(
"configurator-artifacts",
_directives=["default"],
)
configurator_artifacts.terraform = artifact_AsdfTool(
"terraform",
version="1.1.4",
file="terraform",
)
configurator_artifacts.gcloud = artifact_AsdfTool(
"gcloud",
version="398.0.0",
file="gcloud",
)
configurator_artifacts.kompose = artifact_AsdfTool(
"kompose",
version="1.26.1",
file="kompose",
)
configurator_artifacts.google_auth = artifact_PythonPackage(
"google-auth",
file="google-auth",
)
configurator_artifacts.octodns = artifact_PythonPackage(
"octodns",
version="==0.9.14",
file="octodns",
)
configurator_artifacts.kubernetes_core = artifact_AnsibleCollection(
"kubernetes.core",
version="2.4.0",
file="kubernetes.core",
)
configurator_artifacts.community_docker = artifact_AnsibleCollection(
"community.docker",
version="1.10.2",
file="community.docker",
)
configurator_artifacts.ansible_utils = artifact_AnsibleCollection(
"ansible.utils",
version="2.10.3",
file="ansible.utils",
)
22 changes: 22 additions & 0 deletions docs/examples/configurators-7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: unfurl/v1alpha1
kind: Ensemble
spec:
service_template:
imports:
- repository: unfurl
file: configurators/templates/docker.yaml
topology_template:
node_templates:
hello-world-container:
type: unfurl.nodes.Container.Application.Docker
artifacts:
image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: busybox
interfaces:
Standard:
inputs:
configuration:
command: ["echo", "hello world"]
detach: no
output_logs: yes
32 changes: 32 additions & 0 deletions docs/examples/configurators-8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: unfurl/v1alpha1
kind: Ensemble
spec:
service_template:
imports:
- repository: unfurl
file: configurators/templates/dns.yaml
topology_template:
node_templates:
example_com_zone:
type: unfurl.nodes.DNSZone
properties:
name: example.com.
provider:
# Amazon Route53 (Note: this provider requires that the zone already exists.)
class: octodns.provider.route53.Route53Provider

test_app:
type: tosca.nodes.WebServer
requirements:
- host: compute
- dns:
node: example_com_zone
relationship:
type: unfurl.relationships.DNSRecords
properties:
records:
www:
type: A
value:
# get the ip address of the Compute instance that this is hosted on
eval: .source::.requirements::[.name=host]::.target::public_address
Loading

0 comments on commit 3a9dedb

Please sign in to comment.