diff options
author | Apeksha D Khakharia <akhakhar@redhat.com> | 2018-01-29 12:38:10 +0530 |
---|---|---|
committer | Apeksha D Khakharia <akhakhar@redhat.com> | 2018-01-29 12:38:30 +0530 |
commit | cbc41a646d4348313194e079221367738db81d6b (patch) | |
tree | 077d08edd73a8f3ecaa1cbdefa12563f4eefaeab /cns-libs/cnslibs/common/openshift_ops.py | |
parent | be8e17c8185c43a1a7170990e774639c9662023d (diff) |
CNS: adding library for creating namespace
Change-Id: Ia20fe357186ed408cfa3a42dc2d4ac70ddd29ba4
Signed-off-by: Apeksha D Khakharia <akhakhar@redhat.com>
Diffstat (limited to 'cns-libs/cnslibs/common/openshift_ops.py')
-rw-r--r-- | cns-libs/cnslibs/common/openshift_ops.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cns-libs/cnslibs/common/openshift_ops.py b/cns-libs/cnslibs/common/openshift_ops.py index 5920d51f..3d3dd061 100644 --- a/cns-libs/cnslibs/common/openshift_ops.py +++ b/cns-libs/cnslibs/common/openshift_ops.py @@ -267,3 +267,27 @@ def oc_get_all_pvs(ocp_node): dict: Dictionary containting data about the PV. """ return oc_get_yaml(ocp_node, 'pv', None) + + +def create_namespace(hostname, namespace): + ''' + This function creates namespace + Args: + hostname (str): hostname on which we need to + create namespace + namespace (str): project name + Returns: + bool: True if successful and if already exists, + otherwise False + ''' + cmd = "oc new-project %s" % namespace + ret, out, err = g.run(hostname, cmd, "root") + if ret == 0: + g.log.info("new namespace %s successfully created" % namespace) + return True + output = out.strip().split("\n")[0] + if "already exists" in output: + g.log.info("namespace %s already exists" % namespace) + return True + g.log.error("failed to create namespace %s" % namespace) + return False |