+# This script can be used to create the required folders for
+# a descriptor package and a template descriptor
+
+# Usage: generate_descriptor_pkg.sh <base-directory> <package-directory>
+
+# Descriptor names should be
+# - (nsd|vnfd).(yaml|yml|json|xml)
+# - *_(nsd|vnfd).(yaml|yml|json|xml)
+# - *_(nsd|vnfd)_*.(yaml|yml|json|xml)
+# - (nsd|vnfd)/*.(yaml|yml|json|xml)
+#
+
+SCRIPTNAME=`basename $0`
+
+# From https://osm.etsi.org/wikipub/index.php/Release_0_Data_Model_Details
+# Supported folders for VNFD
+# cloud_init - Rel 4.3, not yet part of OSM
+VNFD_FOLDERS=(images scripts icons charms cloud_init)
+
+# Supported folders for NSD
+# OSM document specifies (ns|vnf)-config folder, while Rel 4.3
+# is using (ns|vnf)_config.
+NSD_FOLDERS=(scripts icons ns_config vnf_config)
+
+# Other files allowed in the descriptor base directory
+ALLOWED_FILES=(README)
+
+DESC_TYPES=(vnfd nsd)
+DESC_EXTN=(yml yaml json xml)
+CHKSUM='checksums.txt'
+
+VERBOSE=false
+DRY_RUN=false
+CREATE=false
+RM="--remove-files"
+DEBUG=false
+
+function usage() {
+ cat <<EOF
+Usage:
+ $SCRIPTNAME [-t <type>] [-N] [-c] [base-directory] <package-dir>
+
+ -h|--help : show this message
+
+ -t|--package-type <nsd|vnfd> : Descriptor package type
+ is NSD or VNFD. Script will try to
+ determine the type if not provided.
+ Default is vnfd for create-folders.
+
+ -d|--destination-dir <destination directory>: Directory to create the
+ archived file.
+
+ -N|--no-remove-files : Do not remove the package files after creating
+ archive
+
+ -c|--create-folder : Create folder with the structure for the
+ package type using the base-dir and package-dir
+ and a descriptor template
+
+ -v| --verbose : Generate logs
+
+ -n| --dry-run : Validate the package dir
+
+ base-dir : Directory where the archive file or folders are created,
+ if destination directory is not specified.
+ Default is current directory
+
+ package-dir : The descriptor name and directory
+EOF
+}
+
+function write_vnfd_tmpl() {
+ name=$(basename $1)
+ desc_file="${name}_vnfd.yaml"
+
+ cat >$desc_file <<EOF
+# Only one VNFD per descriptor package is supported
+# Update the <update> tag with correct values
+# Update or remove <update, optional> tags
+vnfd:vnfd-catalog:
+ vnfd:
+ - id: ${name}
+ name: ${name}
+ short-name: ${name}
+ description: ${name}
+
+ # Place the logo as png in icons directory and provide the name here
+ logo: <update, optional>
+
+ # This is an optional section and can be removed
+ vnf-configuration:
+ config-attributes:
+ config-delay: '0'
+ config-priority: '1'
+
+ # Specify the config method
+ # Remove this section if the VNF does not use a config method
+ juju:
+ charm: <update>
+
+ # config-primitive specifies the config and actions for the VNF/charm
+ # This is an optional section
+ config-primitive:
+ # If there are no config to be set, remove this section
+ - name: config
+ # There can be multiple parameter sections
+ # The name and type should be same as VNF/charm specification
+ parameter:
+ - name: <update>
+ data-type: STRING
+ mandatory: <true|false>
+ default-value: <update>
+
+ # If there are no actions specified at VNF level, remove this section
+ # Multiple action sections can be specified
+ # The name should be the name of the action
+ - name: <update, optional>
+ # There can be multiple parameter sections
+ # The name and type should be same as charm specification
+ parameter:
+ - name: <update, optional>
+ data-type: STRING
+ mandatory: <true|false>
+
+ # Any config or action that need to be executed when VNF comes up
+ # This is an optional section
+ initial-config-primitive:
+ - name: config
+ # Any config to be set when VNF comes up
+ # For charm normally the VNF management IP need to be set
+ # in one of the config parameters
+ # Sepcifying the value a <rw_mgmt_ip> will cause the MANO
+ # to replace this with the management ip of VNF when it is
+ # instantiated
+ parameter:
+ - name: <update>
+ value: <rw_mgmt_ip>
+ seq: '1'
+
+ mgmt-interface:
+ # This should be id of one of the VDUs specified for this VNF
+ vdu-id: ${name}-VM
+ port: <update, optional>
+
+ connection-point:
+ # Specify the connection points from VDU
+ # Can specify multiple connection points here
+ - name: eth0
+ type: VPORT
+ - name: eth1
+ type: VPORT
+
+ # Atleast one VDU need to be specified
+ vdu:
+ - id: ${name}-VM
+ name: ${name}-VM
+ description: ${name}-VM
+
+ # Image including the full path
+ image: <update>
+
+ # Flavour of the VM to be instantiated for the VDU
+ vm-flavor:
+ memory-mb: '4096'
+ storage-gb: '10'
+ vcpu-count: '2'
+
+ external-interface:
+ # Specify the external interfaces
+ # There can be multiple interfaces defined
+ - name: eth0
+ virtual-interface:
+ bandwidth: '0'
+ type: VIRTIO
+ vpci: 0000:00:0a.0
+ vnfd-connection-point-ref: eth0
+ - name: eth1
+ virtual-interface:
+ bandwidth: '0'
+ type: OM-MGMT
+ vpci: 0000:00:0b.0
+ vnfd-connection-point-ref: eth1
+
+ # Mgmt vpci, match with the specification in the
+ # external interface for mgmt
+ mgmt-vpci: 0000:00:0a.0
+
+ # Specify EPA parameters
+ # This section is optional
+ guest-epa:
+ cpu-pinning-policy: DEDICATED
+ cpu-thread-pinning-policy: PREFER
+ mempage-size: LARGE
+ numa-node-policy:
+ mem-policy: STRICT
+ node:
+ - id: '0'
+ paired-threads:
+ num-paired-threads: '1'
+ node-cnt: '1'
+
+EOF
+
+ if [ $VERBOSE == true ]; then
+ echo "INFO: Created $desc_file"
+ fi
+}
+
+function write_nsd_tmpl() {
+ name=$(basename $1)
+ desc_file="${name}_nsd.yaml"
+
+ cat >$desc_file <<EOF
+# Only one NSD per descriptor package is supported
+# Update the <update> tag with correct values
+# Update or remove <update, optional> tags
+nsd:nsd-catalog:
+ nsd:
+ - id: ${name}
+ name: ${name}
+ short-name: ${name}
+ description: ${name}
+
+ # Place the logo as png in icons directory and provide the name here
+ logo: <update, optional>
+
+ # Specify the VNFDs that are part of this NSD
+ constituent-vnfd:
+ # The member-vnf-index needs to be unique, starting from 1
+ # vnfd-id-ref is the id of the VNFD
+ # Multiple constituent VNFDs can be specified
+ - member-vnf-index: <update>
+ vnfd-id-ref: <update>
+
+ vld:
+ # Management network for the VNFs
+ - id: management
+ name: management
+ provider-network:
+ overlay-type: VLAN
+ physical-network: <update>
+ type: ELAN
+ vnfd-connection-point-ref:
+ # Specify all the constituent VNFs
+ # member-vnf-index-ref - entry from constituent vnf
+ # vnfd-id-ref - VNFD id
+ # vnfd-connection-point-ref - connection point name in the VNFD
+ - member-vnf-index-ref: '1'
+ vnfd-connection-point-ref: <update>
+ vnfd-id-ref: <update>
+ - member-vnf-index-ref: '2'
+ vnfd-connection-point-ref: <update>
+ vnfd-id-ref: <update>
+
+ # Addtional netowrk can be specified for data, etc
+ - id: <update>
+ name: <update>
+ type: ELAN
+ provider-network:
+ overlay-type: VLAN
+ physical-network: <update>
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: <update>
+ vnfd-connection-point-ref: <update>
+ vnfd-id-ref: <update>
+
+ # NS level configuration primitive
+ # This section is optional
+ config-primitive:
+ - name: <update>
+ # List of parameters, optional
+ parameter:
+ - name: <update>
+ data-type: string
+ default-value: <update>
+ mandatory: <true|false>
+
+ # List of parameters grouped by name
+ # optional section
+ parameter-group:
+ - mandatory: <true|false>
+ name: <update>
+ parameter:
+ - name: <update>
+ data-type: integer
+ default-value: <update>
+ hidden: <true|false>
+ mandatory: <true|false>
+
+ # Script based NS level configuration
+ user-defined-script: <update>
+EOF
+
+ if [ $VERBOSE == true ]; then
+ echo "INFO: Created $desc_file"
+ fi
+}
+
+function write_nsd_config_tmpl() {
+ name=$(basename $1)
+ cfg_file="ns_config/$name.yaml"
+
+ cat >$cfg_file <<EOF
+
+EOF
+
+ if [ $VERBOSE == true ]; then
+ echo "INFO: Created $cfg_file"
+ fi
+}
+
+OPTS=`getopt -o vhnt:d:cN --long verbose,dry-run,help,package-type:,destination-dir,create-folder,no-remove-files,debug -n $SCRIPTNAME -- "$@"`