def book_port(self, network, port_name, segment, net_name=None):
        try:
            if not net_name:
                net_name = self._get_net_name(network)
            pg = self._get_or_create_pg(net_name, network, segment)
            for iter in range(0, 4):
                try:
                    port_info = self._lookup_unbound_port_or_increase_pg(pg)

                    port_settings = self.builder.port_setting()
                    port_settings.blocked = self.builder.blocked(False)
                    update_spec = self.builder.port_config_spec(
                        port_info.config.configVersion,
                        port_settings,
                        name=port_name)
                    update_spec.key = port_info.key
                    update_task = self.connection.invoke_api(
                        self.connection.vim,
                        'ReconfigureDVPort_Task',
                        self._dvs,
                        port=[update_spec])
                    self.connection.wait_for_task(update_task)
                    return port_info.key
                except vmware_exceptions.VimException as e:
                    sleep(0.1)
            raise exceptions.wrap_wmvare_vim_exception(e)
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #2
0
    def book_port(self, network, port_name, segment, net_name=None):
        try:
            if not net_name:
                net_name = self._get_net_name(network)
            pg = self._get_or_create_pg(net_name, network, segment)
            for iter in range(0, 4):
                try:
                    port_info = self._lookup_unbound_port_or_increase_pg(pg)

                    port_settings = self.builder.port_setting()
                    port_settings.blocked = self.builder.blocked(False)
                    update_spec = self.builder.port_config_spec(
                        port_info.config.configVersion, port_settings,
                        name=port_name)
                    update_spec.key = port_info.key
                    update_task = self.connection.invoke_api(
                        self.connection.vim, 'ReconfigureDVPort_Task',
                        self._dvs, port=[update_spec])
                    self.connection.wait_for_task(update_task)
                    return {'key': port_info.key,
                            'dvs_uuid': self._dvs_uuid,
                            'pg_key': pg.value}
                except vmware_exceptions.VimException as e:
                    sleep(0.1)
            raise exceptions.wrap_wmvare_vim_exception(e)
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
def update_port_rules(dvs, ports):
    try:
        builder = dvs_util.SpecBuilder(dvs.connection.vim.client.factory)
        port_config_list = []
        for port in ports:
            try:
                if port['binding:vif_details'].get('dvs_port_key') is not None:
                    port_info = dvs._get_port_info_by_portkey(
                        port['binding:vif_details']['dvs_port_key'])
                else:
                    port_info = dvs.get_port_info_by_name(port['id'])
            except exceptions.PortNotFound:
                LOG.warning(_LW("Port %s was not found. Security rules "
                                "can not be applied."), port['id'])
                continue

            port_config = port_configuration(builder,
                                             str(port_info['key']),
                                             port['security_group_rules'])
            port_config.configVersion = port_info['config']['configVersion']
            port_config_list.append(port_config)
        if port_config_list:
            task = dvs.connection.invoke_api(
                dvs.connection.vim,
                'ReconfigureDVPort_Task',
                dvs._dvs,
                port=port_config_list
            )
            return dvs.connection.wait_for_task(task)
    except vmware_exceptions.VimException as e:
        raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #4
0
 def book_port(self, network, port_name, segment):
     try:
         net_name = self._get_net_name(self.dvs_name, network)
         pg = self._get_or_create_pg(net_name, network, segment)
         while True:
             try:
                 port_info = self._lookup_unbound_port(pg)
                 break
             except exceptions.UnboundPortNotFound:
                 try:
                     self._increase_ports_on_portgroup(pg)
                 except (vmware_exceptions.VMwareDriverException,
                         exceptions.VMWareDVSException) as e:
                     if dvs_const.CONCURRENT_MODIFICATION_TEXT in e.message:
                         LOG.info(_LI('Concurent modification on '
                                      'increase port group.'))
                         continue
         builder = SpecBuilder(self.connection.vim.client.factory)
         port_settings = builder.port_setting()
         port_settings.blocked = builder.blocked(False)
         update_spec = builder.port_config_spec(
             port_info.config.configVersion, port_settings, name=port_name)
         update_spec.key = port_info.key
         update_task = self.connection.invoke_api(
             self.connection.vim, 'ReconfigureDVPort_Task',
             self._dvs, port=[update_spec])
         self.connection.wait_for_task(update_task)
         return port_info.key
     except vmware_exceptions.VimException as e:
         raise exceptions.wrap_wmvare_vim_exception(e)
    def update_network(self, network, original=None):
        original_name = self._get_net_name(original) if original else None
        current_name = self._get_net_name(network)
        blocked = not network['admin_state_up']
        try:
            pg_ref = self._get_pg_by_name(original_name or current_name)
            pg_config_info = self._get_config_by_ref(pg_ref)
            if (pg_config_info.defaultPortConfig.blocked.value != blocked
                    or (original_name and original_name != current_name)):
                # we upgrade only defaultPortConfig, because it is inherited
                # by all ports in PortGroup, unless they are explicit
                # overwritten on specific port.
                pg_spec = self._build_pg_update_spec(
                    pg_config_info.configVersion, blocked=blocked)
                pg_spec.name = current_name
                pg_update_task = self.connection.invoke_api(
                    self.connection.vim,
                    'ReconfigureDVPortgroup_Task',
                    pg_ref,
                    spec=pg_spec)

                self.connection.wait_for_task(pg_update_task)
                LOG.info(_LI('Network %(name)s updated'),
                         {'name': current_name})
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
 def _delete_port_group(self, pg_ref, name):
     remove_used_pg_try = 0
     while True:
         try:
             pg_delete_task = self.connection.invoke_api(
                 self.connection.vim, 'Destroy_Task', pg_ref)
             self.connection.wait_for_task(pg_delete_task)
             LOG.info(_LI('Network %(name)s deleted.') % {'name': name})
             break
         except vmware_exceptions.VimException as e:
             if dvs_const.RESOURCE_IN_USE in e.message:
                 remove_used_pg_try += 1
                 if remove_used_pg_try > 3:
                     LOG.info(
                         _LI('Network %(name)s was not deleted. Active'
                             ' ports were found') % {'name': name})
                     break
                 else:
                     sleep(0.2)
             else:
                 raise exceptions.wrap_wmvare_vim_exception(e)
         except vmware_exceptions.VMwareDriverException as e:
             if dvs_const.DELETED_TEXT in e.message:
                 sleep(0.1)
             else:
                 raise
Beispiel #7
0
    def update_network(self, network, original=None):
        original_name = self._get_net_name(original) if original else None
        current_name = self._get_net_name(network)
        blocked = not network['admin_state_up']
        try:
            pg_ref = self._get_pg_by_name(original_name or current_name)
            pg_config_info = self._get_config_by_ref(pg_ref)
            if (pg_config_info.defaultPortConfig.blocked.value != blocked or
                    (original_name and original_name != current_name)):
                # we upgrade only defaultPortConfig, because it is inherited
                # by all ports in PortGroup, unless they are explicit
                # overwritten on specific port.
                pg_spec = self._build_pg_update_spec(
                    pg_config_info.configVersion,
                    blocked=blocked)
                pg_spec.name = current_name
                pg_update_task = self.connection.invoke_api(
                    self.connection.vim,
                    'ReconfigureDVPortgroup_Task',
                    pg_ref, spec=pg_spec)

                self.connection.wait_for_task(pg_update_task)
                LOG.info(_LI('Network %(name)s updated'),
                         {'name': current_name})
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
    def create_network(self, network, segment):
        name = self._get_net_name(network)
        blocked = not network['admin_state_up']
        if network['provider:physical_network'] in self.uplink_map:
            uplinks = self.uplink_map[network['provider:physical_network']]
        else:
            uplinks = None
        try:
            pg_spec = self._build_pg_create_spec(
                name,
                segment['segmentation_id'],
                blocked, uplinks)
            pg_create_task = self.connection.invoke_api(
                self.connection.vim,
                'CreateDVPortgroup_Task',
                self._dvs, spec=pg_spec)

            result = self.connection.wait_for_task(pg_create_task)
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
        else:
            pg = result.result
            LOG.info(_LI('Network %(name)s created \n%(pg_ref)s'),
                     {'name': name, 'pg_ref': pg})
            return pg
Beispiel #9
0
 def _delete_port_group(self, pg_ref, name):
     remove_used_pg_try = 0
     while True:
         try:
             pg_delete_task = self.connection.invoke_api(
                 self.connection.vim,
                 'Destroy_Task',
                 pg_ref)
             self.connection.wait_for_task(pg_delete_task)
             LOG.info(_LI('Network %(name)s deleted.'), {'name': name})
             break
         except vmware_exceptions.VimException as e:
             if dvs_const.RESOURCE_IN_USE in e.message:
                 remove_used_pg_try += 1
                 if remove_used_pg_try > 3:
                     LOG.info(_LI('Network %(name)s was not deleted. Active'
                                  ' ports were found'), {'name': name})
                     break
                 else:
                     sleep(0.2)
             else:
                 raise exceptions.wrap_wmvare_vim_exception(e)
         except vmware_exceptions.VMwareDriverException as e:
             if dvs_const.DELETED_TEXT in e.message:
                 sleep(0.1)
             else:
                 raise
Beispiel #10
0
 def __init__(self, dvs_name, connection):
     self.connection = connection
     try:
         self.dvs_name = dvs_name
         self._dvs, self._datacenter = self._get_dvs(dvs_name, connection)
         # (SlOPS) To do release blocked port after use
         self._blocked_ports = set()
     except vmware_exceptions.VimException as e:
         raise exceptions.wrap_wmvare_vim_exception(e)
 def __init__(self, dvs_name, connection):
     self.connection = connection
     self.dvs_name = dvs_name
     self._blocked_ports = set()
     self.builder = spec_builder.SpecBuilder(
         self.connection.vim.client.factory)
     self.uplink_map = {}
     try:
         self._dvs, self._datacenter = self._get_dvs(dvs_name, connection)
     except vmware_exceptions.VimException as e:
         raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #12
0
 def __init__(self, dvs_name, connection):
     self.connection = connection
     self.dvs_name = dvs_name
     self._blocked_ports = set()
     self.builder = spec_builder.SpecBuilder(
         self.connection.vim.client.factory)
     self.uplink_map = {}
     try:
         self._dvs, self._datacenter = self._get_dvs(dvs_name, connection)
     except vmware_exceptions.VimException as e:
         raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #13
0
 def release_port(self, port):
     try:
         port_info = self.get_port_info(port)
         update_spec = self.builder.port_config_spec(
             port_info.config.configVersion, name='')
         update_spec.key = port_info.key
         update_spec.operation = 'remove'
         self.connection.invoke_api(
             self.connection.vim, 'ReconfigureDVPort_Task',
             self._dvs, port=[update_spec])
         self.remove_block(port_info.key)
     except exceptions.PortNotFound:
         LOG.debug("Port %s was not found. Nothing to delete.", port['id'])
     except vmware_exceptions.VimException as e:
         if dvs_const.RESOURCE_IN_USE in e.message:
             LOG.debug("Port %s in use, couldn't be deleted.", port['id'])
         else:
             raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #14
0
    def switch_port_blocked_state(self, port):
        try:
            port_info = self.get_port_info(port)
            port_settings = self.builder.port_setting()
            state = not port['admin_state_up']
            port_settings.blocked = self.builder.blocked(state)

            update_spec = self.builder.port_config_spec(
                port_info.config.configVersion, port_settings)
            update_spec.key = port_info.key
            update_task = self.connection.invoke_api(
                self.connection.vim, 'ReconfigureDVPort_Task',
                self._dvs, port=[update_spec])
            self.connection.wait_for_task(update_task)
        except exceptions.PortNotFound:
            LOG.debug("Port %s was not found. Nothing to block.", port['id'])
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #15
0
    def switch_port_blocked_state(self, port):
        try:
            port_info = self.get_port_info(port)
            port_settings = self.builder.port_setting()
            state = not port['admin_state_up']
            port_settings.blocked = self.builder.blocked(state)

            update_spec = self.builder.port_config_spec(
                port_info.config.configVersion, port_settings)
            update_spec.key = port_info.key
            update_task = self.connection.invoke_api(self.connection.vim,
                                                     'ReconfigureDVPort_Task',
                                                     self._dvs,
                                                     port=[update_spec])
            self.connection.wait_for_task(update_task)
        except exceptions.PortNotFound:
            LOG.debug("Port %s was not found. Nothing to block." % port['id'])
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #16
0
 def release_port(self, port):
     try:
         port_info = self.get_port_info(port)
         update_spec = self.builder.port_config_spec(
             port_info.config.configVersion, name='')
         update_spec.key = port_info.key
         update_spec.operation = 'remove'
         self.connection.invoke_api(self.connection.vim,
                                    'ReconfigureDVPort_Task',
                                    self._dvs,
                                    port=[update_spec])
         self.remove_block(port_info.key)
     except exceptions.PortNotFound:
         LOG.debug("Port %s was not found. Nothing to delete.", port['id'])
     except vmware_exceptions.VimException as e:
         if dvs_const.RESOURCE_IN_USE in e.message:
             LOG.debug("Port %s in use, couldn't be deleted.", port['id'])
         else:
             raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #17
0
 def delete_network(self, network):
     name = self._get_net_name(self.dvs_name, network)
     while True:
         try:
             pg_ref = self._get_pg_by_name(name)
             pg_delete_task = self.connection.invoke_api(
                 self.connection.vim,
                 'Destroy_Task',
                 pg_ref)
             self.connection.wait_for_task(pg_delete_task)
             LOG.info(_LI('Network %(name)s deleted.') % {'name': name})
             break
         except exceptions.PortGroupNotFound:
             LOG.debug('Network %s not present in vcenter.' % name)
             break
         except vmware_exceptions.VimException as e:
             raise exceptions.wrap_wmvare_vim_exception(e)
         except vmware_exceptions.VMwareDriverException as e:
             if dvs_const.DELETED_TEXT in e.message:
                 sleep(1)
             else:
                 raise
Beispiel #18
0
def update_port_rules(dvs, ports):
    try:
        builder = PortConfigSpecBuilder(dvs.connection.vim.client.factory)
        port_config_list = []
        hashed_rules = {}
        for port in ports:
            key = port.get('binding:vif_details', {}).get('dvs_port_key')
            if key:
                port_config = port_configuration(builder, key,
                                                 port['security_group_rules'],
                                                 hashed_rules)
                port_config_list.append(port_config)
        if port_config_list:
            task = dvs.connection.invoke_api(dvs.connection.vim,
                                             'ReconfigureDVPort_Task',
                                             dvs._dvs,
                                             port=port_config_list)
            dvs.connection.wait_for_task(task)
    except vmware_exceptions.VimException as e:
        if 'The object or item referred to could not be found' in str(e):
            pass
        else:
            raise exceptions.wrap_wmvare_vim_exception(e)
Beispiel #19
0
    def create_network(self, network, segment):
        name = self._get_net_name(network)
        blocked = not network['admin_state_up']
        uplinks = self.uplink_map.get(network['provider:physical_network'])
        try:
            pg_spec = self._build_pg_create_spec(name,
                                                 segment['segmentation_id'],
                                                 blocked, uplinks)
            pg_create_task = self.connection.invoke_api(
                self.connection.vim,
                'CreateDVPortgroup_Task',
                self._dvs,
                spec=pg_spec)

            result = self.connection.wait_for_task(pg_create_task)
        except vmware_exceptions.VimException as e:
            raise exceptions.wrap_wmvare_vim_exception(e)
        else:
            pg = result.result
            LOG.info(_LI('Network %(name)s created \n%(pg_ref)s'), {
                'name': name,
                'pg_ref': pg
            })
            return pg
def update_port_rules(dvs, ports):
    try:
        builder = PortConfigSpecBuilder(dvs.connection.vim.client.factory)
        port_config_list = []
        hashed_rules = {}
        for port in ports:
            key = port.get('binding:vif_details', {}).get('dvs_port_key')
            if key:
                port_config = port_configuration(
                    builder, key, port['security_group_rules'], hashed_rules)
                port_config_list.append(port_config)
        if port_config_list:
            task = dvs.connection.invoke_api(
                dvs.connection.vim,
                'ReconfigureDVPort_Task',
                dvs._dvs,
                port=port_config_list
            )
            dvs.connection.wait_for_task(task)
    except vmware_exceptions.VimException as e:
        if 'The object or item referred to could not be found' in str(e):
            pass
        else:
            raise exceptions.wrap_wmvare_vim_exception(e)