BgpNeighbornetclab/netclab-xp@v0.2.13
TypeComposition
Referenced XRDBgpNeighbor
YAML
Composition
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: bgpneighbors.eos.netclab.dev
  creationTimestamp: null
spec:
  compositeTypeRef:
    apiVersion: eos.netclab.dev/v1alpha1
    kind: BgpNeighbor
  mode: Pipeline
  pipeline:
    - step: environmentConfigs
      functionRef:
        name: crossplane-contrib-function-environment-configs
      input:
        apiVersion: environmentconfigs.fn.crossplane.io/v1beta1
        kind: Input
        spec:
          environmentConfigs:
            - ref:
                name: endpoint-protocols
              type: Reference
    - step: requests
      functionRef:
        name: crossplane-contrib-function-go-templating
      input:
        apiVersion: gotemplating.fn.crossplane.io/v1beta1
        inline:
          template: >
            {{- $deviceUrl := "" }}

            {{- $basicAuth := "" }}

            {{- $address := .observed.composite.resource.spec.endpoint }}

            {{- with index .context "apiextensions.crossplane.io/environment" }}
              {{- $deviceUrl = printf "%s://%s:%d" .restconf.scheme $address .restconf.port }}
            {{- end }}

            {{- $basicAuth := ( getCredentialData . "eos-creds" ).basicAuth |
            toString | b64enc }}

            ---

            apiVersion: http.crossplane.io/v1alpha2

            kind: Request

            metadata:
              annotations:
                gotemplating.fn.crossplane.io/composition-resource-name: {{ .observed.composite.resource.metadata.name }}
            spec:
              forProvider:
                insecureSkipTLSVerify: true
                headers:
                  Accept: ["application/yang-data+json"]
                  Authorization: ["Basic {{ $basicAuth }}"]
                payload:
                  baseUrl: "{{ $deviceUrl }}/restconf/data/openconfig-network-instance:network-instances/network-instance=default/protocols/protocol=BGP,BGP/bgp/neighbors/neighbor={{ .observed.composite.resource.spec.neighborIp }}/config"
                  body: |
                    { "openconfig-network-instance:peer-as": {{ .observed.composite.resource.spec.neighborAsn }} }

                mappings:
                - action: CREATE
                  method: PATCH
                  body: .payload.body
                  url: .payload.baseUrl

                - action: UPDATE
                  method: PATCH
                  body: .payload.body
                  url: .payload.baseUrl

                - action: OBSERVE
                  url: .payload.baseUrl

                - action: REMOVE
                  method: DELETE
                  url: .payload.baseUrl
        kind: GoTemplate
        source: Inline
      credentials:
        - name: eos-creds
          source: Secret
          secretRef:
            name: eos-creds
            namespace: crossplane-system
    - step: auto-ready
      functionRef:
        name: crossplane-contrib-function-auto-ready