Esempio n. 1
0
def _get(ap, path):
    """Get OpenConfig JSON.

  Args:
    ap: AP Class Object.
    path: (str) Describing the xpath.
  Returns:
    config_json: Full AP config in OC IETF_JSON.
  """
    # Set up the gNMI path.
    if path == 'r0-config':  # Config shown here just for example.
        paths = gnmi_lib.ParsePath(
            gnmi_lib.PathNames(
                '/access-points/access-point[hostname=%s]/radios/radio[id=0]/config'
                % ap.ap_name))
    elif path == 'r0-state':
        paths = gnmi_lib.ParsePath(
            gnmi_lib.PathNames(
                '/access-points/access-point[hostname=%s]/radios/radio[id=0]/state/'
                % ap.ap_name))
    elif path == 'config_state':
        paths = gnmi_lib.ParsePath(
            gnmi_lib.PathNames('/access-points/access-point[hostname=%s]/' %
                               ap.ap_name))
    if ap.targetport == '443' or ap.targetport == '10161':
        # Target is ap-manager.
        response = gnmi_lib.Get(ap.stub, paths, constants.MIST_USER,
                                constants.MIST_PASS)
        return response.notification[0].update[0].val.json_ietf_val
    response = gnmi_lib.Get(  # Target is AP.
        ap.stub, paths, constants.ARISTA_USER, constants.ARISTA_PASS)
    return response.notification[0].update[0].val.json_ietf_val
Esempio n. 2
0
def SetConfig(ap, json_path='', xpath='', json_str=''):
    """Performs Set request and display response.

  If no xpath is provided _HOST_PATH is used.  Either json_path or json_str must
  be provided as the source of configuration.

  Args:
    ap: (object) chido_test.ApObject containing all AP attributes.
    json_path: (str) full path to JSON file.
    xpath: (str) Explicit OpenConfig tree xpath.
    json_str: (str) A valid json string.

  Returns:
    ap.gnmi_set_status: (bool) whether the gNMI SET operation passed or failed.
  """
    if json_str:
        json_data = json_str
    elif json_path:
        with open(json_path, 'rt') as data_file:
            json_data = data_file.read()
    else:
        raise ValueError('No valid path or json string provided to set config')

    payload = json.loads(json_data)
    username, password = _GetUserPass(ap.vendor)

    if xpath:
        paths = gnmi_lib.ParsePath(gnmi_lib.PathNames(xpath))
    else:
        paths = gnmi_lib.ParsePath(
            gnmi_lib.PathNames((_HOST_PATH % ap.ap_name)))

    if ap.vendor == 'arista':
        creds = gnmi_lib.CreateCreds(constants.ARISTA_CA_CERT)
        ap.stub = gnmi_lib.CreateStub(creds, ap.targetip, ap.targetport,
                                      'openconfig.mojonetworks.com')
    elif ap.vendor == 'aruba':
        creds = gnmi_lib.CreateCreds(constants.ARUBA_CA_CERT)
        ap.stub = gnmi_lib.CreateStub(creds, ap.targetip, ap.targetport,
                                      'OpenConfig.arubanetworks.com')
    elif ap.vendor == 'mist':
        creds = gnmi_lib.CreateCreds()
        ap.stub = gnmi_lib.CreateStub(creds, _MIST_GCP,
                                      constants.GNMI_TARGETPORTS['mist'],
                                      _MIST_GCP)

    config_response = gnmi_lib.Set(ap.stub, paths, username, password, payload,
                                   _SET_UPDATE)
    logging.info(_RESPONSE, config_response)
    ap.gnmi_set_status = True

    return ap.gnmi_set_status
Esempio n. 3
0
def GetPath(ap, xpath):
    """Performs Get request and display response.

  Args:
    ap: (object) chido_test.ApObject containing all AP attributes.
    xpath: (str) the OpenConfig path to get.

  Raises:
    UnsupportedVendorError: If an AP is an unsupported vendor.
  Returns:
    gnmi_pb2.GetResponse object representing a gNMI GetResponse.
  """
    ap.targetport = constants.GNMI_TARGETPORTS[ap.vendor]
    username, password = _GetUserPass(ap.vendor)

    path = gnmi_lib.ParsePath(gnmi_lib.PathNames((xpath)))

    if ap.vendor == 'arista':
        creds = gnmi_lib.CreateCreds(constants.ARISTA_CA_CERT)
        ap.stub = gnmi_lib.CreateStub(creds, ap.targetip, ap.targetport,
                                      'openconfig.mojonetworks.com')
    elif ap.vendor == 'aruba':
        creds = gnmi_lib.CreateCreds(constants.ARUBA_CA_CERT)
        ap.stub = gnmi_lib.CreateStub(creds, ap.targetip, ap.targetport,
                                      'OpenConfig.arubanetworks.com')
    elif ap.vendor == 'mist':
        creds = gnmi_lib.CreateCreds()
        ap.stub = gnmi_lib.CreateStub(creds, _MIST_GCP, ap.targetport,
                                      _MIST_GCP)
    else:
        raise UnsupportedVendorError(
            'Unsupported vendor for AP %s, vendor: %s' %
            (ap.ap_name, ap.vendor))

    return gnmi_lib.Get(ap.stub, path, username, password)
Esempio n. 4
0
def Provision(ap):
  """Triggers the provisioning workflow.

  Args:
    ap: AP Class object.

  This populates the conig object (from PyangBind, from YANG model) for day-0
  provisioning.
  """
  paths = gnmi_lib.ParsePath(gnmi_lib.PathNames((
    '/provision-aps/provision-ap[mac=%s]/' % ap.mac)))
  provision_apconfigs = ap_manager_configs.provision_aps.provision_ap
  day0 = provision_apconfigs.add(ap.mac)
  day0.config.mac = ap.mac
  day0.config.hostname = ap.ap_name
  day0.config.country_code = 'US'
  json_value = json.loads(pybindJSON.dumps(day0, mode='ietf', indent=2))
  if FLAGS.dry_run:
    print('Here\'s the JSON that was created, for sending to the Target:')
    print('*'*25, '\n\n', json.dumps(json_value, indent=2),'\n\n', '*'*25)
    print('JSON written as dry_run_provision.json')
    f = six.moves.builtins.open('dry_run_provision.json', 'w')
    f.write(json.dumps(json_value, indent=2) + '\n')
    sys.exit()
  else:
    r = gnmi_lib.Set(ap.stub, paths, ap.targetuser, ap.targetpass, json_value, 'update')
    print('provisioning succesfull, with the following gNMI SetResponse:\n', r)
Esempio n. 5
0
def ConfigPhyMac(ap, student_ssids):
  """Triggers the configuration of PHY and MAC layer.

  Args:
    ap: AP Class object.
    student_ssids: (list) SSIDs to configure on the AP.

  This populates the conig object (from PyangBind, from YANG model) for day-1+
  configuration.
  """
  paths = gnmi_lib.ParsePath(gnmi_lib.PathNames((
    '/access-points/access-point[hostname=%s]/' % ap.ap_name)))
  ap_configs = access_point_configs.access_points.access_point
  ap_configs.add(ap.ap_name)
  open_ssid = ap_configs[ap.ap_name].ssids.ssid.add(ap.openssid)
  open_ssid.config.name = ap.openssid
  open_ssid.config.enabled = True
  open_ssid.config.hidden = False
  open_ssid.config.operating_frequency = 'FREQ_5GHZ'
  open_ssid.config.opmode = 'OPEN'
  open_ssid.wmm.config.trust_dscp = True
  psk_ssid = ap_configs[ap.ap_name].ssids.ssid.add(ap.pskssid)
  psk_ssid.config.enabled = True
  psk_ssid.config.name = ap.pskssid
  psk_ssid.config.hidden = False
  psk_ssid.config.operating_frequency = 'FREQ_2_5_GHZ'
  psk_ssid.config.opmode = 'WPA2_PERSONAL'
  psk_ssid.config.wpa2_psk = 'testing123'
  psk_ssid.wmm.config.trust_dscp = True
  # PHY Layer stuff.
  fiveg = ap_configs[ap.ap_name].radios.radio.add(0)
  fiveg.config.id = 0
  fiveg.config.operating_frequency = 'FREQ_5GHZ'
  fiveg.config.enabled = True
  fiveg.config.dca = False
  fiveg.config.transmit_power = 3
  fiveg.config.channel_width = 20
  fiveg.config.channel = 165
  twog = ap_configs[ap.ap_name].radios.radio.add(1)
  twog.config.id = 1
  twog.config.operating_frequency = 'FREQ_2GHZ'
  twog.config.enabled = True
  twog.config.dca = False
  twog.config.transmit_power = 3
  twog.config.channel_width = 20
  twog.config.channel = 6
  json_value = _int_fixer(json.loads(pybindJSON.dumps(
    access_point_configs, mode='ietf', indent=2))['openconfig-access-points:access-points']['access-point'][0])
  if FLAGS.dry_run:
    print('Here\'s the JSON that was created, for sending to the Target:')
    print('*'*25, '\n\n', json.dumps(json_value, indent=2),'\n\n', '*'*25)
    print('JSON written as dry_run_configs.json')
    f = six.moves.builtins.open('dry_run_configs.json', 'w')
    f.write(json.dumps(json_value, indent=2) + '\n')
    sys.exit()
  else:
    r = gnmi_lib.Set(ap.stub, paths, ap.targetuser, ap.targetpass, json_value, 'update')
    print('Configuration succesfull, with the following gNMI SetResponse:\n', r)
    return json.dumps(json_value)