Skip to content

Commit

Permalink
Don't modify incoming arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
bra-fsn committed Aug 28, 2024
1 parent 40589aa commit fc4d85a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 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.23"
version = "0.0.24"
requires-python = ">= 3.9"
dependencies = [
"click",
Expand Down
37 changes: 22 additions & 15 deletions src/sc_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,46 +69,53 @@ def pulumi_stack(

def create(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)):
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)

stack = pulumi_stack(pulumi_program, **pulumi_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.up(**stack_opts)


def destroy(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)):
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)
stack = pulumi_stack(lambda: None, **pulumi_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.up(**stack_opts)


def destroy_stack(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)):
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)
stack = pulumi_stack(lambda: None, **pulumi_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.refresh(**stack_opts)
stack.destroy(**stack_opts)
stack.workspace.remove_stack(stack.name)


def cancel(vendor, pulumi_opts, resource_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)

stack = pulumi_stack(lambda: None, **pulumi_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.cancel()


def get_stack(vendor, pulumi_opts, resource_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)

return pulumi_stack(lambda: None, **pulumi_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)

0 comments on commit fc4d85a

Please sign in to comment.