Esempio n. 1
0
    def _reconfigure_port_group(self, pg_moref, spec_update_calback,
                                spec_update_data):
        # Get the current configuration of the port group
        pg_spec = self._session.invoke_api(vim_util, 'get_object_properties',
                                           self._session.vim, pg_moref,
                                           ['config'])
        if len(pg_spec) == 0 or len(pg_spec[0].propSet[0]) == 0:
            LOG.error('Failed to get object properties of %s', pg_moref)
            raise nsx_exc.DvsNotFound(dvs=pg_moref)

        # Convert the extracted config to DVPortgroupConfigSpec
        new_spec = self._copy_port_group_spec(pg_spec[0].propSet[0].val)

        # Update the configuration using the callback & data
        spec_update_calback(new_spec, spec_update_data)

        # Update the port group configuration
        task = self._session.invoke_api(self._session.vim,
                                        'ReconfigureDVPortgroup_Task',
                                        pg_moref,
                                        spec=new_spec)
        try:
            self._session.wait_for_task(task)
        except Exception:
            LOG.error('Failed to reconfigure DVPortGroup %s', pg_moref)
            raise nsx_exc.DvsNotFound(dvs=pg_moref)
Esempio n. 2
0
 def _get_dvs_moref_by_name(self, session, dvs_name):
     """Get the moref of the configured DVS."""
     results = session.invoke_api(vim_util, 'get_objects', session.vim,
                                  'DistributedVirtualSwitch', 100)
     while results:
         for dvs in results.objects:
             for prop in dvs.propSet:
                 if dvs_name == prop.val:
                     vim_util.cancel_retrieval(session.vim, results)
                     return dvs.obj
         results = vim_util.continue_retrieval(session.vim, results)
     raise nsx_exc.DvsNotFound(dvs=dvs_name)