1
1
# -*- coding: utf-8 -*-
2
- import copy
3
2
import logging
4
3
from util import full_stack
5
4
from util import get_credentials_for
6
5
from workflow .steps .util .base import BaseStep
7
- from dbaas_aclapi .acl_base_client import AclClient
8
- from dbaas_credentials .models import CredentialType
9
6
from workflow .exceptions .error_codes import DBAAS_0019
10
7
from dbaas_aclapi .models import DatabaseInfraInstanceBind
8
+ from dbaas_aclapi .acl_base_client import AclClient
9
+ from dbaas_credentials import helpers
10
+ from dbaas_credentials .models import CredentialType
11
11
12
12
13
13
LOG = logging .getLogger (__name__ )
@@ -26,53 +26,25 @@ def undo(self, workflow_dict):
26
26
if 'databaseinfra' not in workflow_dict :
27
27
return False
28
28
29
- action = 'deny'
30
-
31
29
database = workflow_dict ['databaseinfra' ].databases .get ()
32
- for database_bind in database .acl_binds .all ():
33
- acl_environment , acl_vlan = database_bind .bind_address .split (
34
- '/' )
35
- data = {"kind" : "object#acl" , "rules" : []}
36
- default_options = {
37
- "protocol" : "tcp" ,
38
- "source" : "" ,
39
- "destination" : "" ,
40
- "description" : "{} access for database {} in {}" .format (database_bind .bind_address ,
41
- database .name ,
42
- database .environment .name ),
43
- "action" : action ,
44
- "l4-options" : {"dest-port-start" : "" ,
45
- "dest-port-op" : "eq" }
46
- }
30
+ databaseinfra = database .databaseinfra
47
31
48
- LOG .info ("Default options: {}" .format (default_options ))
49
- databaseinfra = database .infra
32
+ acl_credential = get_credentials_for (
33
+ environment = database .environment ,
34
+ credential_type = CredentialType .ACLAPI )
35
+ acl_client = AclClient (
36
+ acl_credential .endpoint , acl_credential .user ,
37
+ acl_credential .password , database .environment )
38
+
39
+ for database_bind in database .acl_binds .all ():
50
40
infra_instances_binds = DatabaseInfraInstanceBind .objects .filter (
51
41
databaseinfra = databaseinfra ,
52
42
bind_address = database_bind .bind_address )
53
-
54
- for infra_instance_bind in infra_instances_binds :
55
- custom_options = copy .deepcopy (default_options )
56
- custom_options ['source' ] = database_bind .bind_address
57
- custom_options [
58
- 'destination' ] = infra_instance_bind .instance + '/32'
59
- custom_options [
60
- 'l4-options' ]['dest-port-start' ] = infra_instance_bind .instance_port
61
- data ['rules' ].append (custom_options )
62
-
63
- acl_credential = get_credentials_for (environment = database .environment ,
64
- credential_type = CredentialType .ACLAPI )
65
- acl_client = AclClient (acl_credential .endpoint ,
66
- acl_credential .user ,
67
- acl_credential .password ,
68
- database .environment )
69
-
70
- LOG .info ("Data used on payload: {}" .format (data ))
71
- acl_client .revoke_acl_for (environment = acl_environment ,
72
- vlan = acl_vlan , payload = data )
73
-
74
- infra_instances_binds .delete ()
75
- database_bind .delete ()
43
+ try :
44
+ helpers .unbind_address (database_bind , acl_client , infra_instances_binds )
45
+ except Exception as e :
46
+ LOG .warn (e )
47
+ continue
76
48
77
49
return True
78
50
except Exception :
0 commit comments