Completed
Pull Request — master (#395)
by
unknown
01:42
created

DatabaseRdsSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %
Metric Value
dl 0
loc 34
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _id_generator() 0 3 1
B run() 0 24 1
A _user_name() 0 4 1
1
import re
2
import uuid
3
from st2actions.runners.pythonrunner import Action
4
5
6
class DatabaseRdsSpec(Action):
7
    def run(self, payload):
8
        # For dbidentifier
9
        db_name = re.sub('[^0-9a-zA-Z]+', '-', payload['name']) + "-" + payload['namespace']
10
11
        # Lets get a username generated
12
        user_name = self._user_name(uid=payload['uid'])
13
        # Lets get a password randomly generated
14
        pw = self._id_generator()
15
        instance_class = 'db.m3.xlarge'
16
        port = '3306'
17
        rds_engine = 'mysql'
18
        allocated_storage = '50'
19
20
        payload = {
21
            'db_name': db_name,
22
            'user_name': user_name,
23
            'pw': pw,
24
            'instance_class': instance_class,
25
            'port': port,
26
            'rds_engine': rds_engine,
27
            'allocated_storage': allocated_storage,
28
        }
29
30
        return payload
31
32
    def _user_name(self, uid):
33
        short_uid = uid[0:7]
34
        return "db_" + short_uid
35
        pass
36
37
    def _id_generator(self):
38
        return uuid.uuid4().hex
39
        pass
40