示例#1
0

# this is the variable of the room id we need to figure out:
room_id = None
# you can replace room ID from output of script here
# this will speed up things a bit as the room search
# can be omitted.
# room_id = 'your-room-id-output-from-the-script'

if not room_id:
    room_id = spark_get_room_id(SPARK_TOKN, SPARK_ROOM)
    print('Your room ID "{id}".'.format(id=room_id))

if room_id:
    spark_send_message(
        SPARK_TOKN, room_id, 'Hello room! My script verified that I can '
        'post messages to Spark using REST API calls.')
    if check_restconf(RESTCONF_URL):
        spark_send_message(
            SPARK_TOKN, room_id,
            'It also verified that RESTCONF enabled device '
            'is working properly.')
    else:
        spark_send_message(
            SPARK_TOKN, room_id, 'Unfortunately, RESTCONF enabled device is '
            'NOT working properly.')
    if check_apic_em(APIC_EM_URL):
        spark_send_message(
            SPARK_TOKN, room_id, 'It also verified that APIC-EM '
            'is working properly.')
    else:
示例#2
0
import requests

# Disable all warning messages since we're dealing with a
# self-signed certificate on APIC-EM
requests.packages.urllib3.disable_warnings()

# We need to know our token and other information.
# Make sure you either create your own room
# or provide the name of the common event room
SPARK_TOKN = 'Cut and paste your token here'
# The spark room name is case sensitive.  Do not change this value for the KSO.
SPARK_ROOM = 'Federal Devnet Express Q3KSO'

# this is the variable of the room id we need to figure out:
room_id = None
# you can replace room ID from output of script here
# this will speed up things a bit as the room search
# can be omitted.
# room_id = 'your-room-id-output-from-the-script'

if not room_id:
    room_id = spark_get_room_id(SPARK_TOKN, SPARK_ROOM)
    print('Your room ID "{id}".'.format(id=room_id))

if room_id:
    spark_send_message(
        SPARK_TOKN, room_id, 'Hello room! My script verified that I can '
        'post messages to Spark using REST API calls.')
    print('Please check room ' + SPARK_ROOM +
          ', there are messages posted on your behalf.')
示例#3
0
def create_vlan(host, port, user, password, interface, vlan, ip, insecure):
    """Function to create a subinterface on CSR1000V."""
    intfc = re.compile(r'^(\D+)(\d+)$')
    m = intfc.match(interface)
    if m is None:
        print("invalid interface name. Valid example: ", BASE)
        return -1

    data = '''
	{
	  "ned:%s": {
	    "name": "%s.%d",
	    "encapsulation": {
	      "dot1Q": {
		    "vlan-id": %d
	      }
	    },
	    %s
	  }
	}
	'''

    if ip.version == 6:
        ipdata = '''
		    "ipv6": {
		      "address": {
			    "prefix-list": [
			      {
			        "prefix": "%s"
			      }
			    ]
		      }
		    }
		''' % str(ip)
    else:
        ipdata = '''
		    "ip": {
		      "address": {
			    "primary": {
			      "address": "%s",
			      "mask": "%s"
			    }
		      }
		    }
		''' % (ip.ip, ip.netmask)

    data = data % (m.group(1), m.group(2), vlan, vlan, ipdata)
    url = "https://%s/api/running/native/interface/%s/%s.%d" % (
        host, m.group(1), m.group(2), vlan)
    headers = {
        'content-type': 'application/vnd.yang.data+json',
        'accept': 'application/vnd.yang.data+json'
    }

    try:
        result = requests.put(url,
                              auth=(user, password),
                              data=data,
                              headers=headers,
                              verify=not insecure)
        room = myspark.spark_get_room_id(hello_lab.TOKEN, hello_lab.NAME)
        myspark.spark_send_message(
            hello_lab.TOKEN, room,
            "Hi! I'm adding a configuration change now to the CSR1000V!")
        myspark.spark_send_message(
            hello_lab.TOKEN, room,
            "Here is the change being applied using RESTCONF:")
        myspark.spark_send_message(hello_lab.TOKEN, room, "URL: %s" % url)
        myspark.spark_send_message(hello_lab.TOKEN, room, "JSON: %s" % data)

    except:
        print(str(sys.exc_info()[0]))
        return -1

    # we expect a 201 for success
    if result.status_code == 201:
        return 0

    # something went wrong
    print(result.status_code, result.text)
    return -1
示例#4
0
    
RSS_URL = "http://localhost/test.xml"
RSS_URL = "https://news.yahoo.co.jp/pickup/rss.xml"

# print yahoo_news_dic.feed.title

messages_old = ""
messages = ""
if room_id:
    yahoo_news_dic = feedparser.parse(RSS_URL)
    for entry in yahoo_news_dic.entries:
        title = entry.title
        link  = entry.link
        messages = messages + title + '\n' + link + '\n'
    date = '\n' + datetime.now().strftime("%Y/%m/%d %H:%M:%S") + "\n"
    spark_send_message(SPARK_TOKN, room_id, date)
    spark_send_message(SPARK_TOKN, room_id, messages)
    print(date)
    print(messages)
    messages_old = messages

num = 1
while True:
    if messages == messages_old:
        print("同じ" + str(num) + ':'),
        for entry in yahoo_news_dic.entries:
            title = entry.title
            link  = entry.link
            break
        print("title:"),
        print(title)
    if apic_em_response.ok:
        return True
    else:
        return False



# this is the variable of the room id we need to figure out:
room_id = None
# you can replace room ID from output of script here
# room_id = 'your-room-id-output-from-the-script'


if not room_id:
    room_id = spark_get_room_id(TOKEN, NAME)


if room_id:
    spark_send_message(TOKEN, room_id, 'Hello room! My script verified that I can post messages to Spark using REST API calls.\n')
    if check_restconf(RESTCONF):
        spark_send_message(TOKEN, room_id, 'It also verified that RESTCONF enabled device is working properly.\n')
    else:
        spark_send_message(TOKEN, room_id, 'Unfortunately, RESTCONF enabled device is not working properly.\n')
    if check_apic_em(APIC_EM):
        spark_send_message(TOKEN, room_id, 'It also verified that APIC-EM is working properly.\n')
    else:
        spark_send_message(TOKEN, room_id, 'Unfortunately, APIC-EM is working properly.\n')
    print("Please check room " + NAME + ", there are messages posted on your behalf")