Exemplo n.º 1
0
    def new(cls, name, namespace, netblock, provide_dhcp=False,
            provide_nat=False, uuid=None, vxid=None):

        if not uuid:
            # uuid should only be specified in testing
            uuid = str(uuid4())

        if not vxid:
            vxid = Network.allocate_vxid(uuid)

        # Pre-create the IPManager
        IPManager.new(uuid, netblock)

        Network._db_create(
            uuid,
            {
                'vxid': vxid,
                'name': name,
                'namespace': namespace,
                'netblock': netblock,
                'provide_dhcp': provide_dhcp,
                'provide_nat': provide_nat,
                'version': cls.current_version
            }
        )

        n = Network.from_db(uuid)
        n.state = Network.STATE_INITIAL

        # Networks should immediately appear on the network node
        etcd.enqueue('networknode', DeployNetworkTask(uuid))

        # TODO(andy): Integrate metadata into each object type
        # Initialise metadata
        db.persist_metadata('network', uuid, {})

        return n
Exemplo n.º 2
0
 def test_new(self, mock_persist, mock_lock, mock_time):
     ipm = IPManager.new('uuid', '192.168.1.0/24')
     self.assertEqual(
         {
             '192.168.1.0': {
                 'user': ('ipmanager', 'uuid'),
                 'when': 1632261535.027476
             },
             '192.168.1.255': {
                 'user': ('ipmanager', 'uuid'),
                 'when': 1632261535.027476
             },
             '192.168.1.1': {
                 'user': ('ipmanager', 'uuid'),
                 'when': 1632261535.027476
             }
         }, ipm.in_use)