basic ec2 and s3 working
This commit is contained in:
parent
6a060dfd7e
commit
77d6df6531
33 changed files with 561 additions and 1 deletions
44
moto/ec2/models.py
Normal file
44
moto/ec2/models.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
from boto.ec2.instance import Instance, InstanceState, Reservation
|
||||
|
||||
from moto.core import BaseBackend
|
||||
from .utils import random_instance_id, random_reservation_id
|
||||
|
||||
|
||||
class MockEC2(BaseBackend):
|
||||
base_url = "https://ec2.us-east-1.amazonaws.com"
|
||||
|
||||
def __init__(self):
|
||||
self.reservations = {}
|
||||
|
||||
def add_instance(self):
|
||||
new_instance = Instance()
|
||||
new_instance.id = random_instance_id()
|
||||
new_instance._state = InstanceState(0, "pending")
|
||||
|
||||
new_reservation = Reservation()
|
||||
new_reservation.id = random_reservation_id()
|
||||
new_reservation.instances = [new_instance]
|
||||
self.reservations[new_reservation.id] = new_reservation
|
||||
return new_reservation
|
||||
|
||||
def terminate_instances(self, instance_ids):
|
||||
terminated_instances = []
|
||||
for instance in self.all_instances():
|
||||
if instance.id in instance_ids:
|
||||
instance._state = InstanceState(32, 'shutting-down')
|
||||
terminated_instances.append(instance)
|
||||
|
||||
return terminated_instances
|
||||
|
||||
def all_instances(self):
|
||||
instances = []
|
||||
for reservation in self.all_reservations():
|
||||
for instance in reservation.instances:
|
||||
instances.append(instance)
|
||||
return instances
|
||||
|
||||
def all_reservations(self):
|
||||
return self.reservations.values()
|
||||
|
||||
|
||||
ec2_backend = MockEC2()
|
||||
Loading…
Add table
Add a link
Reference in a new issue