예제 #1
0
파일: network.py 프로젝트: viogq/nspawn
def interface_list() -> List[str]:
    """
    Discover available host interfaces
    """
    cmd_ip = system_command('ip')
    command = f"{cmd_ip} -o addr show up primary scope global".split()
    result = SUDO.execute_unit(command)
    result.assert_return()
    line_list = result.stdout.splitlines()
    pattern = re.compile(r"^\d+[:]\s+(\S+)\s+(.+)$")
    select = lambda line: pattern.search(line).group(1)
    face_list = list(map(select, line_list))
    return face_list
예제 #2
0
 def nspawn_exec_stop(self) -> Command:
     """
     Container stop command
     """
     program = system_command('true')
     return Command([program])
예제 #3
0
 def file_create(self, path) -> Command:
     touch = system_command('touch')
     return Command([touch, '-a', path])
예제 #4
0
 def folder_delete(self, path) -> Command:
     rm = system_command('rm')
     return Command([rm, '-r', '-f', path])
예제 #5
0
 def folder_create(self, path) -> Command:
     mkdir = system_command('mkdir')
     return Command([mkdir, '-p', path])
예제 #6
0
 def mount_point_desure(self) -> Command:  # TODO
     shell = system_command('sh')
     test = " ".join(self.mount_point_test())
     delete = " ".join(self.mount_point_delete())
     return Command([shell, '-c', f"while {test} ; do {delete} ; sleep {self.delay} ; done" ])
예제 #7
0
 def mount_point_ensure(self) -> Command:  # TODO
     shell = system_command('sh')
     test = " ".join(self.mount_point_test())
     create = " ".join(self.mount_point_create())
     return Command([shell, '-c', f"until {test} ; do {create} ; sleep {self.delay} ; done" ])
예제 #8
0
 def mount_point_delete(self) -> Command:
     umount = system_command('umount')
     point = self.machine_store.mount_point()
     return Command([umount, point])
예제 #9
0
 def mount_point_create(self) -> Command:
     mount = system_command('mount')
     point = self.machine_store.mount_point()
     options = self.mount_options()
     return Command([mount, '-t', 'overlay', '-o', options, 'overlay', point])
예제 #10
0
 def mount_point_test(self) -> Command:
     test = system_command('mountpoint')
     point = self.machine_store.mount_point()
     return Command([test, point])