def run(self): args = self.parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) if utils.in_container() and not os.path.isabs(args.output): msg = "If running inside container --output path has to be absolute" logger.critical(msg) raise Exception(msg) nulecule_dir = utils.get_path(os.path.abspath(args.output)) if os.path.exists(nulecule_dir): msg = "{} must not exist".format(nulecule_dir) logger.critical(msg) raise Exception(msg) artifacts_dir = os.path.join(nulecule_dir, "artifacts", "kubernetes") nulecule_file = os.path.join(nulecule_dir, "Nulecule") oc = OpenshiftClient(oc=args.oc, namespace=args.project, oc_config=args.oc_config) artifacts = oc.export_all() # remove ugly thing to do :-( # I don't know hot to get securityContext and Selinux # to work on k8s for now :-( artifacts = oc.remove_securityContext(artifacts) # list of artifact for Nulecule file nulecule_artifacts = [] os.makedirs(artifacts_dir) filepath = os.path.join(artifacts_dir, "artifacts.json") nulecule_artifacts.append("file://{}".format( os.path.relpath(filepath, nulecule_dir))) anymarkup.serialize_file(artifacts, filepath, format="json") nulecule = { "specversion": "0.0.2", "id": args.project, "metadata": { "name": args.project }, "graph": [{ "name": args.project, "artifacts": { "kubernetes": nulecule_artifacts } }] } anymarkup.serialize_file(nulecule, nulecule_file, format="yaml") logger.info("Nulecule application created in {}".format( utils.remove_path(nulecule_dir)))
def __init__(self, oc=None, namespace=None, oc_config=None): if oc: self.oc = oc else: self.oc = self._find_oc() self.namespace = namespace if oc_config: self.oc_config = utils.get_path(oc_config)
def __init__(self, oc=None, namespace=None, oc_config=None, selector=None): if oc: self.oc = oc else: self.oc = self._find_oc() self.namespace = namespace self.selector = selector if oc_config: self.oc_config = utils.get_path(oc_config)
def run(self): args = self.parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) if utils.in_container() and not os.path.isabs(args.output): msg = "If running inside container --output path has to be absolute" logger.critical(msg) raise Exception(msg) nulecule_dir = utils.get_path(os.path.abspath(args.output)) if os.path.exists(nulecule_dir): msg = "{} must not exist".format(nulecule_dir) logger.critical(msg) raise Exception(msg) artifacts_dir = os.path.join(nulecule_dir, "artifacts", "kubernetes") nulecule_file = os.path.join(nulecule_dir, "Nulecule") oc = OpenshiftClient(oc=args.oc, namespace=args.project, oc_config=args.oc_config) artifacts = oc.export_all() # remove ugly thing to do :-( # I don't know hot to get securityContext and Selinux # to work on k8s for now :-( artifacts = oc.remove_securityContext(artifacts) # list of artifact for Nulecule file nulecule_artifacts = [] os.makedirs(artifacts_dir) filepath = os.path.join(artifacts_dir, "artifacts.json") nulecule_artifacts.append("file://{}".format(os.path.relpath( filepath, nulecule_dir))) anymarkup.serialize_file(artifacts, filepath, format="json") nulecule = {"specversion": "0.0.2", "id": args.project, "metadata": {"name": args.project}, "graph": [{"name": args.project, "artifacts": {"kubernetes": nulecule_artifacts}}]} anymarkup.serialize_file(nulecule, nulecule_file, format="yaml") logger.info("Nulecule application created in {}".format( utils.remove_path(nulecule_dir)))
def _find_oc(): """ Determine the path to oc command Search /usr/bin:/usr/local/bin Returns: str: path to oc binary """ test_paths = ['/usr/bin/oc', '/usr/local/bin/oc'] for path in test_paths: test_path = utils.get_path(path) logger.debug("trying oc at " + test_path) oc = test_path if os.access(oc, os.X_OK): logger.debug("found oc at " + test_path) return oc logger.fatal("No oc found in {}. Please provide corrent path to co " "binary using --oc argument".format(":".join(test_paths))) return None
def _find_oc(self): """ Determine the path to oc command Search /usr/bin:/usr/local/bin Returns: str: path to oc binary """ test_paths = ['/usr/bin/oc', '/usr/local/bin/oc'] for path in test_paths: test_path = utils.get_path(path) logger.debug("trying oc at " + test_path) oc = test_path if os.access(oc, os.X_OK): logger.debug("found oc at " + test_path) return oc logger.fatal("No oc found in {}. Please provide corrent path to co " "binary using --oc argument".format(":".join(test_paths))) return None
def run(self): args = self.parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) logger.debug("Running with arguments {}".format(args)) if utils.in_container() and not os.path.isabs(args.output): msg = "If running inside container --output path has to be absolute path" logger.critical(msg) raise Exception(msg) if not args.skip_push and args.export_images != 'none' and not args.registry_host: msg = "With --export-images you also need set --registry-host. If you don't want to push images to registry, you have to use --skip-push" logger.critical(msg) raise Exception(msg) # validate and parse --registry-login if args.registry_login is None: registry_user = None registry_password = None elif len(args.registry_login.split(":")) == 2: registry_user = args.registry_login.split(":")[0] registry_password = args.registry_login.split(":")[1] else: msg = "Invalid format of --registry-login. Use (username:password)" logger.critical(msg) raise Exception(msg) nulecule_dir = utils.get_path(args.output) if os.path.exists(nulecule_dir): msg = "{} must not exist".format(nulecule_dir) logger.critical(msg) raise Exception(msg) artifacts_dir = os.path.join(nulecule_dir, "artifacts") provider_paths = { provider: os.path.join(artifacts_dir, provider) for provider in NULECULE_PROVIDERS } nulecule_file = os.path.join(nulecule_dir, "Nulecule") oc = OpenshiftClient(oc=args.oc, namespace=args.project, oc_config=args.oc_config, selector=args.selector) # export project info from openshift exported_project = oc.export_project() # export images if args.export_images != "none": if args.export_images == "internal": only_internal = True elif args.export_images == "all": only_internal = False exported_project.pull_images(args.oc_registry_host, oc.get_username(), oc.get_token(), only_internal) # if registy-host is not set or skip-push is set do not perform push if args.registry_host and not args.skip_push: exported_project.push_images(args.registry_host, registry_user, registry_password, only_internal) exported_project.update_artifacts_images() provider_artifacts = {} for provider, path in provider_paths.items(): # list of artifact for Nulecule file nulecule_artifacts = [] os.makedirs(path) # create artifact files for artifact in exported_project.artifacts[provider]: if "name" in artifact["metadata"]: name = artifact["metadata"]["name"] else: name = "unknown" kind = artifact["kind"] filename = "{}-{}.json".format(name, kind) filepath = os.path.join(path, filename) if os.path.exists(filepath): filepath = utils.get_new_name(filepath) nulecule_artifacts.append("file://{}".format( os.path.relpath(filepath, nulecule_dir))) anymarkup.serialize_file(artifact, filepath, format="json") provider_artifacts[provider] = nulecule_artifacts nulecule = { "specversion": "0.0.2", "id": args.project, "metadata": { "name": args.project }, "graph": [{ "name": args.project, "artifacts": provider_artifacts }] } anymarkup.serialize_file(nulecule, nulecule_file, format="yaml") utils.generate_dockerfile(nulecule_dir, args.atomicapp_ver) logger.info("Nulecule application created in {}".format( utils.remove_path(nulecule_dir)))
def run(self): args = self.parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) logger.debug("Running with arguments {}".format(args)) if utils.in_container() and not os.path.isabs(args.output): msg = "If running inside container --output path has to be absolute path" logger.critical(msg) raise Exception(msg) if args.export_images != 'none' and not args.registry_host: msg = "With --export-images you need also set --registry-host" logger.critical(msg) raise Exception(msg) # validate and parse --registry-login if args.registry_login is None: registry_user = None registry_password = None elif len(args.registry_login.split(":")) == 2: registry_user = args.registry_login.split(":")[0] registry_password = args.registry_login.split(":")[1] else: msg = "Invalid format of --registry-login. Use (username:password)" logger.critical(msg) raise Exception(msg) nulecule_dir = utils.get_path(args.output) if os.path.exists(nulecule_dir): msg = "{} must not exist".format(nulecule_dir) logger.critical(msg) raise Exception(msg) artifacts_dir = os.path.join(nulecule_dir, "artifacts", "kubernetes") nulecule_file = os.path.join(nulecule_dir, "Nulecule") oc = OpenshiftClient(oc=args.oc, namespace=args.project, oc_config=args.oc_config) # export project info from openshift exported_project = oc.export_project() # export images if args.export_images != "none": if args.export_images == "internal": only_internal = True elif args.export_images == "all": only_internal = False exported_project.pull_images(args.oc_registry_host, oc.get_username(), oc.get_token(), only_internal) # if registy-host is not set do not perform push if args.registry_host: exported_project.push_images(args.registry_host, registry_user, registry_password, only_internal) exported_project.update_artifacts_images() artifacts = exported_project.artifacts # list of artifact for Nulecule file nulecule_artifacts = [] os.makedirs(artifacts_dir) filepath = os.path.join(artifacts_dir, "artifacts.json") nulecule_artifacts.append("file://{}".format(os.path.relpath( filepath, nulecule_dir))) anymarkup.serialize_file(artifacts, filepath, format="json") nulecule = {"specversion": "0.0.2", "id": args.project, "metadata": {"name": args.project}, "graph": [{"name": args.project, "artifacts": {"kubernetes": nulecule_artifacts}}]} anymarkup.serialize_file(nulecule, nulecule_file, format="yaml") utils.generate_dockerfile(nulecule_dir) logger.info("Nulecule application created in {}".format( utils.remove_path(nulecule_dir)))
def run(self): args = self.parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) logger.debug("Running with arguments {}".format(args)) if utils.in_container() and not os.path.isabs(args.output): msg = "If running inside container --output path has to be absolute path" logger.critical(msg) raise Exception(msg) if not args.skip_push and args.export_images != 'none' and not args.registry_host: msg = "With --export-images you also need set --registry-host. If you don't want to push images to registry, you have to use --skip-push" logger.critical(msg) raise Exception(msg) # validate and parse --registry-login if args.registry_login is None: registry_user = None registry_password = None elif len(args.registry_login.split(":")) == 2: registry_user = args.registry_login.split(":")[0] registry_password = args.registry_login.split(":")[1] else: msg = "Invalid format of --registry-login. Use (username:password)" logger.critical(msg) raise Exception(msg) nulecule_dir = utils.get_path(args.output) if os.path.exists(nulecule_dir): msg = "{} must not exist".format(nulecule_dir) logger.critical(msg) raise Exception(msg) artifacts_dir = os.path.join(nulecule_dir, "artifacts") provider_paths = {provider: os.path.join(artifacts_dir, provider) for provider in NULECULE_PROVIDERS} nulecule_file = os.path.join(nulecule_dir, "Nulecule") oc = OpenshiftClient(oc=args.oc, namespace=args.project, oc_config=args.oc_config, selector=args.selector) # export project info from openshift exported_project = oc.export_project() # export images if args.export_images != "none": if args.export_images == "internal": only_internal = True elif args.export_images == "all": only_internal = False exported_project.pull_images(args.oc_registry_host, oc.get_username(), oc.get_token(), only_internal) # if registy-host is not set or skip-push is set do not perform push if args.registry_host and not args.skip_push: exported_project.push_images(args.registry_host, registry_user, registry_password, only_internal) exported_project.update_artifacts_images() provider_artifacts = {} for provider, path in provider_paths.items(): # list of artifact for Nulecule file nulecule_artifacts = [] os.makedirs(path) # create artifact files for artifact in exported_project.artifacts[provider]: if "name" in artifact["metadata"]: name = artifact["metadata"]["name"] else: name = "unknown" kind = artifact["kind"] filename = "{}-{}.json".format(name, kind) filepath = os.path.join(path, filename) if os.path.exists(filepath): filepath = utils.get_new_name(filepath) nulecule_artifacts.append("file://{}".format(os.path.relpath( filepath, nulecule_dir))) anymarkup.serialize_file(artifact, filepath, format="json") provider_artifacts[provider] = nulecule_artifacts nulecule = {"specversion": "0.0.2", "id": args.project, "metadata": {"name": args.project}, "graph": [{"name": args.project, "artifacts": provider_artifacts}]} anymarkup.serialize_file(nulecule, nulecule_file, format="yaml") utils.generate_dockerfile(nulecule_dir, args.atomicapp_ver) logger.info("Nulecule application created in {}".format( utils.remove_path(nulecule_dir)))