Exemple #1
0
 def remote_head(self, remote_url: str) -> Mapping[str, str]:
     logger.debug(f"http.head.fetch: {remote_url}")
     header_path = make_temp_path("curl-head")
     SUDO.parent_ensure(header_path)
     curl = Curl()
     with_auth_url(curl, remote_url)
     with_proxy_config(curl, remote_url)
     curl.with_file_head(header_path)
     curl.execute_unit_sert()
     header_dict = parse_header_file(header_path)
     SUDO.files_delete(header_path)
     return header_dict
Exemple #2
0
 def invoke_fetch(self, effect: token.FetchEffect) -> None:
     remote_url = effect.url
     package_name = os.path.basename(remote_url)
     fetch_archive = make_temp_path('fetch-archive') + '-' + package_name
     fetch_extract = make_temp_path('fetch-extract') + '-' + package_name
     # download
     transport = transport_provider(remote_url)
     transport.get(fetch_archive, remote_url)
     # extract
     packer = packer_provider(remote_url)
     packer.extract(fetch_archive, fetch_extract)
     # move
     source_path = fetch_extract + '/' + effect.source
     target_path = self.runtime_path(effect.target)
     SUDO.files_move(source_path, target_path)
     # clean
     SUDO.files_delete(fetch_archive)
     SUDO.files_delete(fetch_extract)
Exemple #3
0
 def extract(self, archive_path: str, extract_path: str) -> None:
     logger.debug(f"pack.extract.tar: {extract_path}")
     SUDO.file_assert(archive_path)
     extract_temp = make_temp_path("tar-extract-temp")
     SUDO.folder_ensure(extract_temp)
     tar = Tar()
     tar.with_archive(archive_path)
     tar.with_extract(extract_temp)
     tar.with_packer(archive_path)
     tar.with_make_unpack()  # keep last
     tar.execute_unit_sert()
     if SUDO.folder_check(extract_path):
         # user rsync to preserve active machines
         SUDO.files_sync_full(extract_temp, extract_path)
         SUDO.files_delete(extract_temp)
     else:
         # user move for efficiency
         SUDO.files_move(extract_temp, extract_path)
     synchronize_header(archive_path, extract_path)
Exemple #4
0
 def get(self, local_url: str, remote_url: str) -> None:
     "fetch remote resource and persist headers in xattr"
     logger.debug(f"http.get.fetch: {remote_url}")
     local, remote = self.parse(local_url, remote_url)
     header_path = make_temp_path("curl-head")
     source_path = make_temp_path("curl-gets")
     target_path = local.path
     SUDO.parent_ensure(header_path)
     curl = Curl()
     with_auth_url(curl, remote_url)
     with_proxy_config(curl, remote_url)
     curl.with_file_get(source_path)
     curl.with_dump_header(header_path)
     curl.execute_unit_sert()
     header_dict = parse_header_file(header_path)
     SUDO.files_delete(header_path)
     SUDO.files_move(source_path, target_path)
     # TODO attr
     SUDO.xattr_save(target_path, header_dict)
Exemple #5
0
def perform_erase(service: str) -> None:
    image_path = service_image(service)
    SUDO.files_delete(image_path)
Exemple #6
0
def perform_machine_runtime_erase(machine_result:MachineResult) -> None:
    "remove machine runtime folder, i.e,:"
    "/var/lib/nspawn/runtime/<machine>"
    base_dir = machine_result.machine_store.base_dir()
    SUDO.files_delete(base_dir)
Exemple #7
0
def perform_machine_delete(machine_result:MachineResult) -> None:
    "delete machine systemd service file"
    service_file = machine_result.machine_store.service_file()
    SUDO.files_delete(service_file)
    SYSTEM_CTL.daemon_reload()
Exemple #8
0
def perform_image_erase_path(image_store: ImageStore) -> None:
    SUDO.files_delete(image_store.archive_path())
    SUDO.files_delete(image_store.extract_path())