def _parse_allow(allow):
 seen_protos = {}
 allow_dict = []
 protocols = allow.split(',')
 for p in protocols:
  pairs = p.split(':')
  if (pairs[0].lower() not in ['tcp', 'udp', 'icmp']):
   raise SaltCloudSystemExit('Unsupported protocol {0}. Must be tcp, udp, or icmp.'.format(pairs[0]))
  if ((len(pairs) == 1) or (pairs[0].lower() == 'icmp')):
   seen_protos[pairs[0]] = []
  elif (pairs[0] not in seen_protos):
   seen_protos[pairs[0]] = [pairs[1]]
  else:
   seen_protos[pairs[0]].append(pairs[1])
 for k in seen_protos:
  d = {'IPProtocol': k}
  if (len(seen_protos[k]) > 0):
   d['ports'] = seen_protos[k]
  allow_dict.append(d)
 log.debug('firewall allowed protocols/ports: {0}'.format(allow_dict))
 return allow_dict

def _parse_allow ( allow ) : seen_protos = { } allow_dict = [ ] protocols = allow . split ( ',' ) for p in protocols : pairs = p . split ( ':' ) if ( pairs [ 0 ] . lower ( ) not in [ 'tcp' , 'udp' , 'icmp' ] ) : raise SaltCloudSystemExit ( 'Unsupported protocol {0}. Must be tcp, udp, or icmp.' . format ( pairs [ 0 ] ) ) if ( ( len ( pairs ) == 1 ) or ( pairs [ 0 ] . lower ( ) == 'icmp' ) ) : seen_protos [ pairs [ 0 ] ] = [ ] elif ( pairs [ 0 ] not in seen_protos ) : seen_protos [ pairs [ 0 ] ] = [ pairs [ 1 ] ] else : seen_protos [ pairs [ 0 ] ] . append ( pairs [ 1 ] ) for k in seen_protos : d = { 'IPProtocol' : k } if ( len ( seen_protos [ k ] ) > 0 ) : d [ 'ports' ] = seen_protos [ k ] allow_dict . append ( d ) log . debug ( 'firewall allowed protocols/ports: {0}' . format ( allow_dict ) ) return allow_dict
convert firewall rule allowed user-string to specified rest api format .