Completed
Pull Request — master (#395)
by
unknown
01:49
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 base64
2
import json
3
import yaml
4
import os, sys
5
import re
6
import pprint
7
import uuid
8
from st2actions.runners.pythonrunner import Action
9
10
class DatabaseRdsSpec(Action):
11
    def run(self, payload):
12
        # For dbidentifier
13
        db_name = re.sub('[^0-9a-zA-Z]+', '-', payload['name']) + "-" + payload['namespace']
14
15
        #Lets get a username generated
16
        user_name = self._user_name(uid=payload['uid'])
17
        # Lets get a password randomly generated
18
        pw = self._id_generator()
19
        instance_class = 'db.m3.xlarge'
20
        port = '3306'
21
        rds_engine = 'mysql'
22
        allocated_storage = '50'
23
24
        payload = {
25
            'db_name': db_name,
26
            'user_name': user_name,
27
            'pw': pw,
28
            'instance_class': instance_class,
29
            'port': port,
30
            'rds_engine': rds_engine,
31
            'allocated_storage': allocated_storage,
32
        }
33
34
        return payload
35
36
    def _user_name(self, uid):
37
        short_uid = uid[0:7]
38
        return "db_" + short_uid
39
        pass
40
41
    def _id_generator(self):
42
        return uuid.uuid4().hex
43
        pass
44