awspice package¶
Subpackages¶
Submodules¶
awspice.helpers module¶
-
class
awspice.helpers.
Worker
(tasks)[source]¶ Bases:
threading.Thread
Thread executing tasks from a given tasks queue http://code.activestate.com/recipes/577187-python-thread-pool/
-
__init__
(tasks)[source]¶ This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
-
class
awspice.helpers.
ThreadPool
(num_threads)[source]¶ Bases:
object
Pool of threads consuming tasks from a queue http://code.activestate.com/recipes/577187-python-thread-pool/
-
class
awspice.helpers.
ClsEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder
JSON encoder extension.
Sometimes Boto3 returns a non-serializable result to JSON and we get the following error when dumping that result: TypeError: datetime.datetime (2015, 12, 3, 21, 20, 17, 326000, tzinfo = tzutc ()) is not JSON serializable Solve it using this class encoder in
cls
argumentExamples
json.dumps(results, indent=4, cls=awspice.ClsEncoder)
-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
awspice.helpers.
ip_in_aws
(ip)[source]¶ Check if an IP address is from AWS
Parameters: ip – Address to check Returns: bool
awspice.manager module¶
-
class
awspice.manager.
AwsManager
(region='eu-west-1', profile=None, access_key=None, secret_key=None)[source]¶ Bases:
object
Main class that provides access to services (ec2, s3, vpc …) and modules (finder, stats ..)
This master class provides access to individual services through the “services” property, and also to other complex modules such as “finder”, “stats” and “security”.
-
aws
¶ Object of type #ServiceManager that provides access to the other services.
-
service
¶
-
finder
¶
-
security
¶
-
stats
¶
-
test
()[source]¶ Method to verify that the loaded configuration is correct and access with the AWS API is correct
Returns: boolean. True if the test was successful, false if it failed.
-
__init__
(region='eu-west-1', profile=None, access_key=None, secret_key=None)[source]¶ Initialization and configuration of the client
Parameters: - region (str) – Region in which to make queries and operations.
- profile (str) – Name of the AWS profile set in ~/.aws/credentials file
- access_key (str) – API access key of your AWS account
- secret_key (str) – API secret key of your AWS account
Returns: None
-
awspice.servicemanager module¶
-
class
awspice.servicemanager.
ServiceManager
(region, profile=None, access_key=None, secret_key=None)[source]¶ Bases:
object
Parent class that provides access to services.
For each service (ec2, s3, vpc …) you are given access through a property of this class. This property will return an instance of the corresponding class, for example Ec2Service or VpcService. Each class of service (Ec2Service, S3Service …) inherits from the AwsBase class.
-
ec2
¶
-
elb
¶
-
acm
¶
-
iam
¶
-
rds
¶
-
s3
¶
-
ce
¶
-
route53
¶
-
classmethod
get_auth_config
()[source]¶ Get the configuration of the client currently configured
This method allows us to work with multiple accounts and different authentication methods (keys and profiles) without getting lost.
Returns: A dictionary with the type of authentication used and the associated value. The secret_key is not returned for security reasons. {‘Authorization’: {‘Type’: ‘Profile’, ‘Value’: ‘MyBoringCompany’}}
-
__init__
(region, profile=None, access_key=None, secret_key=None)[source]¶ Constructor of the parent class of the services.
With this method you can modify the configuration of the awspice client. It allows us to change the profile, the region or the access codes.
Parameters: - region (str) – Region in which to make queries and operations.
- profile (str) – Name of the AWS profile set in ~/.aws/credentials file
- access_key (str) – API access key of your AWS account
- secret_key (str) – API secret key of your AWS account
-