Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixops
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a3f4d1b1222e
Choose a base ref
...
head repository: NixOS/nixops
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e59765e3032e
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Oct 23, 2019

  1. Adding Nixops delete-resources Command:

    This command will allow users to painlessly remove resources from nixops database while preserving the actual resource. This can be helpful in various disater recovery scenarios when we need to attach an EBS volume to prod form shadow or vice versa. then can safely reeuse that deployment since the shadow won't clain the volume transfered to prod as it's own and tires to destory it
    PsyanticY committed Oct 23, 2019
    Copy the full SHA
    9753a41 View commit details
  2. Merge pull request #1201 from PsyanticY/clearstate

    Adding nixops delete-resources command
    AmineChikhaoui authored Oct 23, 2019
    Copy the full SHA
    e59765e View commit details
Showing with 31 additions and 0 deletions.
  1. +7 −0 nixops/deployment.py
  2. +14 −0 nixops/resources/__init__.py
  3. +5 −0 nixops/script_defs.py
  4. +5 −0 scripts/nixops
7 changes: 7 additions & 0 deletions nixops/deployment.py
Original file line number Diff line number Diff line change
@@ -1160,6 +1160,13 @@ def destroy_resources(self, include=[], exclude=[], wipe=False):
"--arg", "machines", py2nix(attrs, inline=True)]) != 0:
raise Exception("cannot update profile ‘{0}’".format(profile))

def delete_resources(self, include=[], exclude=[]):
"""delete all resources state."""
def worker(m):
if not should_do(m, include, exclude): return
if m.delete_resources(): self.delete_resource(m)

nixops.parallel.run_tasks(nr_workers=-1, tasks=self.resources.values(), worker_fun=worker)

def reboot_machines(self, include=[], exclude=[], wait=False,
rescue=False, hard=False):
14 changes: 14 additions & 0 deletions nixops/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -189,6 +189,20 @@ def destroy(self, wipe=False):
)
return False

def delete_resources(self):
"""delete this resource state, if possible."""
if not self.depl.logger.confirm(
"are you sure you want to clear the state of {}? "
"this will only remove the resource from the local "
"NixOPS state and the resource may still exist outside "
"of the NixOPS database.".format(self.name)):
return False

self.logger.warn(
"removing resource {} from the local NixOPS database ...".format(self.name)
)
return True

def next_charge_time(self):
"""Return the time (in Unix epoch) when this resource will next incur
a financial charge (or None if unknown)."""
5 changes: 5 additions & 0 deletions nixops/script_defs.py
Original file line number Diff line number Diff line change
@@ -456,6 +456,11 @@ def op_reboot(args):
rescue=args.rescue,
hard=args.hard)

def op_delete_resources(args):
depl = open_deployment(args)
if args.confirm:
depl.logger.set_autoresponse("y")
depl.delete_resources(include=args.include or [], exclude=args.exclude or [])

def op_stop(args):
depl = open_deployment(args)
5 changes: 5 additions & 0 deletions scripts/nixops
Original file line number Diff line number Diff line change
@@ -81,6 +81,11 @@ subparser.add_argument('--exclude', nargs='+', metavar='MACHINE-NAME', help='des
subparser.add_argument('--wipe', action='store_true', help='securely wipe data on the machines')
subparser.add_argument('--all', action='store_true', help='destroy all deployments')

subparser = add_subparser(subparsers, 'delete-resources', help='deletes the resource from the local NixOPS state file.')
subparser.set_defaults(op=op_delete_resources)
subparser.add_argument('--include', nargs='+', metavar='RESOURCE-NAME', help='delete only the specified resources')
subparser.add_argument('--exclude', nargs='+', metavar='RESOURCE-NAME', help='delete all resources except the specified resources')

subparser = add_subparser(subparsers, 'stop', help='stop all virtual machines in the network')
subparser.set_defaults(op=op_stop)
subparser.add_argument('--include', nargs='+', metavar='MACHINE-NAME', help='stop only the specified machines')