Setup platform specific network settings
426701
def _setup_network():
    """"""
    global wlan
    global secret

    if sys.platform in PYCOM:
        # Update secret as tuple with wlan mode for PyCom port.
        wlan = network.WLAN(network.WLAN.STA)
        secret = (network.WLAN.WPA2, settings.WIFI_PASSWORD)
    else:
        # default micropython wlan settings
        wlan = network.WLAN(network.STA_IF)
        secret = settings.WIFI_PASSWORD
1281350
def set_ddns_config(self, isenable, hostname, ddnsserver,
                                        user, password, callback=None):
        '''
        
        '''
        params = {'isEnable': isenable,
                  'hostName': hostname,
                  'ddnsServer': ddnsserver,
                  'user': user,
                  'password': password,
                 }
        return self.execute_command('setDDNSConfig', params, callback=callback)
765498
def set_mac_addr(self, mac_addr):
        

        yield from self._hypervisor.send('{platform} set_mac_addr "{name}" {mac_addr}'.format(platform=self._platform,
                                                                                              name=self._name,
                                                                                              mac_addr=mac_addr))

        log.info('Router "{name}" [{id}]: MAC address updated from {old_mac} to {new_mac}'.format(name=self._name,
                                                                                                  id=self._id,
                                                                                                  old_mac=self._mac_addr,
                                                                                                  new_mac=mac_addr))
        self._mac_addr = mac_addr
362676
def _map_device_on_host_networks(provider_nets, devices):
    """"""
    networks = copy.deepcopy(provider_nets)
    for network in networks:
        for device in devices:
            network.setdefault('device', None)
            ip_set = IPSet([network['cidr']])
            if 'ipv4' not in device:
                continue
            ips = device['ipv4']
            if not isinstance(ips, list):
                ips = [ips]
            if len(ips) < 1:
                continue
            ip = IPAddress(ips[0]['address'])
            if ip in ip_set:
                network['device'] = device['device']
                continue
    return networks
678095
def setup(self, redis_conn=None, host='localhost', port=6379):
        '''
        
        '''
        if redis_conn is None:
            if host is not None and port is not None:
                self.redis_conn = redis.Redis(host=host, port=port)
            else:
                raise Exception("Please specify some form of connection "
                                    "to Redis")
        else:
            self.redis_conn = redis_conn

        self.redis_conn.info()
1227726
def setup(self):
        
        options = ""
        if self.get_option("port"):
            options = (options + " -b " + gethostname() +
                       ":%s" % (self.get_option("port")))
        # gethostname() is due to DISPATCH-156

        # for either present option, add --option=value to 'options' variable
        for option in ["ssl-certificate", "ssl-key", "ssl-trustfile"]:
            if self.get_option(option):
                options = (options + " --%s=" % (option) +
                           self.get_option(option))

        self.add_cmd_output([
            "qdstat -a" + options,  # Show Router Addresses
            "qdstat -n" + options,  # Show Router Nodes
            "qdstat -c" + options,  # Show Connections
            "qdstat -m" + options   # Show Broker Memory Stats
        ])

        self.add_copy_spec([
            "/etc/qpid-dispatch/qdrouterd.conf"
        ])
227385
def add_reserved_switch_binding(switch_ip, state):
    """"""

    # overload port_id to contain switch state
    add_nexusport_binding(
        state,
        const.NO_VLAN_OR_VNI_ID,
        const.NO_VLAN_OR_VNI_ID,
        switch_ip,
        const.RESERVED_NEXUS_SWITCH_DEVICE_ID_R1)
963641
def configure_network(ip, netmask, gateway):
    '''
    
    '''
    current = network()

    # Check to see if the network is already configured
    if (ip in current['Network Settings']['IP_ADDRESS']['VALUE'] and
            netmask in current['Network Settings']['SUBNET_MASK']['VALUE'] and
            gateway in current['Network Settings']['GATEWAY_IP_ADDRESS']['VALUE']):
        return True

    _xml = """<RIBCL VERSION="2.0">
                <LOGIN USER_LOGIN="adminname" PASSWORD="password">
                  <RIB_INFO MODE="write">
                    <MOD_NETWORK_SETTINGS>
                      <IP_ADDRESS value="{0}"/>
                      <SUBNET_MASK value="{1}"/>
                      <GATEWAY_IP_ADDRESS value="{2}"/>
                    </MOD_NETWORK_SETTINGS>
                  </RIB_INFO>
                </LOGIN>
              </RIBCL> """.format(ip, netmask, gateway)

    return __execute_cmd('Configure_Network', _xml)
274069
def set_network_connection(self, network):
        
        mode = network.mask if isinstance(network, self.ConnectionType) else network
        return self.ConnectionType(self._driver.execute(
            Command.SET_NETWORK_CONNECTION, {
                'name': 'network_connection',
                'parameters': {'type': mode}})['value'])
1051568
def get_network_settings():
    '''
    
    '''
    if __grains__['lsb_distrib_id'] == 'nilrt':
        raise salt.exceptions.CommandExecutionError('Not supported in this version.')
    settings = []
    networking = 'no' if _get_state() == 'offline' else 'yes'
    settings.append('networking={0}'.format(networking))
    hostname = __salt__['network.get_hostname']
    settings.append('hostname={0}'.format(hostname))
    return settings
885634
def create_network(userid, os_version, network_info):
    
    print("\nConfiguring network interface for %s ..." % userid)
    network_create_info = client.send_request('guest_create_network_interface', 
                                              userid, os_version, network_info)

    if network_create_info['overallRC']:
        raise RuntimeError("Failed to create network for guest %s!\n%s" % 
                           (userid, network_create_info))
    else:
        print("Succeeded to create network for guest %s!" % userid)
448029
def write_config(ip, mac, single, double, long, touch):
    """"""
    click.echo("Write configuration to device %s" % ip)
    data = {
        'single': single,
        'double': double,
        'long': long,
        'touch': touch,
    }
    request = requests.post(
        'http://{}/{}/{}/'.format(ip, URI, mac), data=data, timeout=TIMEOUT)

    if request.status_code == 200:
        click.echo("Configuration of %s set" % mac)
664096
def _configure_port_binding(self, is_provider_vlan, duplicate_type,
                                is_native,
                                switch_ip, vlan_id,
                                intf_type, nexus_port, vni):
        """"""

        # This implies VLAN, VNI, and Port are all duplicate.
        # Then there is nothing to configure in Nexus.
        if duplicate_type == const.DUPLICATE_PORT:
            return

        auto_create, auto_trunk = self._gather_config_parms(
            is_provider_vlan, vlan_id)

        # if type DUPLICATE_VLAN, don't create vlan
        if duplicate_type == const.DUPLICATE_VLAN:
            auto_create = False

        if auto_create and auto_trunk:
            LOG.debug("Nexus: create vlan %s and add to interface", vlan_id)
            self.driver.create_and_trunk_vlan(
                switch_ip, vlan_id, intf_type,
                nexus_port, vni, is_native)
        elif auto_create:
            LOG.debug("Nexus: create vlan %s", vlan_id)
            self.driver.create_vlan(switch_ip, vlan_id, vni)
        elif auto_trunk:
            LOG.debug("Nexus: trunk vlan %s", vlan_id)
            self.driver.send_enable_vlan_on_trunk_int(
                switch_ip, vlan_id,
                intf_type, nexus_port, is_native)
1050562
def configure_next_batch_of_vlans(self, switch_ip):
        """"""

        next_range = self._pop_vlan_range(
                          switch_ip, const.CREATE_VLAN_BATCH)
        if next_range:
            try:
                self.driver.set_all_vlan_states(
                    switch_ip, next_range)
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error("Error encountered restoring vlans "
                        "for switch %(switch_ip)s",
                        {'switch_ip': switch_ip})
                    self._save_switch_vlan_range(switch_ip, [])

        vxlan_range = self._get_switch_vxlan_range(switch_ip)
        if vxlan_range:
            try:
                self._restore_vxlan_entries(switch_ip, vxlan_range)
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error("Error encountered restoring vxlans "
                        "for switch %(switch_ip)s",
                        {'switch_ip': switch_ip})
                    self._save_switch_vxlan_range(switch_ip, [])

        # if no more vlans to restore, we're done. go active.
        if (not self._get_switch_vlan_range(switch_ip) and
            not self._get_switch_vxlan_range(switch_ip)):
            self.set_switch_ip_and_active_state(
                switch_ip, const.SWITCH_ACTIVE)
            LOG.info("Restore of Nexus switch "
                "ip %(switch_ip)s is complete",
                {'switch_ip': switch_ip})
        else:
            LOG.debug(("Restored batch of VLANS on "
                "Nexus switch ip %(switch_ip)s"),
                {'switch_ip': switch_ip})
680254
def set_wifi_setting(self, ssid, psk, isenable, isusewifi, nettype,
                            encryptype, authmode, keyformat, defaultkey,
                            key1='', key2='', key3='', key4='',
                            key1len=64, key2len=64, key3len=64, key4len=64,
                            callback=None):
        '''
        
        '''
        params = {'isEnable'   : isenable,
                  'isUseWifi'  : isusewifi,
                  'ssid'       : ssid,
                  'netType'    : nettype,
                  'encryptType': encryptype,
                  'psk'        : psk,
                  'authMode'   : authmode,
                  'keyFormat'  : keyformat,
                  'defaultKey' : defaultkey,
                  'key1'       : key1,
                  'key2'       : key2,
                  'key3'       : key3,
                  'key4'       : key4,
                  'key1Len'    : key1len,
                  'key2Len'    : key2len,
                  'key3Len'    : key3len,
                  'key4Len'    : key4len,
                  }
        return self.execute_command('setWifiSetting', params, callback=callback)
1251225
def update_platform(self):
        """"""
        self.chain.connection.log("Detecting hw platform")
        platform = self.driver.get_hw_platform(self.udi)
        if platform:
            self.chain.connection.log("HW Platform: {}".format(platform))
            self.platform = platform
342443
def host_config(self):
        
        if platform.system() == 'Darwin':
            default_file_dir = join(expanduser('~'),
                                    'vent_files')
        else:
            default_file_dir = '/opt/vent_files'
        status = self.ensure_dir(default_file_dir)
        if not isfile(self.cfg_file):
            config = Template(template=self.cfg_file)
            sections = {'main': {'files': default_file_dir},
                        'network-mapping': {},
                        'nvidia-docker-plugin': {'port': '3476'}}
            for s in sections:
                if sections[s]:
                    for option in sections[s]:
                        config.add_option(s, option, sections[s][option])
                else:
                    config.add_section(s)
            config.write_config()
        return status