I am trying to create a copy of a file within a container using kubernetes python api.
Below is the function I want to create:
def create_file_copy(self, file_name, pod_name, pod_namespace=None):
if pod_namespace is None:
pod_namespace = self.svc_ns
stream(self.v1.connect_get_namespaced_pod_exec, name = pod_name, namespace = self.svc_ns ,command=['/bin/sh', '-c', 'cp file_name file_name_og'], stderr=True, stdin=True, stdout=True, tty=True)
NOTE: self.v1 is a kubernetes client api object which can access the kubernetes api methods.
My question is around how do I parameterize file_name in "cp file_name file_name_og" in the command parameter ?
No an expert in linux commands so any help is appreciated. Thanks
Assuming that both file_name
and file_name_og
are to be parameterized, this will make the cp
copy command be constructed dynamically from function's arguments:
def create_file_copy(self, file_name, file_name_og, pod_name, pod_namespace=None):
if pod_namespace is None:
pod_namespace = self.svc_ns
stream(self.v1.connect_get_namespaced_pod_exec, name = pod_name, namespace = self.svc_ns ,command=['/bin/sh', '-c', 'cp "' + file_name + '" "' + file_name_og + '"'], stderr=True, stdin=True, stdout=True, tty=True)