def CreateNetworkResourceFromArgs(messages, network_ref, network_args):
  """Creates a new network resource from flag arguments."""

  network = messages.Network(
      name=network_ref.Name(),
      description=network_args.description)

  if network_args.subnet_mode == 'LEGACY':
    network.IPv4Range = network_args.range
  else:
    network.autoCreateSubnetworks = (network_args.subnet_mode == 'AUTO')

  if network_args.bgp_routing_mode:
    network.routingConfig = messages.NetworkRoutingConfig()
    network.routingConfig.routingMode = (messages.NetworkRoutingConfig.
                                         RoutingModeValueValuesEnum(
                                             network_args.bgp_routing_mode))

  return network