  def AssignExternalIp(
      self, net_if: str, ip_addr: Optional[str] = None) -> None:
    """Assigns an external IP to an instance's network interface.

    The instance must not have an IP assigned to the network interface when
    calling this method. If the IP address is specified, it must be one that
    is available to the project.

    Args:
      net_if (str): The instance's network interface to which the IP address
        must be assigned.
      ip_addr (str): Optional. The static IP address that exposes the network
        interface. If None, the assigned IP address will be ephemeral.

    Raises:
      errors.ResourceCreationError: If the assignment did not succeed.
    """
    body = {}
    if ip_addr is not None:
      body['natIP'] = ip_addr
    instances_client = self.GceApi().instances() # pylint: disable=no-member
    params = {
        'project': self.project_id,
        'zone': self.zone,
        'instance': self.name,
        'networkInterface': net_if,
        'body': body
    }
    try:
      # Safe to unpack, as the response is not paged
      response = common.ExecuteRequest(
          instances_client, 'addAccessConfig', params)[0]
    except HttpError as exception:
      message = 'Unable to assign IP to {0:s}: {1:s}'.format(
          self.name, exception.error_details)
      raise errors.ResourceCreationError(message, __name__) from exception
    self.BlockOperation(response, self.zone)
Assigns an external IP to an instance's network interface.

The instance must not have an IP assigned to the network interface when
calling this method. If the IP address is specified, it must be one that
is available to the project.

Args:
net_if (str): The instance's network interface to which the IP address
must be assigned.
ip_addr (str): Optional. The static IP address that exposes the network
interface. If None, the assigned IP address will be ephemeral.

Raises:
errors.ResourceCreationError: If the assignment did not succeed.
libcloudforensics/providers/gcp/internal/compute.py