def build_dev_from_opts(opts):
 for (attribute, shortopt, longopt) in (['region', '-r', '--region'], ['zone', '-z', '--zone'], ['ip', '-i', '--ip'], ['port', '-p', '--port'], ['device', '-d', '--device'], ['weight', '-w', '--weight']):
  if (getattr(opts, attribute, None) is None):
   raise ValueError(('Required argument %s/%s not specified.' % (shortopt, longopt)))
 ip = validate_and_normalize_address(opts.ip)
 replication_ip = validate_and_normalize_address((opts.replication_ip or opts.ip))
 replication_port = (opts.replication_port or opts.port)
 if (not validate_device_name(opts.device)):
  raise ValueError('Invalid device name')
 return {'region': opts.region, 'zone': opts.zone, 'ip': ip, 'port': opts.port, 'device': opts.device, 'meta': opts.meta, 'replication_ip': replication_ip, 'replication_port': replication_port, 'weight': opts.weight}

def build_dev_from_opts ( opts ) : for ( attribute , shortopt , longopt ) in ( [ 'region' , '-r' , '--region' ] , [ 'zone' , '-z' , '--zone' ] , [ 'ip' , '-i' , '--ip' ] , [ 'port' , '-p' , '--port' ] , [ 'device' , '-d' , '--device' ] , [ 'weight' , '-w' , '--weight' ] ) : if ( getattr ( opts , attribute , None ) is None ) : raise ValueError ( ( 'Required argument %s/%s not specified.' % ( shortopt , longopt ) ) ) ip = validate_and_normalize_address ( opts . ip ) replication_ip = validate_and_normalize_address ( ( opts . replication_ip or opts . ip ) ) replication_port = ( opts . replication_port or opts . port ) if ( not validate_device_name ( opts . device ) ) : raise ValueError ( 'Invalid device name' ) return { 'region' : opts . region , 'zone' : opts . zone , 'ip' : ip , 'port' : opts . port , 'device' : opts . device , 'meta' : opts . meta , 'replication_ip' : replication_ip , 'replication_port' : replication_port , 'weight' : opts . weight }
convert optparse stype options into a device dictionary .