Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key/value backend #624

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7035abe
Move statefile into state.file module
moretea Mar 13, 2017
6da031f
Introduce different state state schemes.
moretea Mar 13, 2017
8269650
Rename statefile->state in deployment.py
moretea Mar 13, 2017
c73773f
Move file based deployment lock to file state implementation.
moretea Mar 13, 2017
8a4e34a
Fix indenting
moretea Mar 13, 2017
bb056ea
Bite the bullet; remove _db references from business objects + rename…
moretea Mar 13, 2017
6cc171a
move get_resources_for
moretea Mar 13, 2017
813a231
move set_deployment_attrs
moretea Mar 13, 2017
7b58934
move del_deployment_attr
moretea Mar 13, 2017
7ed3fd3
move get_deployment_attr
moretea Mar 13, 2017
0db686d
move create_resource
moretea Mar 13, 2017
97e0714
Move most logic in export() to get_all_deployment_attrs in statefile.
moretea Mar 13, 2017
584d658
Make import use an atomic transaction thingy.
moretea Mar 13, 2017
97bda1a
move clone_deployment
moretea Mar 13, 2017
77e9b93
move part of delete_resource
moretea Mar 13, 2017
4d33f93
missed a few _'s
moretea Mar 13, 2017
5649e39
move part of delete to _delete_deployment
moretea Mar 13, 2017
4075901
use state atomic
moretea Mar 13, 2017
5f39278
Move part of logic of rename to _rename_resource
moretea Mar 13, 2017
6605128
oh yeah, I did rename _db to __db!
moretea Mar 13, 2017
5881c06
Use atomic instead of _db
moretea Mar 13, 2017
de9d700
Use atomic instead of _db
moretea Mar 13, 2017
ff23c1c
move set_resource_attrs
moretea Mar 13, 2017
eb2a24a
move del_resource_attr
moretea Mar 13, 2017
47b3a43
move get_resource_attr
moretea Mar 13, 2017
6835823
move part of export to get_all_resource_attrs
moretea Mar 13, 2017
3739051
Use atomic instead of _db
moretea Mar 13, 2017
66dee1d
oh yeah, I did rename _db to __db!
moretea Mar 13, 2017
6254ccb
simple typo's
moretea Mar 13, 2017
2d1a822
Need to pass in object; too much coupling to refactor right now
moretea Mar 13, 2017
20c5e89
missed assigning to local dict
moretea Mar 13, 2017
6c37bbd
typo
moretea Mar 13, 2017
4baebf9
missing subclass function. Just copied for now
moretea Mar 13, 2017
44652be
typo
moretea Mar 13, 2017
e238874
locally reachable already
moretea Mar 13, 2017
56c39b7
missed the self parameter
moretea Mar 13, 2017
83b5ca1
use _state.atomic instead of _db
moretea Mar 14, 2017
abf3d6e
schema: file -> sqlite3
moretea Mar 14, 2017
0d999cf
Fix _rename_resource, needs resource_id
moretea Mar 14, 2017
a08de62
WIP: initial json backend.
moretea Mar 14, 2017
6baf57f
Include the deployment_uuid in the API for modifying resource attributes
moretea Mar 14, 2017
2dfa148
Small bug fixes
moretea Mar 14, 2017
6733fa7
Utilize deployment_uid
moretea Mar 14, 2017
3827e69
Also recognize json's true as a valid bool value
moretea Mar 14, 2017
056ab60
Undo split between state.atomic and state.db
moretea Mar 29, 2017
38aa181
Typo
moretea Mar 29, 2017
4aaf084
Rename file -> sqlite3_file in tests
moretea Mar 29, 2017
6950f37
Rename file -> sqlite3_file in scripts/nixops
moretea Mar 29, 2017
6576e16
Rename file -> sqlite3_file in scripts/nixops
moretea Mar 29, 2017
9d7cf8c
Merge branch 'master' into kv-state
rbvermaa Jul 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion nixops/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import errno
from collections import defaultdict
from xml.etree import ElementTree
import nixops.statefile
import nixops.backends
import nixops.logger
import nixops.parallel
Expand Down
23 changes: 23 additions & 0 deletions nixops/state/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import urlparse
import sys
import file

class WrongStateSchemeException(Exception):
pass

def open(url):
url = urlparse.urlparse(url)
scheme = url.scheme

if scheme == "":
scheme = "file"

def raise_(ex):
raise ex

switcher = {
"file": lambda(url): file.StateFile(url.path),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: wrong indentation

}

function = switcher.get(scheme, lambda(url): raise_(WrongStateSchemeException("Unknown state scheme!")))
return function(url)
Empty file added nixops/state/etcd.py
Empty file.
File renamed without changes.
34 changes: 17 additions & 17 deletions scripts/nixops
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from nixops import deployment
from nixops.nix_expr import py2nix
from nixops.parallel import MultipleExceptions, run_tasks

import nixops.statefile
import nixops.state.file
import prettytable
import argparse
import os
Expand Down Expand Up @@ -48,16 +48,16 @@ def sort_deployments(depls):
# $NIXOPS_DEPLOYMENT.
def one_or_all():
if args.all:
sf = nixops.statefile.StateFile(args.state_file)
return sf.get_all_deployments()
state = nixops.state.open(args.state_url)
return state.get_all_deployments()
else:
return [open_deployment()]


def op_list_deployments():
sf = nixops.statefile.StateFile(args.state_file)
state = nixops.state.open(args.state_url)
tbl = create_table([("UUID", 'l'), ("Name", 'l'), ("Description", 'l'), ("# Machines", 'r'), ("Type", 'c')])
for depl in sort_deployments(sf.get_all_deployments()):
for depl in sort_deployments(state.get_all_deployments()):
tbl.add_row(
[depl.uuid, depl.name or "(none)",
depl.description, len(depl.machines),
Expand All @@ -67,8 +67,8 @@ def op_list_deployments():


def open_deployment():
sf = nixops.statefile.StateFile(args.state_file)
depl = sf.open_deployment(uuid=args.deployment)
state = nixops.state.open(args.state_url)
depl = state.open_deployment(uuid=args.deployment)

depl.extra_nix_path = sum(args.nix_path or [], [])
for (n, v) in args.nix_options or []: depl.extra_nix_flags.extend(["--option", n, v])
Expand Down Expand Up @@ -101,8 +101,8 @@ def modify_deployment(depl):


def op_create():
sf = nixops.statefile.StateFile(args.state_file)
depl = sf.create_deployment()
state = nixops.state.open(args.state_url)
depl = state.create_deployment()
sys.stderr.write("created deployment ‘{0}’\n".format(depl.uuid))
modify_deployment(depl)
if args.name or args.deployment: set_name(depl, args.name or args.deployment)
Expand Down Expand Up @@ -189,10 +189,10 @@ def op_info():
])

if args.all:
sf = nixops.statefile.StateFile(args.state_file)
state = nixops.state.open(args.state_url)
if not args.plain:
tbl = create_table([('Deployment', 'l')] + table_headers)
for depl in sort_deployments(sf.get_all_deployments()):
for depl in sort_deployments(state.get_all_deployments()):
do_eval(depl)
print_deployment(depl)
if not args.plain: print tbl
Expand Down Expand Up @@ -491,16 +491,16 @@ def op_export():


def op_import():
sf = nixops.statefile.StateFile(args.state_file)
existing = set(sf.query_deployments())
state = nixops.state.open(args.state_url)
existing = set(state.query_deployments())

dump = json.loads(sys.stdin.read())

for uuid, attrs in dump.iteritems():
if uuid in existing:
raise Exception("state file already contains a deployment with UUID ‘{0}’".format(uuid))
with sf._db:
depl = sf.create_deployment(uuid=uuid)
with state._db:
depl = state.create_deployment(uuid=uuid)
depl.import_(attrs)
sys.stderr.write("added deployment ‘{0}’\n".format(uuid))

Expand Down Expand Up @@ -694,8 +694,8 @@ subparsers = parser.add_subparsers(help='sub-command help')

def add_subparser(name, help):
subparser = subparsers.add_parser(name, help=help)
subparser.add_argument('--state', '-s', dest='state_file', metavar='FILE',
default=nixops.statefile.get_default_state_file(), help='path to state file')
subparser.add_argument('--state', '-s', dest='state_url', metavar='FILE',
default=os.environ.get("NIXOPS_STATE_URL", nixops.state.file.get_default_state_file()), help='URL that points to the state provider.')
subparser.add_argument('--deployment', '-d', dest='deployment', metavar='UUID_OR_NAME',
default=os.environ.get("NIXOPS_DEPLOYMENT", os.environ.get("CHARON_DEPLOYMENT", None)), help='UUID or symbolic name of the deployment')
subparser.add_argument('--debug', action='store_true', help='enable debug output')
Expand Down
6 changes: 3 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import sys
import threading
from os import path
import nixops.statefile
import nixops.state.file

_multiprocess_shared_ = True

db_file = '%s/test.nixops' % (path.dirname(__file__))

def setup():
nixops.statefile.StateFile(db_file).close()
nixops.state.file.StateFile(db_file).close()

def destroy(sf, uuid):
depl = sf.open_deployment(uuid)
Expand All @@ -27,7 +27,7 @@ def destroy(sf, uuid):
depl.logger.log("deployment ‘{0}’ destroyed".format(uuid))

def teardown():
sf = nixops.statefile.StateFile(db_file)
sf = nixops.state.file.StateFile(db_file)
uuids = sf.query_deployments()
threads = []
for uuid in uuids:
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from os import path
import nixops.statefile
import nixops.state.file
from tests import db_file


class DatabaseUsingTest(object):
_multiprocess_can_split_ = True

def setup(self):
self.sf = nixops.statefile.StateFile(db_file)
self.sf = nixops.state.file.StateFile(db_file)

def teardown(self):
self.sf.close()
1 change: 0 additions & 1 deletion tests/functional/generic_deployment_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import subprocess
import nixops.statefile

from nose import SkipTest

Expand Down