
from nova import manager
from nova.network import driver


class MetadataManager(manager.Manager):
    """Metadata Manager.

    This class manages the Metadata API service initialization. Currently, it
    just adds an iptables filter rule for the metadata service.
    """
    def __init__(self, *args, **kwargs):
        super(MetadataManager, self).__init__(*args, **kwargs)
        self.network_driver = driver.load_network_driver()

    def init_host(self):
        """Perform any initialization.

        Currently, we only add an iptables filter rule for the metadata
        service.
        """
        self.network_driver.metadata_accept()


from nova import manager
from nova.network import driver


class MetadataManager(manager.Manager):
    """Metadata Manager.

    This class manages the Metadata API service initialization. Currently, it
    just adds an iptables filter rule for the metadata service.
    """
    def __init__(self, *args, **kwargs):
        super(MetadataManager, self).__init__(*args, **kwargs)
        self.network_driver = driver.load_network_driver()
        self.network_driver.metadata_accept()

Initialize iptables rules on initialization of MetadataManager
Initialize iptables rules on initialization of MetadataManager

To avoid multiple initialization of iptables rules if there are a few
workers for metadata service, perform iptables configuration in
__init__() of MetadataManager.

Change-Id: I674c04f973318f06cbb98693f0a884c824af8748
Closes-Bug: #1097999

  
  from nova import manager
  from nova.network import driver
  
  
  class MetadataManager(manager.Manager):
      """Metadata Manager.
  
      This class manages the Metadata API service initialization. Currently, it
      just adds an iptables filter rule for the metadata service.
      """
      def __init__(self, *args, **kwargs):
          super(MetadataManager, self).__init__(*args, **kwargs)
          self.network_driver = driver.load_network_driver()
- 
-     def init_host(self):
-         """Perform any initialization.
- 
-         Currently, we only add an iptables filter rule for the metadata
-         service.
-         """
          self.network_driver.metadata_accept()
  
Initialize iptables rules on initialization of MetadataManager
## Code Before:

from nova import manager
from nova.network import driver


class MetadataManager(manager.Manager):
    """Metadata Manager.

    This class manages the Metadata API service initialization. Currently, it
    just adds an iptables filter rule for the metadata service.
    """
    def __init__(self, *args, **kwargs):
        super(MetadataManager, self).__init__(*args, **kwargs)
        self.network_driver = driver.load_network_driver()

    def init_host(self):
        """Perform any initialization.

        Currently, we only add an iptables filter rule for the metadata
        service.
        """
        self.network_driver.metadata_accept()

## Instruction:
Initialize iptables rules on initialization of MetadataManager
## Code After:

from nova import manager
from nova.network import driver


class MetadataManager(manager.Manager):
    """Metadata Manager.

    This class manages the Metadata API service initialization. Currently, it
    just adds an iptables filter rule for the metadata service.
    """
    def __init__(self, *args, **kwargs):
        super(MetadataManager, self).__init__(*args, **kwargs)
        self.network_driver = driver.load_network_driver()
        self.network_driver.metadata_accept()
