def __init__(self, name, region, vpc, description, inbound=None, outbound=None): """ :param name: String, name of SG :param region: String, AWS region :param vpc: String, IP of the VPC this SG belongs to :param description: String :param inbound: List of dicts, IP Permissions that should exist :param outbound: List of dicts, IP Permissions that should exist """ self.id = None self.name = name self.region = region self.vpc = vpc self.description = description self.IpPermissions = [] self.IpPermissionsEgress = [] self.owner = None self.changed = False try: self._get() except AWSNotFound: self._create() self._merge_rules(must.be_list(inbound), self.IpPermissions) self._merge_rules(must.be_list(outbound), self.IpPermissionsEgress, egress=True) if self.changed: self._get()
def __init__(self, name, region, kind, subnets, groups): self.id = None self.targets = None self.name = name self.token = str(uuid.uuid5(uuid.NAMESPACE_URL, self.name)) self.region = region self.kind = kind # generalPurpose | maxIO self.subnets = must.be_list(subnets) self.groups = must.be_list(groups) if not self._get(): self._create() self._mounts()
def __init__(self, name, region, vpc, image, key, count, size, groups, zone=None, public=True, script=None): self.name = name self.region = region self.vpc = vpc self.image = image self.key = key self.count = must.be_int(count) self.deficit = 0 # Should always be negative inventory (requested - running) self.size = size # --instance-type self.groups = must.be_list(groups) # --security-group-ids self.id = set() self.subnets = set() self.public_ips = set() self.private_ips = set() self.public = public self.script = script self.zones = set() self.zone = zone # AZ to use during _create() if not self._get(): self._create() self._get()
def __init__(self, name, region, listeners, instances=None, subnets=None, zones=None, groups=None, scheme=None): """ :param name: String, name of LB :param region: String, AWS region :param listeners: list() of Listeners, funct make_listener() can help with formatting :param subnets: list() of Subnets :param zones: list() of Availability Zones :param groups: list() of Security Group IDs :param scheme: String or None. Can be 'internal', otherwise LB is Internet-facing """ self.dns = None self.name = name self.region = region self.listeners = [] self.subnets = subnets self.zones = [] self.groups = [] self.scheme = None self.vpc = None self.instances = [] instances = must.be_list(instances) listeners = must.be_list(listeners) groups = must.be_list(groups) zones = must.be_list(zones) try: self._get() except AWSNotFound: self._create(zones, groups, scheme, listeners) if self.groups != groups: self._groups(groups) merge_elements(listeners, self.listeners, self._add_listener, self._rm_listener) merge_elements(zones, self.zones, self._add_zone, self._rm_zone, add_first=True) merge_elements(instances, self.instances, self._add_instance, self._rm_instance)
def _rm_instance(self, instances): instances = must.be_list(instances) command = [ 'elb', 'deregister-instances-from-load-balancer', '--region', self.region, '--load-balancer-name', self.name, '--instances' ] command.extend(instances) bin_aws(command) for this in instances: if this in self.instances: self.instances.remove(this) print('Deregistered {0}'.format(command)) # TODO: Log(...) return True
def _add_instance(self, instances): instances = must.be_list(instances) command = [ 'elb', 'register-instances-with-load-balancer', '--region', self.region, '--load-balancer-name', self.name, '--instances' ] command.extend(instances) bin_aws(command) for this in instances: if this not in self.instances: self.instances.append(this) print('Registered {0}'.format(command)) # TODO: Log(...) return True