Beispiel #1
0
#!/usr/bin/python3
import json
import requests
from requests import urllib3
import time
import pprint as pp
import csv
import pandas as pd
from docx import Document
from docx.shared import Inches, Pt
from docx.enum.section import WD_ORIENT, WD_SECTION
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


def http_get(meraki_url):
    base_url = ('https://api.meraki.com/api/v0/{}'.format(meraki_url))
    headers = {
        'X-Cisco-Meraki-API-Key': '029c931f51ee7ea3d74de7cbf6e2db80b17d38d7'
    }
    get_response = requests.get(base_url, headers=headers, verify=False).json()
    time.sleep(0.5)
    return get_response


def create_word_doc_title(doc_title=''):
    doc = Document()
    doc.add_heading(doc_title, 0)
    doc.add_picture('meraki_splash.png', width=Inches(3.25))
    doc.add_page_break()

    return doc
Beispiel #2
0
def main():
    parser = argparse.ArgumentParser(description="AVISDK based Script to get a list of VIPs using highest Bandwidth or no of Connections")
    parser.add_argument("-u", "--username", required=False, help="Login username")
    parser.add_argument("-to", "--token", required=True, help="Token for Authentication")
    parser.add_argument("-c", "--controller", required=True, help="Controller IP address")
    parser.add_argument("-t", "--tenant", required=False, help="Tenant Name")
    parser.add_argument("-a", "--api_version", required=True, help="API Version")
    parser.add_argument("-l", "--limits", required=True, help="No of Samples to be taken")
    parser.add_argument("-s", "--step", required=True, help="Take samples after every n seconds - possible values 300,3600,86400")
    parser.add_argument("-pm", "--parameter", required=True, help="Parameter to be checked - possible values: bw, conn")

    args = parser.parse_args()

    user = str([args.username if args.username else "admin"][0])
    tenant = str([args.tenant if args.tenant else "admin"][0])
    api_version = str([args.api_version if args.api_version else "17.2.11"][0])
    token = args.token
    controller = args.controller
    limits = int(args.limits)
    step = int(args.step)
    if args.parameter == 'conn':
        m_id = 'l4_client.avg_complete_conns'
    elif args.parameter == 'bw':
        m_id = 'l4_client.avg_bandwidth'
    else:
        print 'Invalid Parameter, exitting.'
        sys.exit()

    # Get Api Session
    urllib3.disable_warnings()
    global api
    api = ApiSession.get_session(controller, user, token=token, tenant=tenant, api_version=api_version)

    page = 1
    vs_list = {}

    print 'Getting VS info..',
    while True:
        resp = api.get('virtualservice?page_size=1000&page=' + str(page))
        for vs in resp.json()['results']:
            vs_list.update({vs['name']:vs['uuid']})
        if 'next' in resp.json():
            page = page + 1
        else:
            break
    print 'done'

    dic = {}
    print 'Getting Metrics info',
    for k,v in vs_list.items():
        name = k.encode('ascii','ignore')
        uuid = v.encode('ascii','ignore')
        avg_value = metrics(uuid, m_id, tenant, step, limits)
        dic.update({name:avg_value})
        sys.stdout.write('.')
        sys.stdout.flush()
    print 'done\n'

    print '\nTotal VIPs in Tenant:', tenant, ':', len(vs_list)
    print 'Average Values over past', (step * limits)/(60*60), 'hours (', (step * limits)/60, 'min) Collected Samples:', limits, 'each after:', step, 'sec'
    top_vips(dic, m_id)
Beispiel #3
0
import ffmpeg
import requests
import sys
import os
import threadpool
import platform
from requests import urllib3

urllib3.disable_warnings()

from datetime import datetime


def concat(video_name='out.mp4'):
    current_path = sys.path[0] + '/'
    if platform.system() == 'Windows':
        current_path = sys.path[0].replace('\\', '\\\\') + '\\\\'
    input_file = current_path + 'ts.txt'
    output_file = current_path + video_name
    try:
        out, err = (
            ffmpeg.input(input_file, f='concat', safe='0').output(output_file, c='copy').run(quiet=False,
                                                                                             overwrite_output=True)
        )
    except Exception as e:
        print(e)


def download(url, thread_num=5):
    prefix = url[:url.rfind('/') + 1]
    headers = {
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import shutil
import tarfile

import requests
from requests import urllib3
urllib3.disable_warnings(urllib3.exceptions.SubjectAltNameWarning)


def upload_part(url, params, headers, data, parts, verify):
    print("Sending part nr {} of current upload...".format(
        params['partNumber']))
    response = requests.put(url + "/upload",
                            data,
                            headers=headers,
                            params=params,
                            verify=verify)
    if response.status_code != 200:
        print("Could not upload part nr : {}".format(params['partNumber']))
        raise Exception(response)

    print("Part nr {} of current upload sent successfully".format(
def main():
    parser = argparse.ArgumentParser(
        description="AVISDK based Script to patch a VS to enable scaleout_ecmp"
    )
    parser.add_argument("-u",
                        "--username",
                        required=False,
                        help="Login username")
    parser.add_argument("-p",
                        "--password",
                        required=True,
                        help="Login password")
    parser.add_argument("-c",
                        "--controller",
                        required=True,
                        help="Controller IP address")
    parser.add_argument("-t", "--tenant", required=False, help="Tenant Name")
    parser.add_argument("-v",
                        "--vs_name",
                        required=True,
                        help="Virtual Service Name")
    parser.add_argument("-a",
                        "--api_version",
                        required=False,
                        help="Api Version")

    args = parser.parse_args()

    # Defining required variable from required arguments
    user = str([args.username if args.username else "admin"][0])
    password = args.password
    controller = args.controller
    tenant = str([args.tenant if args.tenant else "admin"][0])
    api_version = str([args.api_version if args.api_version else "17.2.1"][0])
    vs_name = args.vs_name

    # Get Api Session
    urllib3.disable_warnings()
    api = ApiSession.get_session(controller,
                                 user,
                                 password,
                                 tenant=tenant,
                                 api_version=api_version)

    # Getting VS object by name
    resp = api.get_object_by_name("virtualservice", vs_name)

    # Checking if scaleout_ecmp is already enabled, then no need to patch. Preform exit
    # Get the VS uuid to perform patch
    if resp['scaleout_ecmp']:
        print "The Intended VS: %s has scaleout_ecmp enabled already." % vs_name
        exit(1)
    else:
        vs_uuid = resp['uuid']

    # Defining data to patch
    data = {"replace": {"scaleout_ecmp": "True"}}

    # Patching the VS to set scaleout_ecmp as True
    resp = api.patch('virtualservice/%s' % vs_uuid, data=data)
    if resp.status_code in range(200, 299):
        print "\n"
        print "VS patched successfully, Dumping updated VS json object below :"
        print "\n===========\n"
        print json.dumps(json.loads(resp.text), indent=2)
        print "\n===========\n"
    else:
        print('Error in patching virtualservice :%s' % resp.text)
        exit(0)