-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from typing import Dict, Type | ||
import nixops.plugins | ||
from nixops.storage import StorageBackend | ||
from nixops.storage.legacy import LegacyBackend | ||
|
||
|
||
@nixops.plugins.hookimpl | ||
def register_backends() -> Dict[str, Type[StorageBackend]]: | ||
return {} | ||
return {"legacy": LegacyBackend} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from nixops.storage import StorageArgDescriptions, StorageArgValues | ||
import nixops.statefile | ||
import sys | ||
import os | ||
import os.path | ||
|
||
|
||
class LegacyBackend: | ||
@staticmethod | ||
def arguments() -> StorageArgDescriptions: | ||
raise NotImplementedError | ||
|
||
def __init__(self, args: StorageArgValues) -> None: | ||
pass | ||
|
||
# fetchToFile: acquire a lock and download the state file to | ||
# the local disk. Note: no arguments will be passed over kwargs. | ||
# Making it part of the type definition allows adding new | ||
# arguments later. | ||
def fetchToFile(self, path: str, **kwargs) -> None: | ||
os.symlink(os.path.abspath(self.state_location()), path) | ||
|
||
def onOpen(self, sf: nixops.statefile.StateFile, **kwargs) -> None: | ||
pass | ||
|
||
def state_location(self) -> str: | ||
env_override = os.environ.get("NIXOPS_STATE", os.environ.get("CHARON_STATE")) | ||
if env_override is not None: | ||
return env_override | ||
|
||
home_dir = os.environ.get("HOME", "") | ||
charon_dir = f"{home_dir}/.charon" | ||
nixops_dir = f"{home_dir}/.nixops" | ||
|
||
if not os.path.exists(nixops_dir): | ||
if os.path.exists(charon_dir): | ||
sys.stderr.write( | ||
"renaming ‘{0}’ to ‘{1}’...\n".format(charon_dir, nixops_dir) | ||
) | ||
os.rename(charon_dir, nixops_dir) | ||
if os.path.exists(nixops_dir + "/deployments.charon"): | ||
os.rename( | ||
nixops_dir + "/deployments.charon", | ||
nixops_dir + "/deployments.nixops", | ||
) | ||
else: | ||
os.makedirs(nixops_dir, 0o700) | ||
|
||
return nixops_dir + "/deployments.nixops" | ||
|
||
# uploadFromFile: upload the new state file and release any locks | ||
# Note: no arguments will be passed over kwargs. Making it part of | ||
# the type definition allows adding new arguments later. | ||
def uploadFromFile(self, path: str, **kwargs) -> None: | ||
pass |