MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / get_instance

Function get_instance

misc/python/materialize/scratch.py:648–669  ·  view source on GitHub ↗

Get an instance by instance id. The special name 'mine' resolves to a unique running owned instance, if there is one; otherwise the name is assumed to be an instance id.

(name: str)

Source from the content-addressed store, hash-verified

646
647
648def get_instance(name: str) -> Instance:
649 """
650 Get an instance by instance id. The special name 'mine' resolves to a
651 unique running owned instance, if there is one; otherwise the name is
652 assumed to be an instance id.
653 """
654 if name == "mine":
655 filters: list[FilterTypeDef] = [
656 {"Name": "tag:LaunchedBy", "Values": [whoami()]},
657 {"Name": "instance-state-name", "Values": ["pending", "running"]},
658 ]
659 instances = [i for i in boto3.resource("ec2").instances.filter(Filters=filters)]
660 if not instances:
661 raise RuntimeError("can't understand 'mine': no owned instance?")
662 if len(instances) > 1:
663 raise RuntimeError(
664 f"can't understand 'mine': too many owned instances ({', '.join(i.id for i in instances)})"
665 )
666 instance = instances[0]
667 say(f"understanding 'mine' as unique owned instance {instance.id}")
668 return instance
669 return boto3.resource("ec2").Instance(name)
670
671
672def list_instances(

Callers

nothing calls this directly

Calls 4

whoamiFunction · 0.85
sayFunction · 0.85
filterMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected