nuagenetworks / monolithe

generic and extendable code generator from specifications.
BSD 3-Clause "New" or "Revised" License
16 stars 28 forks source link

handle type list with subtype as any other spec #108

Closed killanch closed 5 years ago

killanch commented 5 years ago

For now some of the specs use 'entity' and 'object' as subtype for list data type. I have just logged such attributes.

Sample (see attribute vscs in generated code below):

import NUAttribute from 'service/NUAttribute';
import ServiceClassRegistry from 'service/ServiceClassRegistry';
import NUEntity from 'service/NUEntity';
import NUVRS from './NUVRS';
import NUVSC from './NUVSC';

/* Represents NSGatewayMonitor entity
   This API can be used to gather read-only information about an NSG, including information on its
   state, system metrics, alarm counts, location and version. It is a single view of the full data
   available for an NSG.
*/
export default class NUNSGatewayMonitor extends NUEntity {
    constructor(...args) {
        super(...args);
        this.defineProperties({
            vrsinfo: undefined,
            vscs: undefined,
            nsginfo: undefined,
            nsgstate: undefined,
            nsgsummary: undefined,
        });
    }

    static entityDescriptor = {
        description: `This API can be used to gather read-only information about an NSG, including information on its state, system metrics, alarm counts, location and version. It is a single view of the full data available for an NSG.`,
        userlabel: `NSG monitor`,
    }

    static attributeDescriptors = {
        ...NUEntity.attributeDescriptors,
        vrsinfo: new NUAttribute({
            localName: 'vrsinfo',
            attributeType: NUAttribute.ATTR_TYPE_OBJECT,
            description: `information about VRS reported from sysmon in JSON format. Has info about cpu usage, memory usage, physical interfaces etc.`,
            isUnique: true,
            isReadOnly: true,
            subType: NUVRS,
            userlabel: `VRS information`,
        }),
        vscs: new NUAttribute({
            localName: 'vscs',
            attributeType: NUAttribute.ATTR_TYPE_LIST,
            description: `List of controllers associated with the nsg`,
            isReadOnly: true,
            subType: NUVSC,
            userlabel: `Vscs`,
        }),
        nsginfo: new NUAttribute({
            localName: 'nsginfo',
            attributeType: NUAttribute.ATTR_TYPE_STRING,
            description: `An embedded object from the nsinfo entity from VSD. Contains info such as software version, CPU type, BIOS version etc. The embedded object is returned in JSON format`,
            isReadOnly: true,
            userlabel: `Nsginfo`,
        }),
        nsgstate: new NUAttribute({
            localName: 'nsgstate',
            attributeType: NUAttribute.ATTR_TYPE_STRING,
            description: `Information from the NSGState object in VSD in JSON format. Contains information about connection status, TPM status, operation mode etc.`,
            isReadOnly: true,
            userlabel: `Nsgstate`,
        }),
        nsgsummary: new NUAttribute({
            localName: 'nsgsummary',
            attributeType: NUAttribute.ATTR_TYPE_STRING,
            description: `NSG summary in JSON format - contains alarm counts, locality, bootstrap info etc.`,
            isReadOnly: true,
            userlabel: `Nsgsummary`,
        }),
    }

    static getClassName() {
        return 'NUNSGatewayMonitor';
    }

    static getAllowedJobCommands() {
        return [];
    }

    static supportsAlarms() {
        return false;
    }

    static getInstanceFromID(ID) {
        const instance = new NUNSGatewayMonitor();
        instance.ID = ID;
        return instance;
    }

    get RESTName() {
        return 'nsgatewaysmonitor';
    }

    get resourceName() {
        return 'nsgatewaysmonitors';
    }

    getClassName() {
        return NUNSGatewayMonitor.getClassName();
    }

    getAllowedJobCommands() {
        return NUNSGatewayMonitor.getAllowedJobCommands();
    }
}

ServiceClassRegistry.register(NUNSGatewayMonitor);