Skip to content

benoit-ferre/cd60.nce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cd60.nce – Huawei iMaster NCE‑Campus (Tenant view)

Language: English
Auth: token‑only (generated by nce_auth)
TLS: self‑signed allowed (validate_certs: false)
Default Base URI: https://weu.naas.huawei.com:18002


✨ What’s inside

  • Modules
    • nce_auth — obtain / revoke token (POST/DELETE /controller/v2/tokens)
    • nce_site — CRUD for Sites (single object, idempotent)
    • nce_device — CRUD for Devices (single object, idempotent)
  • Plugins
    • Lookup: nce_lookuplookup('sites'|'devices', '<identifier|name>')
    • Inventory: nce_inventory — builds inventory from devices; strict filename: nce.yml|nce.yaml
  • Conventions enforced
    • Inputs under object (MUST include name)
    • Uniqueness under selector (key→value without name)
    • Idempotent modules (detect create vs update automatically)

⚙️ Requirements

  • Ansible 2.14+ (recommended 2.15+)
  • Python 3.9+
  • Access to Huawei iMaster NCE‑Campus tenant view

📦 Installation

Option A — Use this ZIP as a source collection (no build)

  1. Unzip in your project so the path looks like:
    <project>/collections/ansible_collections/cd60/nce/
    
  2. Export the collections path when running Ansible:
    export ANSIBLE_COLLECTIONS_PATHS="$(pwd)"

Option B — Build a Galaxy artifact and install

Requires ansible-galaxy locally.

# From your project root that contains ./collections/ansible_collections/cd60/nce
ansible-galaxy collection build collections/ansible_collections/cd60/nce -f
# Produces cd60-nce-<version>.tar.gz
ansible-galaxy collection install cd60-nce-*.tar.gz --force

🚀 Quick start playbooks

1) Obtain a token (module: nce_auth)

---
- name: Get NCE token
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Obtain a token
      cd60.nce.nce_auth:
        base_uri: https://weu.naas.huawei.com:18002
        username: "{{ lookup('env', 'NCE_USERNAME') }}"
        password: "{{ lookup('env', 'NCE_PASSWORD') }}"
        validate_certs: false
      register: nce_auth

    - debug:
        var: nce_auth.token

2) Ensure a Site is present (module: nce_site)

---
- name: Ensure site present
  hosts: localhost
  gather_facts: false
  vars:
    nce_token: "{{ lookup('env', 'NCE_TOKEN') | default(none) }}"
  tasks:
    - name: Create or update site
      cd60.nce.nce_site:
        token: "{{ nce_token }}"
        base_uri: https://weu.naas.huawei.com:18002
        validate_certs: false
        selector:
          organizationName: "Nanjing Research Center"
          address: "66 JiangYun Road"
        object:
          name: "site1"
          type: ["AP"]
          description: "site1"
          latitude: "50"
          longitude: "111"
        state: present

3) Ensure a Device is present (module: nce_device)

---
- name: Ensure device present
  hosts: localhost
  gather_facts: false
  vars:
    nce_token: "{{ lookup('env', 'NCE_TOKEN') }}"
  tasks:
    - name: Create or update device
      cd60.nce.nce_device:
        token: "{{ nce_token }}"
        base_uri: https://weu.naas.huawei.com:18002
        validate_certs: false
        selector:
          esn: "210235AABBCC"
        object:
          name: "SW-Edge-01"
          esn: "210235AABBCC"
          ip: "10.10.10.10"
          siteId: "ea25fdbf-8dee-4823-bac2-5bfe8e3359ca"
        state: present

🔎 Lookup plugin examples (nce_lookup)

Récupérer un site par nom

- name: Lookup a site by name
  hosts: localhost
  gather_facts: false
  vars:
    nce_token: "{{ lookup('env', 'NCE_TOKEN') }}"
  tasks:
    - name: Fetch site object
      set_fact:
        site_obj: "{{ lookup('cd60.nce.nce_lookup', 'sites', 'site1', base_uri='https://weu.naas.huawei.com:18002', token=nce_token, validate_certs=False) | first }}"

    - debug:
        var: site_obj

Récupérer un device par id

- name: Lookup a device by UUID
  hosts: localhost
  gather_facts: false
  vars:
    nce_token: "{{ lookup('env', 'NCE_TOKEN') }}"
  tasks:
    - set_fact:
        dev_obj: "{{ lookup('cd60.nce.nce_lookup', 'devices', 'd3f9b5c2-xxxx-xxxx-xxxx-aaaaaaaaaaaa', base_uri='https://weu.naas.huawei.com:18002', token=nce_token, validate_certs=False) | first }}"

    - debug:
        var: dev_obj

📇 Inventory plugin examples (nce_inventory)

Fichier nce.yml

plugin: cd60.nce.nce_inventory
base_uri: https://weu.naas.huawei.com:18002
token: "{{ nce_token }}"
validate_certs: false
# Optional: filter on sites
# site_ids:
#   - "ea25fdbf-8dee-4823-bac2-5bfe8e3359ca"

Utilisation

# Lister l’inventaire
ansible-inventory -i nce.yml --list

# Exécuter un module (ex: debug) sur tous les hôtes découverts
ANSIBLE_HOST_KEY_CHECKING=False ansible -i nce.yml all -m debug -a 'var=nce_device.name'

Le plugin ajoute chaque device comme hôte avec ansible_host = nom du device et publie l’objet brut complet sous nce_device.


🧪 Lancer les tests d’intégration

This target validates create/update/rename/idempotency/delete for the site module.

Prerequisites

Provide the following environment variables before running ansible-test integration:

  • NCE_BASE_URI (e.g. https://weu.naas.huawei.com:18002)
  • NCE_USERNAME and NCE_PASSWORD (tenant credentials)
  • Optional: NCE_VALIDATE_CERTS (true/false)
  • Optional overrides for test data: NCE_TEST_SITE_OLD, NCE_TEST_SITE_NEW, NCE_TEST_SITE_CITY, NCE_TEST_SITE_TZ, NCE_TEST_SITE_ADDR, NCE_TEST_SITE_COUNTRY

Run

From the collection root (where galaxy.yml lives), run:

ansible-test integration cd60_nce_site -vv --color --python 3.11

You can also run all integration tests:

ansible-test integration --retry-on-error --color -vv

These tests use the collection's FQCN (cd60.nce.cd60_nce_site) and the auth/lookup plugins.

Lint et build

make lint   # ansible-lint (tolérant sur quelques règles)
make build  # construit l’artifact Galaxy .tar.gz

🧭 Conventions (rappel)

  • object: toutes les propriétés configurables d’un objet (MUST include name).
  • selector: mapping clé→valeur pour l’unicité (ne pas inclure name).
  • Idempotence: pas de paramètre d’opération (création vs mise à jour auto‑détectées).

❓ Support

Propose des issues/feedbacks dans votre dépôt GitOps interne, ou ouvrez un ticket au pôle Réseau & Automatisation.

Developer tools

To create a single-file text bundle (with the extractor script embedded):

make bundle

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published