'Content-type': 'application/json',
    "X-Auth-Token": apic_session_ticket
}

# ############################################################################
# Get Network Device Count
# ############################################################################
tmp_get = '%s/network-device/count' % _LabEnv.APIC_EM_API
print('My GET Request: ' + tmp_get)
r = requests.get(tmp_get, verify=False, headers=APIC_EM_HEADERS)
print('APIC-EM Response: ' + r.text)

my_parsed_response = r.json()
print('Parsed JSON Response: ')
pprint(my_parsed_response)

my_device_count = my_parsed_response['response']
print('Network Device Count: ' + str(my_device_count))

# ############################################################################
# Share the News
# ############################################################################
tmp_text = 'Hello ' + _LabEnv.LAB_SESSION + ', my APIC-EM at manages ' + str(
    my_device_count) + ' Devices.'
r = _LabEnv.postSparkMessage(tmp_text)
print('Spark Response: ' + r.text)

# ############################################################################
# EOF
# ############################################################################
Example #2
0
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ''AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
#
# TECHNICAL ASSISTANCE CENTER (TAC) SUPPORT IS NOT AVAILABLE FOR THIS SCRIPT.
# ############################################################################
# 
# This is a simple script leveraging _LabEnv to post into a Spark Room 
# 
# ############################################################################
import _LabEnv
import json
import requests
import sys

r = _LabEnv.postSparkMessage('Simple Hello '+_LabEnv.LAB_SESSION+' this is '+_LabEnv.LAB_USER)
print('Spark Response: ' + r.text)

# ############################################################################
# EOF
# ############################################################################
Example #3
0
RESTCONF_API  = "http://198.18.133.218:8008/api/operational/interfaces-state?deep"
INTF      = 'GigabitEthernet1'
TEXT      = 'Hello, %s, this is %s.  Interface %s has received %d bytes and transmitted %d bytes.'
SPARK_ROOM_ID = None

# ############################################################################
# Get Router Interface Data via RESTCONF
# ############################################################################
response = requests.request("GET", RESTCONF_API, headers=_LabEnv.RESTCONF_HEADERS, verify=False)
j = json.loads(response.text)
in_octets = -1
out_octets = -1
for intf in j['ietf-interfaces:interfaces-state']['interface']:
    if intf['name'] == INTF:
        in_octets = intf['statistics']['in-octets']
        out_octets = intf['statistics']['out-octets']
        break
if in_octets == -1 or out_octets == -1:
    print("Failed to find statistics for interface " + INTF)
    sys.exit(1)
   
# ############################################################################
# Post to Spark Room
# ############################################################################
messagetext = TEXT % (_LabEnv.LAB_SESSION, _LabEnv.LAB_USER, INTF, in_octets, out_octets)
r = _LabEnv.postSparkMessage(messagetext)
print('Spark Response: ' + r.text)

# ############################################################################
# EOF
# ############################################################################
Example #4
0
    data = {'username': _LabEnv.APIC_EM_USR, 'password': _LabEnv.APIC_EM_PWD}
    try:
        response = requests.post(_LabEnv.APIC_EM_API + APIC_EM_AUTH_ENDPOINT,
                                 json=data,
                                 headers=headers,
                                 verify=False)
        response.raise_for_status()
        spark_message = u'{} APIC-EM Login {}\n'.format(
            CHECK_MARK_SYMBOL,
            response.json()['response'])
    except (requests.exceptions.ConnectionError,
            requests.exceptions.HTTPError):
        spark_message = u'{} Connection to APIC-EM server {} was unsuccessful\n'.format(
            CROSS_MARK_SYMBOL, _LabEnv.APIC_EM_HOST)
    return spark_message


lab_state += form_apic_em_status_spark_message()

# ############################################################################
# Post into Spark Room
# ############################################################################
# messagetext = 'Hello %s this is %s on %s\n%s' % (_LabEnv.LAB_SESSION, _LabEnv.LAB_USER, dCloudPOD, labstate)
spark_message = u'Hello {}! This is {} \n{}'.format(_LabEnv.LAB_SESSION,
                                                    _LabEnv.LAB_USER,
                                                    lab_state)
r = _LabEnv.postSparkMessage(spark_message)

# ############################################################################
# EOF
# ############################################################################