class AWS(object): def __init__(self, aws_access_key, aws_secret_key, aws_region): self._connection = boto.ec2.connect_to_region( aws_region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) self._region = aws_region self._price_store = AWSPricingStore() """Retreives a list of instances :param state one of running, terminated, stopped :returns: AWSInstance """ def instances(self, state="running"): reservations = self._connection.get_all_reservations() for reservation in reservations: for instance in reservation.instances: if instance.state == state: launchedAtUtc = self._parse_date_time(instance.launch_time) cost_per_hour = self._price_store.instance_cost_per_hour( self._region, instance.instance_type) yield AWSInstance(identifier=instance.id, launchedAtUtc=launchedAtUtc, aws_region=self._region, aws_instance_type=instance.instance_type, keyname=instance.key_name, cost_per_hour=cost_per_hour, tags=instance.tags) """Retreives a list of volumes :param state one of running, terminated, stopped :returns: AWSVolume """ def volumes(self): volumes = self._connection.get_all_volumes() for volume in volumes: createdAtUtc = self._parse_date_time(volume.create_time) cost_per_gb, iops_cost = self._price_store.volume_costs( self._region, volume.type) yield AWSVolume(volume.id, volume.size, volume.type, self._region, volume.iops, createdAtUtc, cost_per_gb, iops_cost) def _parse_date_time(self, datetime_str): # example - 2016-01-13T15:42:25.000Z return datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S.%fZ')
def __init__(self, aws_access_key, aws_secret_key, aws_region): self._connection = boto.ec2.connect_to_region( aws_region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) self._region = aws_region self._price_store = AWSPricingStore()
class AWS(object): def __init__(self, aws_access_key, aws_secret_key, aws_region): self._connection = boto.ec2.connect_to_region(aws_region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) self._region = aws_region self._price_store = AWSPricingStore() """Retreives a list of instances :param state one of running, terminated, stopped :returns: AWSInstance """ def instances(self, state="running"): reservations = self._connection.get_all_reservations() for reservation in reservations: for instance in reservation.instances: if instance.state == state: launchedAtUtc = self._parse_date_time(instance.launch_time) cost_per_hour = self._price_store.instance_cost_per_hour(self._region, instance.instance_type) yield AWSInstance(identifier=instance.id, launchedAtUtc=launchedAtUtc, aws_region=self._region, aws_instance_type=instance.instance_type, keyname=instance.key_name, cost_per_hour=cost_per_hour, tags=instance.tags) """Retreives a list of volumes :param state one of running, terminated, stopped :returns: AWSVolume """ def volumes(self): volumes = self._connection.get_all_volumes() for volume in volumes: createdAtUtc = self._parse_date_time(volume.create_time) cost_per_gb, iops_cost = self._price_store.volume_costs(self._region, volume.type) yield AWSVolume(volume.id, volume.size, volume.type, self._region, volume.iops, createdAtUtc, cost_per_gb, iops_cost) def _parse_date_time(self, datetime_str): # example - 2016-01-13T15:42:25.000Z return datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S.%fZ')
def __init__(self, aws_access_key, aws_secret_key, aws_region): self._connection = boto.ec2.connect_to_region(aws_region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) self._region = aws_region self._price_store = AWSPricingStore()