Configures portgroups on a DVS.

    Creates/updates/removes portgroups in a provided DVS

    dvs
        Name of the DVS

    portgroups
        Portgroup dict representations (see module sysdocs)
342435
def portgroups_configured(name, dvs, portgroups):
    '''
    
    '''
    datacenter = _get_datacenter_name()
    log.info('Running state %s on DVS \'%s\', datacenter \'%s\'',
             name, dvs, datacenter)
    changes_required = False
    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': None}
    comments = []
    changes = {}
    changes_required = False

    try:
        #TODO portroups validation
        si = __salt__['vsphere.get_service_instance_via_proxy']()
        current_pgs = __salt__['vsphere.list_dvportgroups'](
            dvs=dvs, service_instance=si)
        expected_pg_names = []
        for pg in portgroups:
            pg_name = pg['name']
            expected_pg_names.append(pg_name)
            del pg['name']
            log.info('Checking pg \'%s\'', pg_name)
            filtered_current_pgs = \
                    [p for p in current_pgs if p.get('name') == pg_name]
            if not filtered_current_pgs:
                changes_required = True
                if __opts__['test']:
                    comments.append('State {0} will create a new portgroup '
                                    '\'{1}\' in DVS \'{2}\', datacenter '
                                    '\'{3}\''.format(name, pg_name, dvs,
                                                     datacenter))
                else:
                    __salt__['vsphere.create_dvportgroup'](
                        portgroup_dict=pg, portgroup_name=pg_name, dvs=dvs,
                        service_instance=si)
                    comments.append('Created a new portgroup \'{0}\' in DVS '
                                    '\'{1}\', datacenter \'{2}\''
                                    ''.format(pg_name, dvs, datacenter))
                log.info(comments[-1])
                changes.update({pg_name: {'new': pg}})
            else:
                # Porgroup already exists. Checking the config
                log.trace('Portgroup \'%s\' found in DVS \'%s\', datacenter '
                          '\'%s\'. Checking for any updates.',
                          pg_name, dvs, datacenter)
                current_pg = filtered_current_pgs[0]
                diff_dict = _get_diff_dict(current_pg, pg)

                if diff_dict:
                    changes_required = True
                    if __opts__['test']:
                        changes_strings = \
                                _get_changes_from_diff_dict(diff_dict)
                        log.trace('changes_strings = %s', changes_strings)
                        comments.append(
                            'State {0} will update portgroup \'{1}\' in '
                            'DVS \'{2}\', datacenter \'{3}\':\n{4}'
                            ''.format(name, pg_name, dvs, datacenter,
                                      '\n'.join(['\t{0}'.format(c) for c in
                                                 changes_strings])))
                    else:
                        __salt__['vsphere.update_dvportgroup'](
                            portgroup_dict=pg, portgroup=pg_name, dvs=dvs,
                            service_instance=si)
                        comments.append('Updated portgroup \'{0}\' in DVS '
                                        '\'{1}\', datacenter \'{2}\''
                                        ''.format(pg_name, dvs, datacenter))
                    log.info(comments[-1])
                    changes.update(
                        {pg_name: {'new':
                                   _get_val2_dict_from_diff_dict(diff_dict),
                                   'old':
                                   _get_val1_dict_from_diff_dict(diff_dict)}})
        # Add the uplink portgroup to the expected pg names
        uplink_pg = __salt__['vsphere.list_uplink_dvportgroup'](
            dvs=dvs, service_instance=si)
        expected_pg_names.append(uplink_pg['name'])
        # Remove any extra portgroups
        for current_pg in current_pgs:
            if current_pg['name'] not in expected_pg_names:
                changes_required = True
                if __opts__['test']:
                    comments.append('State {0} will remove '
                                    'the portgroup \'{1}\' from DVS \'{2}\', '
                                    'datacenter \'{3}\''
                                    ''.format(name, current_pg['name'], dvs,
                                              datacenter))
                else:
                    __salt__['vsphere.remove_dvportgroup'](
                        portgroup=current_pg['name'], dvs=dvs,
                        service_instance=si)
                    comments.append('Removed the portgroup \'{0}\' from DVS '
                                    '\'{1}\', datacenter \'{2}\''
                                    ''.format(current_pg['name'], dvs,
                                              datacenter))
                log.info(comments[-1])
                changes.update({current_pg['name']:
                                {'old': current_pg}})
        __salt__['vsphere.disconnect'](si)
    except salt.exceptions.CommandExecutionError as exc:
        log.exception('Encountered error')
        if si:
            __salt__['vsphere.disconnect'](si)
        if not __opts__['test']:
            ret['result'] = False
        ret.update({'comment': exc.strerror,
                    'result': False if not __opts__['test'] else None})
        return ret
    if not changes_required:
        # We have no changes
        ret.update({'comment': ('All portgroups in DVS \'{0}\', datacenter '
                                '\'{1}\' exist and are correctly configured. '
                                'Nothing to be done.'.format(dvs, datacenter)),
                    'result': True})
    else:
        ret.update({
            'comment': '\n'.join(comments),
            'changes': changes,
            'result': None if __opts__['test'] else True,
        })
    return ret
135982
def update_dvportgroup(portgroup_ref, spec):
    '''
    
    '''
    pg_name = get_managed_object_name(portgroup_ref)
    log.trace('Updating portgrouo %s', pg_name)
    try:
        task = portgroup_ref.ReconfigureDVPortgroup_Task(spec)
    except vim.fault.NoPermission as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(
            'Not enough permissions. Required privilege: '
            '{0}'.format(exc.privilegeId))
    except vim.fault.VimFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(exc.msg)
    except vmodl.RuntimeFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareRuntimeError(exc.msg)
    wait_for_task(task, pg_name, six.text_type(task.__class__))
1031930
function(group, containers)
	{
	    if (lang.isObject(group.groupContainer))
		containers.push(group.groupContainer);
	    else
	    {
		for (var cI in group.containers)
		    containers.push(group.containers[cI].container);

		for (var gI in group.groups)
		    WireIt.GroupUtils.addAllContainers(group.groups[gI].group, containers)
	    }
	}
886956
def setup(cfg):
    

    # copy the necessary configuration values over
    this_module = sys.modules[__name__]
    for name, value in cfg.items():
        if hasattr(this_module, name):
            setattr(this_module, name, value)
97636
def update_instance_security_group(self, instance_id,
                                       new_security_group_ids):
        """"""
        ports = port_list(self.request, device_id=instance_id)
        for p in ports:
            params = {'security_groups': new_security_group_ids}
            port_update(self.request, p.id, **params)
1399
def group_remove(name, **kwargs):
    
    ctx = Context(**kwargs)
    ctx.execute_action('group:remove', **{
        'storage': ctx.repo.create_secure_service('storage'),
        'name': name,
    })
1216917
def update_group_property(self, group_id, group_properties):
        
        group_properties['group_id'] = group_id
        return self._post(
            'merchant/group/propertymod',
            data=group_properties
        )
450412
def _apply_dvportgroup_out_shaping(pg_name, out_shaping, out_shaping_conf):
    '''
    
    '''
    log.trace('Building portgroup\'s \'%s\' out shaping policy', pg_name)
    if out_shaping_conf.get('average_bandwidth'):
        out_shaping.averageBandwidth = vim.LongPolicy()
        out_shaping.averageBandwidth.value = \
                out_shaping_conf['average_bandwidth']
    if out_shaping_conf.get('burst_size'):
        out_shaping.burstSize = vim.LongPolicy()
        out_shaping.burstSize.value = out_shaping_conf['burst_size']
    if 'enabled' in out_shaping_conf:
        out_shaping.enabled = vim.BoolPolicy()
        out_shaping.enabled.value = out_shaping_conf['enabled']
    if out_shaping_conf.get('peak_bandwidth'):
        out_shaping.peakBandwidth = vim.LongPolicy()
        out_shaping.peakBandwidth.value = out_shaping_conf['peak_bandwidth']
1087420
def group_add(self, name='Ungrouped'):
        
        if not hasattr(self, name):
            self.__dict__[name] = Group(self, name)
            self.loaded_groups.append(name)
919309
private void createSubgroups(GroupHierarchyConfig config, String groupId) {
        config.getSubitems().forEach(cfg -> {
            if (cfg instanceof GroupHierarchyConfig) {
                GroupMetadata curGroup = findGroup((GroupHierarchyConfig) cfg, groupId);
                String subGroupId;
                if (curGroup != null) {
                    subGroupId = curGroup.getId();
                } else {
                    subGroupId = create(converter.createGroupConfig((GroupHierarchyConfig) cfg, groupId))
                        .getResult()
                        .as(GroupByIdRef.class)
                        .getId();
                }
                createSubgroups((GroupHierarchyConfig) cfg, subGroupId);
            } else if (cfg instanceof CreateServerConfig) {
                ((CreateServerConfig) cfg).group(Group.refById(groupId));
            } else {
                ((CompositeServerConfig) cfg).getServer().group(Group.refById(groupId));
            }
        });
    }
1301497
def _resize_port_models_list(port_models, rel_pos_key, factor, gaphas_editor=True):
    
    for port_m in port_models:
        old_rel_pos = port_m.get_meta_data_editor(for_gaphas=gaphas_editor)[rel_pos_key]
        port_m.set_meta_data_editor(rel_pos_key, mult_two_vectors(factor, old_rel_pos), from_gaphas=gaphas_editor)
359436
def group_add(self, name, restrict, repos, lces=[], assets=[], queries=[],
                  policies=[], dashboards=[], credentials=[], description=''):
        '''
        '''
        return self.raw_query('group', 'add', data={
            'lces': [{'id': i} for i in lces],
            'assets': [{'id': i} for i in assets],
            'queries': [{'id': i} for i in queries],
            'policies': [{'id': i} for i in policies],
            'dashboardTabs': [{'id': i} for i in dashboards],
            'credentials': [{'id': i} for i in credentials],
            'repositories': [{'id': i} for i in repos],
            'definingAssets': [{'id': i} for i in restrict],
            'name': name,
            'description': description,
            'users': [],
            'context': ''
        })
831562
def setLocalityGroups(self, login, tableName, groups):
    
    self.send_setLocalityGroups(login, tableName, groups)
    self.recv_setLocalityGroups()
1222449
def _configure(changes):

    '''
    
    '''

    cfgred = True
    reasons = []
    fun = 'update_config'

    for key in ['added', 'updated', 'removed']:
        _updated_changes = changes.get(key, {})
        if not _updated_changes:
            continue
        _location = _updated_changes.get('location', '')
        _contact = _updated_changes.get('contact', '')
        _community = _updated_changes.get('community', {})
        _chassis_id = _updated_changes.get('chassis_id', '')
        if key == 'removed':
            fun = 'remove_config'
        _ret = __salt__['snmp.{fun}'.format(fun=fun)](location=_location,
                                                      contact=_contact,
                                                      community=_community,
                                                      chassis_id=_chassis_id,
                                                      commit=False)
        cfgred = cfgred and _ret.get('result')
        if not _ret.get('result') and _ret.get('comment'):
            reasons.append(_ret.get('comment'))

    return {
        'result': cfgred,
        'comment': '\n'.join(reasons) if reasons else ''
    }
1240260
def _get_dvs_uplink_portgroup(dvs, portgroup_name):
    '''
    
    '''
    for portgroup in dvs.portgroup:
        if portgroup.name == portgroup_name:
            return portgroup

    return None
1323773
function add_group() {
    server.EntryGroupNew(function(err, path) {
      if (err) {
        sails.log.error('DBus: Could not call org.freedesktop.Avahi.Server.EntryGroupNew');
        return;
      }
      service.getInterface(
        path,
        avahi.DBUS_INTERFACE_ENTRY_GROUP.value,
        function (
          err,
          newGroup
        ) {
          group = newGroup;
          add_service();
        }
      )
    });
  }
1115115
def _apply_dvs_config(config_spec, config_dict):
    '''
    
    '''
    if config_dict.get('name'):
        config_spec.name = config_dict['name']
    if config_dict.get('contact_email') or config_dict.get('contact_name'):
        if not config_spec.contact:
            config_spec.contact = vim.DVSContactInfo()
        config_spec.contact.contact = config_dict.get('contact_email')
        config_spec.contact.name = config_dict.get('contact_name')
    if config_dict.get('description'):
        config_spec.description = config_dict.get('description')
    if config_dict.get('max_mtu'):
        config_spec.maxMtu = config_dict.get('max_mtu')
    if config_dict.get('lacp_api_version'):
        config_spec.lacpApiVersion = config_dict.get('lacp_api_version')
    if config_dict.get('network_resource_control_version'):
        config_spec.networkResourceControlVersion = \
                config_dict.get('network_resource_control_version')
    if config_dict.get('uplink_names'):
        if not config_spec.uplinkPortPolicy or \
           not isinstance(config_spec.uplinkPortPolicy,
                          vim.DVSNameArrayUplinkPortPolicy):

            config_spec.uplinkPortPolicy = \
                    vim.DVSNameArrayUplinkPortPolicy()
        config_spec.uplinkPortPolicy.uplinkPortName = \
                config_dict['uplink_names']