Skip to content

Commit

Permalink
Fix again
Browse files Browse the repository at this point in the history
  • Loading branch information
bra-fsn committed Aug 28, 2024
1 parent 58995e4 commit 04778ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sparecores-runner"
version = "0.0.24"
version = "0.0.25"
requires-python = ">= 3.9"
dependencies = [
"click",
Expand Down
46 changes: 26 additions & 20 deletions src/sc_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pulumi.automation import create_or_select_stack
from typing import Annotated, Callable, get_type_hints
import click
import copy
import os
import sentry_sdk

Expand Down Expand Up @@ -68,54 +69,59 @@ def pulumi_stack(


def create(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)):
# don't modify incoming opts
pulumi_opts = copy.deepcopy(pulumi_opts)
resource_f = getattr(resources, f"{resources.PREFIX}{vendor}")
if not pulumi_opts.get("stack_name"):
pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts)

def pulumi_program():
return resource_f(**resource_opts)

if pulumi_opts.get("stack_name"):
stack = pulumi_stack(pulumi_program, **pulumi_opts)
else:
stack = pulumi_stack(pulumi_program, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts)
stack = pulumi_stack(pulumi_program, **pulumi_opts)
stack.up(**stack_opts)


def destroy(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)):
# don't modify incoming opts
pulumi_opts = copy.deepcopy(pulumi_opts)
resource_f = getattr(resources, f"{resources.PREFIX}{vendor}")
if not pulumi_opts.get("stack_name"):
pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts)

if pulumi_opts.get("stack_name"):
stack = pulumi_stack(lambda: None, **pulumi_opts)
else:
stack = pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts)
stack = pulumi_stack(lambda: None, **pulumi_opts)
stack.up(**stack_opts)


def destroy_stack(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)):
# don't modify incoming opts
pulumi_opts = copy.deepcopy(pulumi_opts)
resource_f = getattr(resources, f"{resources.PREFIX}{vendor}")
if not pulumi_opts.get("stack_name"):
pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts)

if pulumi_opts.get("stack_name"):
stack = pulumi_stack(lambda: None, **pulumi_opts)
else:
stack = pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts)
stack = pulumi_stack(lambda: None, **pulumi_opts)
stack.refresh(**stack_opts)
stack.destroy(**stack_opts)
stack.workspace.remove_stack(stack.name)


def cancel(vendor, pulumi_opts, resource_opts):
# don't modify incoming opts
pulumi_opts = copy.deepcopy(pulumi_opts)
resource_f = getattr(resources, f"{resources.PREFIX}{vendor}")
if not pulumi_opts.get("stack_name"):
pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts)

if pulumi_opts.get("stack_name"):
stack = pulumi_stack(lambda: None, **pulumi_opts)
else:
stack = pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts)
stack = pulumi_stack(lambda: None, **pulumi_opts)
stack.cancel()


def get_stack(vendor, pulumi_opts, resource_opts):
# don't modify incoming opts
pulumi_opts = copy.deepcopy(pulumi_opts)
resource_f = getattr(resources, f"{resources.PREFIX}{vendor}")
if not pulumi_opts.get("stack_name"):
pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts)

if pulumi_opts.get("stack_name"):
return pulumi_stack(lambda: None, **pulumi_opts)
else:
return pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts)
return pulumi_stack(lambda: None, **pulumi_opts)

0 comments on commit 04778ab

Please sign in to comment.