Merge "switch from CLI to REST for consistency and because the CLI hates question...
[osm/devops.git] / descriptor-packages / tools / generate_descriptor_pkg.sh
1 #!/bin/bash
2
3 ############################################################################
4 # Copyright 2016 RIFT.io Inc #
5 # #
6 # Licensed under the Apache License, Version 2.0 (the "License"); #
7 # you may not use this file except in compliance with the License. #
8 # You may obtain a copy of the License at #
9 # #
10 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # #
12 # Unless required by applicable law or agreed to in writing, software #
13 # distributed under the License is distributed on an "AS IS" BASIS, #
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15 # See the License for the specific language governing permissions and #
16 # limitations under the License. #
17 ############################################################################
18
19 #
20 # This shell script is used to create a descriptor package
21 # The main functions of this script include:
22 # - Generate checksums.txt file
23 # - Generate a tar.gz file
24 # This script can be used to create the required folders for
25 # a descriptor package and a template descriptor
26
27 # Usage: generate_descriptor_pkg.sh <base-directory> <package-directory>
28
29 # Descriptor names should be
30 # - (nsd|vnfd).(yaml|yml|json|xml)
31 # - *_(nsd|vnfd).(yaml|yml|json|xml)
32 # - *_(nsd|vnfd)_*.(yaml|yml|json|xml)
33 # - (nsd|vnfd)/*.(yaml|yml|json|xml)
34 #
35
36 SCRIPTNAME=`basename $0`
37
38 # From https://osm.etsi.org/wikipub/index.php/Release_0_Data_Model_Details
39 # Supported folders for VNFD
40 # cloud_init - Rel 4.3, not yet part of OSM
41 VNFD_FOLDERS=(images scripts icons charms cloud_init)
42
43 # Supported folders for NSD
44 # OSM document specifies (ns|vnf)-config folder, while Rel 4.3
45 # is using (ns|vnf)_config.
46 NSD_FOLDERS=(scripts icons ns_config vnf_config)
47
48 # Other files allowed in the descriptor base directory
49 ALLOWED_FILES=(README)
50
51 DESC_TYPES=(vnfd nsd)
52 DESC_EXTN=(yml yaml json xml)
53 CHKSUM='checksums.txt'
54
55 VERBOSE=false
56 DRY_RUN=false
57 CREATE=false
58 RM="--remove-files"
59 DEBUG=false
60
61 ARCHIVE=false
62 CREATE_NSD=false
63 VENDOR='OSM'
64 INTF_TYPE='VIRTIO'
65 VCPU=2
66 MEMORY=4096
67 STORAGE=10
68 INTERFACES=1
69
70 function usage() {
71 cat <<EOF
72 Usage:
73 $SCRIPTNAME [-t <type>] [-N] [-c] [base-directory] <package-name>
74
75 -h|--help : show this message
76
77 -t|--package-type <nsd|vnfd> : Descriptor package type
78 is NSD or VNFD. Script will try to
79 determine the type if not provided.
80 Default is vnfd for create-folders.
81
82 -d|--destination-dir <destination directory>: Directory to create the
83 archived file.
84 Default is base-directory
85
86 -N|--no-remove-files : Do not remove the package files after creating
87 archive
88
89 Options specifc for create descriptor:
90
91 -c|--create-folder : Create folder with the structure for the
92 package type using the base-dir and package-dir
93 and a descriptor template
94
95 -a|--archive: Create package for the descriptor
96
97 --nsd : Generate NSD descriptor package also.
98
99 --vendor : Vendor name for descriptor. Default OSM
100
101 --interface-type : Interface type [VIRTIO|SR-IOV|PCI-PASSTHROUGH|E1000]
102 Default VIRTIO
103
104 VM Flavour options:
105
106 --vcpu : Virtual CPU count. Default 2
107
108 --memory : Memory for VM in MB. Default 4096MB
109
110 --storage : Storage size for VM in GB. Default 10GB
111
112 VDU Parameters:
113
114 --image : Location URI of the image
115
116 --cloud-init-file : Cloud init file
117
118 --cloud-init : Cloud init script. Will be ignored if
119 cloud-init-file is specified
120
121 --interfaces : Number of external interfaces in additon to OM-MGMT. Default 1.
122
123 End of create descriptor specific options
124
125 -v| --verbose : Generate progress details
126
127 -n| --dry-run : Validate the package dir
128
129 base-dir : Directory where the archive file or folders are created,
130 if destination directory is not specified.
131 Default is current directory
132
133 package-name : The descriptor name (full path if base-dir not specified)
134 EOF
135 }
136
137 CP_TYPE='VPORT'
138 function get_cp_type() {
139 case ${INTF_TYPE} in
140 VIRTIO ) CP_TYPE='VPORT';;
141 SR-IOV ) CP_TYPE='VPORT';;
142 PCI-PASSTHROUGH ) CP_TYPE='VPORT';;
143 OM-MGMT ) CP_TYPE='VPORT';;
144 E1000 ) CP_TYPE='VPORT';;
145 * ) echo "ERROR: Unknown interface type ${INTF_TYPE}"; exit 1;;
146 esac
147 }
148
149 # Get pci number starting from 0x0a
150 get_pci() {
151 printf '%02x' $((10 + $1)) | tr '[:upper:]' '[:lower:]'
152 }
153
154 function write_readme() {
155 dir=$1
156 file=${dir}/README
157 date=$(date)
158
159 cat >$file <<EOF
160 Descriptor created by OSM descriptor package generated
161 Created on $date
162 EOF
163
164 }
165
166 function write_vnfd_tmpl() {
167 name=$(basename $1)
168 desc_file="${name}.yaml"
169
170 cat >$desc_file <<EOF
171 vnfd:vnfd-catalog:
172 vnfd:
173 - id: ${name}
174 name: ${name}
175 short-name: ${name}
176 description: Generated by OSM pacakage generator
177 vendor: ${VENDOR}
178 version: '1.0'
179
180 # Place the logo as png in icons directory and provide the name here
181 # logo: <update, optional>
182
183 # Management interface
184 mgmt-interface:
185 vdu-id: ${name}-VM
186
187 # Atleast one VDU need to be specified
188 vdu:
189 # Additional VDUs can be created by copying the
190 # VDU descriptor below
191 - id: ${name}-VM
192 name: ${name}-VM
193 description: ${name}-VM
194 count: 1
195
196 # Flavour of the VM to be instantiated for the VDU
197 vm-flavor:
198 vcpu-count: ${VCPU}
199 memory-mb: ${MEMORY}
200 storage-gb: ${STORAGE}
201
202 # Image including the full path
203 image: '${IMAGE}'
204
205 EOF
206
207 # Add the cloud init file or script
208 if [[ -n ${CLOUD_INIT_FILE} ]]; then
209 cif=$(basename ${CLOUD_INIT_FILE})
210 cat >>$desc_file <<EOF
211 # Cloud init file
212 cloud-init-file: '${cif}'
213 EOF
214 elif [[ -n ${CLOUD_INIT} ]]; then
215 cat >>$desc_file <<EOF
216 # Cloud init to use
217 cloud-init: '${CLOUD_INIT}'
218 EOF
219 fi
220
221 # Add external interfaces
222 cat >>$desc_file <<EOF
223 interface:
224 # Specify the external interfaces
225 # There can be multiple interfaces defined
226 EOF
227
228 # Add mgmt interface
229 cat >>$desc_file <<EOF
230 - name: eth0
231 type: EXTERNAL
232 virtual-interface:
233 type: VIRTIO
234 bandwidth: '0'
235 vpci: '0000:00:0a.0'
236 external-connection-point-ref: eth0
237 EOF
238
239 # Add external interfaces
240 for i in `seq 1 ${INTERFACES}`; do
241 eth=$(($i))
242 pci=$(get_pci $eth)
243 cat >>$desc_file <<EOF
244 - name: eth${eth}
245 type: EXTERNAL
246 virtual-interface:
247 type: ${INTF_TYPE}
248 bandwidth: '0'
249 vpci: '0000:00:${pci}.0'
250 external-connection-point-ref: eth${eth}
251 EOF
252 done
253
254 # Add connection points
255 cat >>$desc_file <<EOF
256
257 connection-point:
258 EOF
259
260 for i in `seq 0 ${INTERFACES}`; do
261 eth=$(($i))
262 cat >>$desc_file <<EOF
263 - name: eth${eth}
264 type: ${CP_TYPE}
265 EOF
266 done
267
268 cat >>$desc_file <<EOF
269
270 # Uncomment and update below to enable juju
271 # charm configuration for the VNF
272 # vnf-configuration:
273 # juju:
274 # charm: <charm name>
275 # service-primitive:
276 # - name: config
277 # parameter:
278 # - name: <config parameter>
279 # data-type: [STRING|INTEGER]
280 # mandatory: [true|false]
281 # default-value: <value>
282 # - name: <action name>
283 # parameter:
284 # - name: <action parameter>
285 # data-type: [STRING|INTEGER]
286 # mandatory: [true|false]
287 # default-value: <value>
288 # initial-config-primitive:
289 # - name: config
290 # parameter:
291 # - name: <config name>
292 # value: <value>
293 # - name: <action name>
294 # parameter:
295 # - name: <action parameter>
296 # value: <value>
297 EOF
298
299 if [ $VERBOSE == true ]; then
300 echo "INFO: Created $desc_file"
301 fi
302 }
303
304 function write_nsd_tmpl() {
305 name=$(basename $1)
306 vnfd=$2
307 desc_file="${name}.yaml"
308
309 cat >$desc_file <<EOF
310 nsd:nsd-catalog:
311 nsd:
312 - id: ${name}
313 name: ${name}
314 short-name: ${name}
315 description: Generated by OSM pacakage generator
316 vendor: ${VENDOR}
317 version: '1.0'
318
319 # Place the logo as png in icons directory and provide the name here
320 # logo: <update, optional>
321
322 # Specify the VNFDs that are part of this NSD
323 constituent-vnfd:
324 # The member-vnf-index needs to be unique, starting from 1
325 # vnfd-id-ref is the id of the VNFD
326 # Multiple constituent VNFDs can be specified
327 - member-vnf-index: 1
328 vnfd-id-ref: ${vnfd}
329
330 EOF
331
332 cat >>$desc_file <<EOF
333 vld:
334 # Networks for the VNFs
335 EOF
336
337 # Add management VLD
338 cat >>$desc_file <<EOF
339 - id: ${name}_vld0
340 name: management
341 short-name: management
342 type: ELAN
343 mgmt-network: 'true'
344 # vim-network-name: <update>
345 # provider-network:
346 # overlay-type: VLAN
347 # segmentation_id: <update>
348 vnfd-connection-point-ref:
349 # Specify the constituent VNFs
350 # member-vnf-index-ref - entry from constituent vnf
351 # vnfd-id-ref - VNFD id
352 # vnfd-connection-point-ref - connection point name in the VNFD
353 - nsd:member-vnf-index-ref: 1
354 nsd:vnfd-id-ref: ${vnfd}
355 # NOTE: Validate the entry below
356 nsd:vnfd-connection-point-ref: eth0
357 EOF
358
359 # Add rest of VLDs
360 for i in `seq 1 ${INTERFACES}`; do
361 eth=$(($i))
362 cat >>$desc_file <<EOF
363 - id: ${name}_vld${i}
364 name: ${name}_vld${i}
365 short-name: ${name}_vld${i}
366 type: ELAN
367 # vim-network-name: <update>
368 # provider-network:
369 # overlay-type: VLAN
370 # segmentation_id: <update>
371 vnfd-connection-point-ref:
372 # Specify the constituent VNFs
373 # member-vnf-index-ref - entry from constituent vnf
374 # vnfd-id-ref - VNFD id
375 # vnfd-connection-point-ref - connection point name in the VNFD
376 - nsd:member-vnf-index-ref: 1
377 nsd:vnfd-id-ref: ${vnfd}
378 # NOTE: Validate the entry below
379 nsd:vnfd-connection-point-ref: eth${eth}
380 EOF
381 done
382
383 if [ $VERBOSE == true ]; then
384 echo "INFO: Created $desc_file"
385 fi
386 }
387
388 function write_nsd_config_tmpl() {
389 name=$(basename $1)
390 cfg_file="ns_config/$name.yaml"
391
392 cat >$cfg_file <<EOF
393
394 EOF
395
396 if [ $VERBOSE == true ]; then
397 echo "INFO: Created $cfg_file"
398 fi
399 }
400
401 cur_dir=`pwd`
402
403 # Check if the array contains a specific value
404 # Taken from
405 # http://stackoverflow.com/questions/3685970/check-if-an-array-contains-a-value
406 function contains() {
407 local n=$#
408 local value=${!n}
409 for ((i=1;i < $#;i++)); do
410 if [ "${!i}" == "${value}" ]; then
411 echo "y"
412 return 0
413 fi
414 done
415 echo "n"
416 return 1
417 }
418
419 function check_type() {
420 type=$1
421 if [ $(contains "${DESC_TYPES[@]}" $type) == "y" ]; then
422 TYPE=$type
423 else
424 echo "ERROR: Unknown descriptor type $type!" >&2
425 exit 1
426 fi
427 }
428
429 function get_expr(){
430 # First argument is to specify if this is a negative match or not
431 # Rest are filename expressions without extension
432
433 local regex=" "
434 local n=$#
435 local neg="${1}"
436 local first="true"
437 for ((i=2;i <= $#;i++)); do
438 for extn in "${DESC_EXTN[@]}"; do
439 if [ $first == true ]; then
440 if [ $neg == true ]; then
441 subexpr='! -name'
442 else
443 subexpr='-name'
444 fi
445 first=false
446 else
447 if [ $neg == true ]; then
448 subexpr=' -a ! -name'
449 else
450 subexpr=' -o -name'
451 fi
452 fi
453
454 regex="$regex $subexpr ${!i}.$extn"
455 done
456 done
457
458 echo "$regex"
459 }
460
461 function generate_package(){
462 type=$1
463 name="${2}_${type}"
464 vnfd="${2}_vnfd" # Required for NSD
465 dest_dir=$3
466
467 dir="${dest_dir}/${name}"
468
469 # Create the folders for the descriptor
470 if [ $VERBOSE == true ]; then
471 echo "INFO: Creating folders for $PKG in $dest_dir"
472 fi
473
474 # Remove any existing directory
475 if [ -d $dir ]; then
476 rm -rf $dir >/dev/null 2>&1
477 fi
478
479 mkdir -p $dir && cd $dir
480 if [ $? -ne 0 ]; then
481 rc=$?
482 echo "ERROR: creating directory $dir ($rc)" >&2
483 exit $rc
484 fi
485
486 if [ $type == 'nsd' ]; then
487 folders=("${NSD_FOLDERS[@]}")
488 else
489 folders=("${VNFD_FOLDERS[@]}")
490 fi
491
492 for d in ${folders[@]}; do
493 mkdir -p $dir/$d
494 if [ $? -ne 0 ]; then
495 rc=$?
496 echo "ERROR: creating directory $dir/$d ($rc)" >&2
497 exit $rc
498 fi
499 if [ $VERBOSE == true ]; then
500 echo "Created folder $d in $dir"
501 fi
502 done
503
504 if [ $VERBOSE == true ]; then
505 echo "INFO: Created folders for in $dir"
506 fi
507
508 # Write a descriptor template file
509 if [ $type == 'vnfd' ]; then
510
511 # Copy cloud init file to correct folder
512 if [[ -n ${CLOUD_INIT_FILE} ]]; then
513 if [[ -e ${CLOUD_INIT_FILE} ]]; then
514 cp ${CLOUD_INIT_FILE} $dir/cloud_init
515 else
516 echo "ERROR: Unable to find cloud-init-file ${CLOUD_INIT_FILE}"
517 exit 1
518 fi
519 fi
520
521 write_vnfd_tmpl $dir
522 else
523 write_nsd_tmpl $dir $vnfd
524 fi
525
526 write_readme $dir
527
528 if [ $ARCHIVE == true ]; then
529 # Create archive of the package
530 cd $dest_dir
531 if [ $VERBOSE == true ]; then
532 tar zcvf ${name}.tar.gz ${name}
533 echo "Created package ${name}.tar.gz in $dest_dir"
534 else
535 tar zcvf ${name}.tar.gz ${name} >/dev/null 2>&1
536 fi
537
538 if [ $? -ne 0 ]; then
539 echo "ERROR: Creating archive for ${name} in $dest_dir" >&2
540 exit 1
541 fi
542
543 echo "$dest_dir/${name}.tar.gz" >&2
544
545 if [ $RM == true ]; then
546 rm -rf ${name}
547 fi
548 fi
549 }
550
551 OPTS=`getopt -o vhnt:d:caN --long verbose,dry-run,help,package-type:,destination-dir,create-folder,no-remove-files,archive,nsd,vendor:,interface-type:,vcpu:,memory:,storage:,image:,cloud-init-file:,cloud-init:,interfaces:,debug -n $SCRIPTNAME -- "$@"`
552
553 if [ $? != 0 ] ; then
554 echo "ERROR: Failed parsing options ($?)." >&2
555 usage
556 exit 1
557 fi
558
559 #echo "$OPTS"
560 eval set -- "$OPTS >/dev/null 2>&1"
561
562 while true; do
563 case "$1" in
564 -v | --verbose ) VERBOSE=true; shift ;;
565 -h | --help ) usage; exit 0; shift ;;
566 -n | --dry-run ) DRY_RUN=true; shift ;;
567 -t | --package-type ) check_type "$2"; shift; shift ;;
568 -d | --destination-dir ) DEST_DIR=$2; shift; shift;;
569 -c | --create-folder ) CREATE=true; shift;;
570 -N | --no-remove-files ) RM=''; shift;;
571 -a | --archive ) ARCHIVE=true; shift;;
572 --nsd ) CREATE_NSD=true; shift;;
573 --vendor ) VENDOR=$2; shift; shift;;
574 --interface-type ) INTF_TYPE=$2; shift; shift;;
575 --vcpu ) VCPU=$2; shift; shift;;
576 --memory ) MEMORY=$2; shift; shift;;
577 --storage ) STORAGE=$2; shift; shift;;
578 --image ) IMAGE=$2; shift; shift;;
579 --cloud-init ) CLOUD_INIT=$2; shift; shift;;
580 --cloud-init-file ) CLOUD_INIT_FILE=$2; shift; shift;;
581 --interfaces ) INTERFACES=$2; shift; shift;;
582 --debug ) DEBUG=true; shift;;
583 -- ) shift; break ;;
584 * ) break ;;
585 esac
586 done
587
588 if [ $DEBUG == true ]; then
589 echo "INFO: Debugging ON"
590 set -x
591 fi
592
593 if [ $VERBOSE == true ]; then
594 echo "INFO: Descriptor type: $TYPE"
595 fi
596
597 # Dry run is to validate existing descriptor folders
598 if [ $DRY_RUN == true ] && [ $CREATE == true ]; then
599 echo "ERROR: Option dry-run with create-folders not supported!" >&2
600 exit 1
601 fi
602
603 if [ $# -gt 1 ]; then
604 BASE_DIR=$1
605 PKG=$(basename $2)
606 else
607 BASE_DIR=$(dirname $1)
608 PKG=$(basename $1)
609 fi
610
611 if [ $VERBOSE == true ]; then
612 echo "INFO: Using base dir: $BASE_DIR"
613 fi
614
615 if [ $VERBOSE == true ]; then
616 echo "INFO: Using package: $PKG"
617 fi
618
619 if [[ -z "$PKG" ]]; then
620 echo "ERROR: Need to specify the package name" >&2
621 usage >&2
622 exit 1
623 fi
624
625 if [[ ! -d $BASE_DIR ]]; then
626 if [ $CREATE == true ]; then
627 mkdir -p $BASE_DIR
628 if [ $? -ne 0 ]; then
629 echo "ERROR: Unable to create base directory $BASE_DIR" >&2
630 exit 1
631 fi
632 fi
633 fi
634 cd $BASE_DIR
635 if [ $? -ne 0 ]; then
636 echo "ERROR: Unable to change to base directory $BASE_DIR!" >&2
637 exit 1
638 fi
639
640 # Get full base dir path
641 BASE_DIR=`pwd`
642 cd $cur_dir
643
644 if [[ -z $DEST_DIR ]]; then
645 DEST_DIR=$BASE_DIR # Default to base directory
646 fi
647
648 mkdir -p $DEST_DIR
649
650 cd $DEST_DIR
651 if [ $? -ne 0 ]; then
652 echo "ERROR: Not able to access destination directory $DEST_DIR!" >&2
653 exit 1
654 fi
655
656 # Get the full destination dir path
657 DEST_DIR=`pwd`
658 cd $cur_dir
659
660 dir=${BASE_DIR}/${PKG}
661
662 function add_chksum() {
663 if [ $VERBOSE == true ]; then
664 echo "INFO: Add file $1 to $CHKSUM"
665 fi
666
667 md5sum $1 >> $CHKSUM
668 }
669
670 if [ $CREATE == false ]; then
671 if [ ! -d $dir ]; then
672 echo "INFO: Package folder $dir not found!" >&2
673 exit 1
674 fi
675
676 cd $dir
677 if [ $? -ne 0 ]; then
678 rc=$?
679 echo "ERROR: changing directory to $dir ($rc)" >&2
680 exit $rc
681 fi
682
683 # Remove checksum file, if present
684 rm -f $CHKSUM
685
686 # Check if the descriptor file is present
687 if [[ -z $TYPE ]]; then
688 # Desc type not specified, look for the desc file and guess the type
689 # Required for backward compatibility
690 for ty in ${DESC_TYPES[@]}; do
691 re=$(get_expr false "$ty" "*_$ty" "*_${ty}_*")
692 desc=$(find * -maxdepth 0 -type f $re 2>/dev/null)
693
694 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
695 # Check the vnfd|nsd folder
696 if [ ! -d $ty ]; then
697 continue
698 fi
699 re=$(get_expr false "*")
700 desc=$(find $ty/* -maxdepth 0 -type f $re 2>/dev/null)
701 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
702 continue
703 elif [ ${#desc[@]} -gt 1 ]; then
704 echo "ERROR: Found multiple descriptor files: ${desc[@]}" >&2
705 exit 1
706 fi
707 # Descriptor sub directory
708 desc_sub_dir=$ty
709 fi
710
711 TYPE=$ty
712 if [ $TYPE == 'nsd' ]; then
713 folders=("${NSD_FOLDERS[@]}")
714 else
715 folders=("${VNFD_FOLDERS[@]}")
716 fi
717
718 if [ $VERBOSE == true ]; then
719 echo "INFO: Determined descriptor is of type $TYPE"
720 fi
721 break
722 done
723
724 if [[ -z $TYPE ]]; then
725 echo "ERROR: Unable to determine the descriptor type!" >&2
726 exit 1
727 fi
728 else
729 if [ $TYPE == 'nsd' ]; then
730 folders=("${NSD_FOLDERS[@]}")
731 else
732 folders=("${VNFD_FOLDERS[@]}")
733 fi
734
735 # Check for descriptor of type provided on command line
736 re=$(get_expr false "$TYPE" "*_${TYPE}" "*_${TYPE}_*")
737 desc=$(find * -maxdepth 0 -type f $re 2>/dev/null)
738
739 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
740 # Check if it is under vnfd/nsd subdirectory
741 # Backward compatibility support
742 re=$(get_expr false "*")
743 desc=$(find $TYPE/* -maxdepth 0 -type f $re 2>/dev/null)
744 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
745 echo "ERROR: Did not find descriptor file of type $TYPE" \
746 " in $dir" >&2
747 exit 1
748 fi
749 desc_sub_dir=$ty
750 fi
751 fi
752
753 if [ ${#desc[@]} -gt 1 ]; then
754 echo "ERROR: Found multiple files of type $TYPE in $dir: $desc" >&2
755 exit 1
756 fi
757
758 descriptor=${desc[0]}
759
760 # Check if there are files not supported
761 files=$(find * -maxdepth 0 -type f ! -name $descriptor 2>/dev/null)
762
763 for f in ${files[@]}; do
764 if [ $(contains "${ALLOWED_FILES[@]}" $f) == "n" ]; then
765 echo "WARN: Unsupported file $f found"
766 fi
767 done
768
769 if [ $VERBOSE == true ]; then
770 echo "INFO: Found descriptor package: ${desc_sub_dir} ${descriptor}"
771 fi
772
773 if [ $DRY_RUN == false ]; then
774 add_chksum ${descriptor}
775 fi
776
777 # Check the folders are supported ones
778 dirs=$( find * -maxdepth 0 -type d )
779
780 for d in ${dirs[@]}; do
781 if [ $(contains "${folders[@]}" $d) == "y" ]; then
782 if [ $DRY_RUN == false ]; then
783 find $d/* -type f 2>/dev/null|
784 while read file; do
785 add_chksum $file
786 done
787 fi
788 elif [[ -z $desc_sub_dir ]] || [ $d != $desc_sub_dir ]; then
789 echo "WARN: $d is not part of standard folders " \
790 "for descriptor type $TYPE in $PKG"
791 fi
792 done
793
794 if [ $VERBOSE == true ]; then
795 echo "INFO: Creating archive for $PKG"
796 fi
797
798 cd $BASE_DIR
799 if [ $DRY_RUN == false ]; then
800 if [ $VERBOSE == true ]; then
801 tar zcvf "$DEST_DIR/$PKG.tar.gz" "${PKG}" ${RM}
802 else
803 #tar zcvf ${name}.tar.gz ${name} >/dev/null 2>&1
804 tar zcvf "$DEST_DIR/$PKG.tar.gz" "${PKG}" ${RM} > /dev/null 2>&1
805 fi
806 if [ $? -ne 0 ]; then
807 rc=$?
808 echo "ERROR: creating archive for $PKG ($rc)" >&2
809 exit $rc
810 fi
811 fi
812 else
813 # Create, default to VNFD if no type is defined
814 if [[ -z $TYPE ]]; then
815 TYPE=vnfd
816 if [ $VERBOSE == true ]; then
817 echo "WARNING: Defaulting to descriptor type $TYPE"
818 fi
819 fi
820
821 if [ $TYPE == 'vnfd' ]; then
822 if [[ -z $IMAGE ]]; then
823 echo "ERROR: Image file need to be specified for VNF"
824 exit 1
825 fi
826 generate_package vnfd $PKG $DEST_DIR
827 fi
828
829 if [ $TYPE == 'nsd' -o $CREATE_NSD == true ]; then
830 generate_package nsd $PKG $DEST_DIR
831 fi
832
833 fi
834
835 cd $cur_dir