Current section

Files

Jump to
diffo_example lib nbn resources nni_group.ex
Raw

lib/nbn/resources/nni_group.ex

# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
#
# SPDX-License-Identifier: MIT
defmodule DiffoExample.Nbn.NniGroup do
@moduledoc """
Diffo - TMF Service and Resource Management with a difference
NniGroup - NNI Group Resource Instance
An NNI Group is the Point of Interconnect (PoI) grouping where a CVC
terminates. It comprises multiple NNI resources.
The NNI Group assigns svlan to CVC.
"""
alias Diffo.Provider.BaseInstance
alias Diffo.Provider.Resource
alias Diffo.Provider.Assignment
alias DiffoExample.Nbn
use Ash.Resource,
fragments: [BaseInstance, Resource],
domain: Nbn,
authorizers: [Ash.Policy.Authorizer]
resource do
description "An Ash Resource representing an NNI Group"
plural_name :NniGroups
end
provider do
specification do
id "e5f6a7b8-9c0d-4e1f-8a2b-4c5d6e7f8a9b"
name "nniGroup"
type :resourceSpecification
description "An NNI Group Resource Instance comprising multiple NNI resources"
category "Network Resource"
end
characteristics do
characteristic :nni_group, DiffoExample.Nbn.NniGroupCharacteristic
characteristic :metrics, DiffoExample.Nbn.NniGroupMetrics
# Every NNI this group comprises — forward :contains relationship (the
# group is the source of the edge → forward_relationships).
inherited_characteristic :nnis, via: [{:forward, relationship: :contains}], read: :nni
end
pools do
pool :svlans, :svlan
end
relationships do
source :all
target :all
end
behaviour do
actions do
create :build
end
end
end
actions do
create :build do
description "creates a new NNI Group resource instance"
accept [:id, :name, :which]
argument :relationships, {:array, :struct}
argument :places, {:array, :struct}
argument :parties, {:array, :struct}
change set_attribute(:type, :resource)
change DiffoExample.Nbn.Changes.SetRspId
change load [:href]
upsert? false
end
update :define do
description "defines the NNI Group"
argument :characteristic_value_updates, {:array, :term}
change set_attribute(:lifecycle_state, :installed)
change Diffo.Provider.Changes.Define
end
update :assign_svlan do
description "assigns an S-VLAN ID from the NNI Group pool to a CVC"
argument :assignment, :struct, constraints: [instance_of: Assignment]
change {Diffo.Provider.Changes.Assign, pool: :svlans}
end
update :relate do
description "relates the NNI Group with other instances (e.g. NNI resources it comprises)"
argument :relationships, {:array, :struct}
change Diffo.Provider.Changes.Relate
end
end
attributes do
attribute :rsp_id, :string do
description "the owning RSP's id — nil for Perentie-managed infrastructure"
allow_nil? true
public? true
end
end
calculations do
end
use DiffoExample.Nbn.RspOwnership
end