mirror of https://github.com/apache/cloudstack.git
marvin_refactor: security group splits into ingress/egress
@also Include the apiclient as part of the factory instantiation so there is not redundant parameter when dealing with the object after it is generated by the factory. Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
parent
ec09163ffd
commit
2bb1533a8e
|
|
@ -103,14 +103,32 @@ class Entity(object):
|
|||
#TODO: doc to explain what possible args go into **kwargs
|
||||
m.docstring = 'Placeholder for docstring\n' + 'optional arguments (**kwargs): [%s]"""' % ', '.join(
|
||||
details['optionals'])
|
||||
if not m.is_creator():
|
||||
# remove the id arg as id is the self (object) itself
|
||||
no_id_args = filter(lambda arg: arg != 'id', details['args'])
|
||||
# remove the id arg as id is the self (object) itself
|
||||
no_id_args = filter(lambda arg: arg != 'id', details['args'])
|
||||
if m.is_enumerator():
|
||||
m.signature = 'def %s(cls, apiclient=None, **kwargs):' % (action)
|
||||
m.body.append(self.tabspace + 'cmd = %(module)s.%(command)s()' % {"module": details["apimodule"],
|
||||
"command": details["apicmd"]})
|
||||
m.body.append(self.tabspace + '[setattr(cmd, key, value) for key, value in kwargs.iteritems()]')
|
||||
m.body.append(self.tabspace + 'if apiclient:')
|
||||
m.body.append(self.tabspace*2 + '%s = apiclient.%s(cmd)' % (entity.lower(), details['apimodule']))
|
||||
m.body.append(self.tabspace + 'else:')
|
||||
m.body.append(self.tabspace*2 + '%s = cls.apiclient.%s(cmd)' % (entity.lower(), details['apimodule']))
|
||||
m.body.append(self.tabspace + '%s = map(lambda e: %s().__update__(e.__dict__), %s) '
|
||||
'if %s and len(%s) > 0 else None' % ( entity.lower(),
|
||||
entity, entity.lower(),
|
||||
entity.lower(), entity.lower()))
|
||||
m.body.append(
|
||||
self.tabspace + '%s = map(lambda e: e.__update__({\'apiclient\': apiclient if apiclient else cls.apiclient}), %s) if %s else None' % (
|
||||
entity.lower(), entity.lower(), entity.lower())
|
||||
)
|
||||
m.body.append(self.tabspace + 'return %s' % entity.lower())
|
||||
elif not m.is_creator():
|
||||
if len(no_id_args) > 0: # at least one required non-id argument
|
||||
m.signature = 'def %s(self, apiclient, %s, **kwargs):'\
|
||||
m.signature = 'def %s(self, %s, **kwargs):'\
|
||||
% (action, ', '.join(list(set(no_id_args))))
|
||||
else:
|
||||
m.signature = 'def %s(self, apiclient, **kwargs):' % (action)
|
||||
m.signature = 'def %s(self, **kwargs):' % (action)
|
||||
m.body.append(self.tabspace + 'cmd = %(module)s.%(command)s()' % {"module": details["apimodule"],
|
||||
"command": details["apicmd"]})
|
||||
if 'id' in details['args']:
|
||||
|
|
@ -118,7 +136,7 @@ class Entity(object):
|
|||
for arg in no_id_args:
|
||||
m.body.append(self.tabspace + 'cmd.%s = %s' % (arg, arg))
|
||||
m.body.append(self.tabspace + '[setattr(cmd, key, value) for key, value in kwargs.iteritems()]')
|
||||
m.body.append(self.tabspace + '%s = apiclient.%s(cmd)' % (entity.lower(), details['apimodule']))
|
||||
m.body.append(self.tabspace + '%s = self.apiclient.%s(cmd)' % (entity.lower(), details['apimodule']))
|
||||
if m.is_enumerator():
|
||||
m.body.append(self.tabspace +
|
||||
'return map(lambda e: %s().__update__(e.__dict__), %s) '
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ def transform_api(api):
|
|||
return 'login', 'CloudStack'
|
||||
elif api == 'logout':
|
||||
return 'logout', 'CloudStack'
|
||||
elif api == 'authorizeSecurityGroupIngress':
|
||||
return 'authorizeSecurityGroupIngress', 'SecurityGroup'
|
||||
elif api == 'authorizeSecurityGroupEgress':
|
||||
return 'authorizeSecurityGroupEgress', 'SecurityGroup'
|
||||
elif api == 'revokeSecurityGroupIngress':
|
||||
return 'revokeSecurityGroupIngress', 'SecurityGroup'
|
||||
elif api == 'revokeSecurityGroupEgress':
|
||||
return 'revokeSecurityGroupEgress', 'SecurityGroup'
|
||||
return api, None
|
||||
|
||||
def verb_adjust(api, entity):
|
||||
|
|
@ -89,6 +97,8 @@ def entity_adjust(entity):
|
|||
return 'UserKeys'
|
||||
elif entity == 'FirewallRule':
|
||||
return 'Firewall'
|
||||
elif entity == 'SecurityGroupRule':
|
||||
return 'SecurityGroup'
|
||||
#Cloudstack maintains Template/ISO/Volume as single Image type
|
||||
#elif entity in ['Template', 'Volume']:
|
||||
# return 'Image'
|
||||
|
|
|
|||
Loading…
Reference in New Issue