Esempio n. 1
0
 def pack(self, output_path, verbose=False, workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path
Esempio n. 2
0
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(
         Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace,
                                                  self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path,
                                          self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
Esempio n. 3
0
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace, self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path, self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
             "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    parser.add_argument(
        "--project",
        help="create a new package based on the project at the specified "
             "location. If not specified will assume current directory '{}'"
             .format(os.getcwd()),
        required=False)

    parser.add_argument(
        "-d", "--destination",
        help="create the package on the specified location",
        required=False)

    parser.add_argument(
        "-n", "--name",
        help="create the package with the specific name",
        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    prj_root = args.project if args.project else os.getcwd()

    # Validate given arguments
    path_ids = dict()
    path_ids[ws_root] = Workspace.__descriptor_name__
    path_ids[prj_root] = Project.__descriptor_name__
    if not __validate_directory__(paths=path_ids):
        return

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)
    project = Project.__create_from_descriptor__(workspace, prj_root)

    pck = Packager(workspace, project, dst_path=args.destination)
    pck.generate_package(args.name)
Esempio n. 5
0
def main():
    import argparse

    parser = argparse.ArgumentParser(description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
        "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    parser.add_argument(
        "--project",
        help="create a new package based on the project at the specified "
        "location. If not specified will assume current directory '{}'".format(
            os.getcwd()),
        required=False)

    parser.add_argument("-d",
                        "--destination",
                        help="create the package on the specified location",
                        required=False)

    parser.add_argument("-n",
                        "--name",
                        help="create the package with the specific name",
                        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    prj_root = args.project if args.project else os.getcwd()

    # Validate given arguments
    path_ids = dict()
    path_ids[ws_root] = Workspace.__descriptor_name__
    path_ids[prj_root] = Project.__descriptor_name__
    if not __validate_directory__(paths=path_ids):
        return

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)
    project = Project.__create_from_descriptor__(workspace, prj_root)

    pck = Packager(workspace, project, dst_path=args.destination)
    pck.generate_package(args.name)
Esempio n. 6
0
    def publish_project(self):
        """
        Publish all components of a project to the available catalogue servers
        :return:
        """
        log.info("Publishing project: '{}'".format(self._project.project_root))

        # Ensure project was defined and its valid
        if not self._project or not Project.__is_valid__(self._project):
            log.error("Publish failed. Invalid or undefined project.")
            return

        # Retrieve project NSD and VNFDs files
        comp_list = self._project.get_ns_descriptor() + \
            self._project.get_vnf_descriptors()

        log.debug("The following project components "
                  "will be published: {}".format(comp_list))

        # Publish project components
        for comp in comp_list:
            self.publish_component(comp)
    def publish_project(self):
        """
        Publish all components of a project to the available catalogue servers
        :return:
        """
        log.info("Publishing project: '{}'".format(self._project.project_root))

        # Ensure project was defined and its valid
        if not self._project or not Project.__is_valid__(self._project):
            log.error("Publish failed. Invalid or undefined project.")
            return

        # Retrieve project NSD and VNFDs files
        comp_list = self._project.get_ns_descriptor() + \
            self._project.get_vnf_descriptors()

        log.debug("The following project components "
                  "will be published: {}".format(comp_list))

        # Publish project components
        for comp in comp_list:
            self.publish_component(comp)
Esempio n. 8
0
 def pack(self,
          output_path,
          verbose=False,
          workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path
Esempio n. 9
0
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Generate new sonata workspaces and project layouts")

    parser.add_argument("--init",
                        help="Create a new sonata workspace",
                        action="store_true")

    parser.add_argument("--workspace",
                        help="location of existing (or new) workspace. "
                        "If not specified will assume '{}'".format(
                            Workspace.DEFAULT_WORKSPACE_DIR),
                        required=False)

    parser.add_argument("--project",
                        help="create a new project at the specified location",
                        required=False)

    parser.add_argument("--debug",
                        help="increases logging level to debug",
                        required=False,
                        action="store_true")

    args = parser.parse_args()

    log_level = "INFO"
    if args.debug:
        log_level = "DEBUG"
        coloredlogs.install(level=log_level)

    # Ensure that one argument is given (--init, --workspace or --project)
    if not args.init and not args.workspace and not args.project:
        parser.print_help()
        return

    # Ensure that argument --workspace is not alone
    if not args.init and args.workspace and not args.project:
        parser.print_help()
        return

    # If workspace arg is not given, create a workspace in user home
    if args.workspace is None:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

        # If a workspace already exists at user home, throw an error and quit
        if args.init and os.path.isdir(ws_root):
            print("A workspace already exists in {}. "
                  "Please specify a different location.\n".format(ws_root),
                  file=sys.stderr)
            exit(1)

    else:
        ws_root = expanduser(args.workspace)

    if args.init:
        ws = Workspace(ws_root, log_level=log_level)
        if ws.check_ws_exists():
            print(
                "A workspace already exists at the "
                "specified location, exiting",
                file=sys.stderr)
            exit(1)

        log.debug("Attempting to create a new workspace")
        cwd = os.getcwd()
        ws.create_dirs()
        ws.create_files()
        os.chdir(cwd)
        log.debug("Workspace created.")
    else:
        ws = Workspace.__create_from_descriptor__(ws_root)
        if not ws:
            print(
                "Could not find a SONATA workspace "
                "at the specified location",
                file=sys.stderr)
            exit(1)

    if args.project is not None:
        log.debug("Attempting to create a new project")

        prj_root = os.path.expanduser(args.project)
        proj = Project(ws, prj_root)
        proj.create_prj()

        log.debug("Project created.")
Esempio n. 10
0
def main():
    import argparse

    parser = argparse.ArgumentParser(description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
        "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    exclusive_parser = parser.add_mutually_exclusive_group(required=True)

    exclusive_parser.add_argument(
        "--project",
        dest="project",
        help="create a new package based on the project at the specified "
        "location. If not specified will assume current directory '{}'".format(
            os.getcwd()),
        required=False)

    exclusive_parser.add_argument(
        "--custom",
        dest="custom",
        help="Create a custom package. Contents and descriptors can be added "
        "using the '--service' and '--function' arguments.",
        action="store_true",
        required=False)
    parser.add_argument(
        "--service",
        dest="service",
        nargs='*',
        help="Only applicable to custom packages. Add a service descriptor "
        "to the package. Multiple services may be specified separated "
        "with a space",
        required=False)
    parser.add_argument(
        "--function",
        dest="function",
        nargs='*',
        help="Only applicable to custom packages. Add a function descriptor "
        "to the package. Multiple functions may be specified separated "
        "with a space",
        required=False)
    parser.add_argument("-d",
                        "--destination",
                        help="create the package on the specified location",
                        required=False)

    parser.add_argument("-n",
                        "--name",
                        help="create the package with the specific name",
                        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)

    prj_root = args.project if args.project else os.getcwd()

    if args.project:

        # Validate given arguments
        path_ids = dict()
        path_ids[ws_root] = Workspace.__descriptor_name__
        path_ids[prj_root] = Project.__descriptor_name__
        if not __validate_directory__(paths=path_ids):
            return

        project = Project.__create_from_descriptor__(workspace, prj_root)

        pck = Packager(workspace, project=project, dst_path=args.destination)
        pck.generate_package(args.name)

    elif args.custom:

        if not (args.service or args.function):
            log.error("To create a custom package, the arguments '--service' "
                      "and/or '--function' must be used.")
            exit(1)

        pck = Packager(workspace,
                       services=args.service,
                       functions=args.function,
                       dst_path=args.destination)
        pck.generate_package(args.name)
Esempio n. 11
0
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Generate new sonata workspaces and project layouts")

    parser.add_argument(
        "--init",
        help="Create a new sonata workspace",
        action="store_true")

    parser.add_argument(
        "--workspace",
        help="location of existing (or new) workspace. "
             "If not specified will assume '{}'"
             .format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    parser.add_argument(
        "--project",
        help="create a new project at the specified location",
        required=False)

    parser.add_argument(
        "--debug",
        help="increases logging level to debug",
        required=False,
        action="store_true")

    args = parser.parse_args()

    log_level = "INFO"
    if args.debug:
        log_level = "DEBUG"
        coloredlogs.install(level=log_level)

    # Ensure that one argument is given (--init, --workspace or --project)
    if not args.init and not args.workspace and not args.project:
        parser.print_help()
        return

    # Ensure that argument --workspace is not alone
    if not args.init and args.workspace and not args.project:
        parser.print_help()
        return

    # If workspace arg is not given, create a workspace in user home
    if args.workspace is None:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

        # If a workspace already exists at user home, throw an error and quit
        if args.init and os.path.isdir(ws_root):
            print("A workspace already exists in {}. "
                  "Please specify a different location.\n"
                  .format(ws_root), file=sys.stderr)
            exit(1)

    else:
        ws_root = expanduser(args.workspace)

    if args.init:
        ws = Workspace(ws_root, log_level=log_level)
        if ws.check_ws_exists():
            print("A workspace already exists at the "
                  "specified location, exiting",
                  file=sys.stderr)
            exit(1)

        log.debug("Attempting to create a new workspace")
        cwd = os.getcwd()
        ws.create_dirs()
        ws.create_files()
        os.chdir(cwd)
        log.debug("Workspace created.")
    else:
        ws = Workspace.__create_from_descriptor__(ws_root)
        if not ws:
            print("Could not find a SONATA workspace "
                  "at the specified location",
                  file=sys.stderr)
            exit(1)

    if args.project is not None:
        log.debug("Attempting to create a new project")

        prj_root = os.path.expanduser(args.project)
        proj = Project(ws, prj_root)
        proj.create_prj()

        log.debug("Project created.")
Esempio n. 12
0
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
             "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    exclusive_parser = parser.add_mutually_exclusive_group(
        required=True
    )

    exclusive_parser.add_argument(
        "--project",
        dest="project",
        help="create a new package based on the project at the specified "
             "location. If not specified will assume current directory '{}'"
             .format(os.getcwd()),
        required=False)

    exclusive_parser.add_argument(
        "--custom",
        dest="custom",
        help="Create a custom package. Contents and descriptors can be added "
             "using the '--service' and '--function' arguments.",
        action="store_true",
        required=False
    )
    parser.add_argument(
        "--service",
        dest="service",
        nargs='*',
        help="Only applicable to custom packages. Add a service descriptor "
             "to the package. Multiple services may be specified separated "
             "with a space",
        required=False
    )
    parser.add_argument(
        "--function",
        dest="function",
        nargs='*',
        help="Only applicable to custom packages. Add a function descriptor "
             "to the package. Multiple functions may be specified separated "
             "with a space",
        required=False
    )
    parser.add_argument(
        "-d", "--destination",
        help="create the package on the specified location",
        required=False)

    parser.add_argument(
        "-n", "--name",
        help="create the package with the specific name",
        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)

    prj_root = args.project if args.project else os.getcwd()

    if args.project:

        # Validate given arguments
        path_ids = dict()
        path_ids[ws_root] = Workspace.__descriptor_name__
        path_ids[prj_root] = Project.__descriptor_name__
        if not __validate_directory__(paths=path_ids):
            return

        project = Project.__create_from_descriptor__(workspace, prj_root)

        pck = Packager(workspace, project=project, dst_path=args.destination)
        pck.generate_package(args.name)

    elif args.custom:

        if not (args.service or args.function):
            log.error("To create a custom package, the arguments '--service' "
                      "and/or '--function' must be used.")
            exit(1)

        pck = Packager(workspace, services=args.service,
                       functions=args.function, dst_path=args.destination)
        pck.generate_package(args.name)
Esempio n. 13
0
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Publish a project or component to the catalogue server")

    parser.add_argument(
        "--workspace",
        help="Specify workspace. Default is located at '{}'".format(
            Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    parser.add_argument("--project",
                        help="Specify project to be published",
                        required=False)

    parser.add_argument("-d",
                        "--component",
                        help="Project component to be published.",
                        required=False)

    parser.add_argument("-c",
                        "--catalogue",
                        help="Catalogue ID where to publish. "
                        "Overrides defaults in workspace config.")

    args = parser.parse_args()

    # Ensure that either --component or --project
    # argument is given, but not the two simultaneously (XOR)
    if bool(args.component) == bool(args.project):
        parser.print_help()
        return

    # If workspace arg is not given, specify workspace as the default location
    if not args.workspace:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR
    else:
        ws_root = expanduser(args.workspace)

    # Create the Workspace object
    ws = Workspace.__create_from_descriptor__(ws_root)
    if not ws:
        print("Could not find a SONATA SDK workspace at '{}'".format(ws_root),
              file=sys.stderr)
        exit(1)

    if args.project:
        prj_root = os.path.expanduser(args.project)
        proj = Project(ws, prj_root)
        if not proj:
            print(
                "Could not find a SONATA SDK project at '{}'".format(prj_root),
                file=sys.stderr)
            exit(1)

        pub = Publisher(ws, project=proj, catalogue=args.catalogue)
        pub.publish_project()

    if args.component:
        comp_file = os.path.expanduser(args.component)
        if not os.path.isfile(comp_file):
            print("'{}' is not a valid file".format(comp_file),
                  file=sys.stderr)
            exit(1)

        pub = Publisher(ws, component=comp_file, catalogue=args.catalogue)
        pub.publish_component()