1 # Copyright ETSI Contributors and Others.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
17 from osmclient
.cli_commands
import utils
18 from prettytable
import PrettyTable
21 logger
= logging
.getLogger("osmclient")
25 name
="package-create", short_help
="Create empty VNF or NS package structure"
27 @click.argument("package-type")
28 @click.argument("package-name")
32 help=('(NS/VNF/NST) Set the location for package creation. Default: "."'),
37 help='(VNF) Set the name of the vdu image. Default "image-name"',
40 "--vdus", default
=1, help="(VNF) Set the number of vdus in a VNF. Default 1"
43 "--vcpu", default
=1, help="(VNF) Set the number of virtual CPUs in a vdu. Default 1"
48 help="(VNF) Set the memory size (MB) of the vdu. Default 1024",
51 "--storage", default
=10, help="(VNF) Set the disk size (GB) of the vdu. Default 10"
56 help="(VNF) Set the number of additional interfaces apart from the management interface. Default 0",
59 "--vendor", default
="OSM", help='(NS/VNF) Set the descriptor vendor. Default "OSM"'
65 help="(NS/VNF/NST) Flag for overriding the package if exists.",
71 help="(NS/VNF/NST) Flag for generating descriptor .yaml with all possible commented options",
74 "--netslice-subnets", default
=1, help="(NST) Number of netslice subnets. Default 1"
77 "--netslice-vlds", default
=1, help="(NST) Number of netslice vlds. Default 1"
83 help="Flag to create a descriptor using the previous OSM format (pre SOL006, OSM<9)",
105 Creates an OSM NS, VNF, NST package
108 PACKAGE_TYPE: Package to be created: NS, VNF or NST.
109 PACKAGE_NAME: Name of the package to create the folder with the content.
113 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
115 "Creating the {} structure: {}/{}".format(
116 package_type
.upper(), base_directory
, package_name
119 resp
= ctx
.obj
.package_tool
.create(
129 interfaces
=interfaces
,
132 netslice_subnets
=netslice_subnets
,
133 netslice_vlds
=netslice_vlds
,
140 name
="package-validate", short_help
="Validate descriptors given a base directory"
142 @click.argument("base-directory", default
=".", required
=False)
144 "--recursive/--no-recursive",
146 help="The activated recursive option will validate the yaml files"
147 " within the indicated directory and in its subdirectories",
153 help="Validates also the descriptors using the previous OSM format (pre SOL006)",
156 def package_validate(ctx
, base_directory
, recursive
, old
):
158 Validate descriptors given a base directory.
161 BASE_DIRECTORY: Base folder for NS, VNF or NST package.
164 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
165 results
= ctx
.obj
.package_tool
.validate(base_directory
, recursive
, old
)
166 table
= PrettyTable()
167 table
.field_names
= ["TYPE", "PATH", "VALID", "ERROR"]
168 # Print the dictionary generated by the validation function
169 for result
in results
:
171 [result
["type"], result
["path"], result
["valid"], result
["error"]]
173 table
.sortby
= "VALID"
174 table
.align
["PATH"] = "l"
175 table
.align
["TYPE"] = "l"
176 table
.align
["ERROR"] = "l"
181 name
="package-translate", short_help
="Translate descriptors given a base directory"
183 @click.argument("base-directory", default
=".", required
=False)
185 "--recursive/--no-recursive",
187 help="The activated recursive option will translate the yaml files"
188 " within the indicated directory and in its subdirectories",
194 help="Do not translate yet, only make a dry-run to test translation",
197 def package_translate(ctx
, base_directory
, recursive
, dryrun
):
199 Translate descriptors given a base directory.
202 BASE_DIRECTORY: Stub folder for NS, VNF or NST package.
205 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
206 results
= ctx
.obj
.package_tool
.translate(base_directory
, recursive
, dryrun
)
207 table
= PrettyTable()
208 table
.field_names
= [
216 # Print the dictionary generated by the validation function
217 for result
in results
:
220 result
["current type"],
224 result
["translated"],
228 table
.sortby
= "TRANSLATED"
229 table
.align
["PATH"] = "l"
230 table
.align
["TYPE"] = "l"
231 table
.align
["ERROR"] = "l"
235 @click.command(name
="package-build", short_help
="Build the tar.gz of the package")
236 @click.argument("package-folder")
238 "--skip-validation", default
=False, is_flag
=True, help="skip package validation"
241 "--skip-charm-build",
244 help="the charm will not be compiled, it is assumed to already exist",
247 def package_build(ctx
, package_folder
, skip_validation
, skip_charm_build
):
249 Build the package NS, VNF given the package_folder.
252 PACKAGE_FOLDER: Folder of the NS, VNF or NST to be packaged
255 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
256 results
= ctx
.obj
.package_tool
.build(
258 skip_validation
=skip_validation
,
259 skip_charm_build
=skip_charm_build
,
265 name
="descriptor-translate",
266 short_help
="Translate input descriptor file from Rel EIGHT OSM descriptors to SOL006 and prints in standard output",
268 @click.argument("descriptor-file", required
=True)
270 def descriptor_translate(ctx
, descriptor_file
):
272 Translate input descriptor.
275 DESCRIPTOR_FILE: Descriptor file for NS, VNF or Network Slice.
278 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
279 result
= ctx
.obj
.package_tool
.descriptor_translate(descriptor_file
)
283 # TODO: check if this command should be here. It is more related to nspkg and nfpkg
284 @click.command(name
="upload-package", short_help
="uploads a VNF package or NS package")
285 @click.argument("filename")
287 "--skip-charm-build",
290 help="the charm will not be compiled, it is assumed to already exist",
293 def upload_package(ctx
, filename
, skip_charm_build
):
294 """uploads a vnf package or ns package
296 filename: vnf or ns package folder, or vnf or ns package file (tar.gz)
299 ctx
.obj
.package
.upload(filename
, skip_charm_build
=skip_charm_build
)