Wednesday, 10 April 2019

Python Standard Library for data science and ML



NumPy
NumPy (or Numerical Python) is one of the principle packages for data science applications. It’s often used to process large multidimensional arrays, extensive collections of high-level mathematical functions, and matrices. Implementation methods also make it easy to conduct multiple operations with these objects.
There have been many improvements made over the last year that have resolved several bugs and compatibility issues. NumPy is popular because it can be used as a highly efficient multi-dimensional container of generic data. It’s also an excellent library as it makes data analysis simple by processing data faster while using a lot less code than lists.
Pandas
Pandas is a Python library that provides highly flexible and powerful tools and high-level data structures for analysis. Pandas is an excellent tool for data analytics because it can translate highly complex operations with data into just one or two commands.
Pandas comes with a variety of built-in methods for combining, filtering, and grouping data. It also boasts time-series functionality that is closely followed by remarkable speed indicators.
SciPy
SciPy is another outstanding library for scientific computing. It’s based on NumPy and was created to extend its capabilities. Like NumPy, SciPy’s data structure is also a multidimensional array that’s implemented by NumPy.
The SciPy package contains powerful tools that help solve tasks related to integral calculus, linear algebra, probability theory, and much more.

Python Interview Questions And Answers Part 1



What is Python? 


  • Python is a high-level, interpreted, interactive and object-oriented scripting language. 
  • Python is designed to be highly readable. 
  • It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.
What are the supported data types in Python?

          Python has five standard data types −
  • Numbers
  • String
  • List
  • Tuple
  • Dictionary

What is the difference between list and tuples?

      
LISTTUPLES
Lists are mutable i.e they can be edited.Tuples are immutable (tuples are lists which can’t be edited).
Lists are slower than tuples.Tuples are faster than list.
Syntax: list_1 = [10, ‘Chelsea’, 20]Syntax: tup_1 = (10, ‘Chelsea’ , 20)

How is memory managed in Python?

      Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap.


What is dictionary in Python?

The built-in datatypes in Python is called dictionary. It defines one-to-one relationship between keys and values. Dictionaries contain pair of keys and their corresponding values. 

Example :
dict={‘Country’:’India’,’Capital’:’Delhi’,’PM’:’Modi’}
print dict[Country]





Tuesday, 26 March 2019

Ansible playbook to add and delete static route on paloalto firewall



---
 - name: modifyRoutes
   gather_facts: no
   connection: local
   hosts: PaloAlto
 
   vars:
     action: StaticRouteAddition
     vdom: root
     interfacename: ['interface port-channel 35.3102']
     interfacename2: port-channel 35.3102
     ip: 192.168.101.101
     mask: 255.255.255.0
     speedmode: auto
     duplexmode: auto
     securityinterfacename: inside
     securitylevelnumber: 0
     devicetype: PALOALTO
     routeModificationType: addition
     routeMode:
     hostIPAddress: 192.168.101.101
     hostIPMask: 255.255.255.0
     nextHopIP: 192.168.102.102
     adminDistance: 10
     destIPAddress:
     destIPMask:
     destGatewayIPAddress:
     distanceValue:
     comments:
     portNum:

     cli:
      host:
      username:
      password:
      auth_pass:
      authorize: yes
      timeout: 100

   tasks:

    - name: StaticRouteAddition
      when: action == "StaticRouteAddition" and devicetype == "PALOALTO"
      panos_op:
         commands:
            - "set networkk virtual-router {{vrName}} routing-table ip static-route {{routerName}} nexthop ip-address {{nxtHOPAddress}}"
         provider: "{{ cli }}"


    - name: StaticRouteDeletion
      when: action == "StaticRouteAddition" and devicetype == "PALOALTO"
      panos_op:
         commands:
            - "unset networkk virtual-router {{vrName}} routing-table ip static-route {{routerName}} nexthop ip-address {{nxtHOPAddress}}"
         provider: "{{ cli }}"

Ansible playbook to add and delete static route on fortigate firewall



---
 - name: modifyRoutes
   gather_facts: no
   connection: local
   hosts: FORTINET
 
   vars:
     action: StaticRouteAddition
     vdom: root
     interfacename: ['interface port-channel 35.3102']
     interfacename2: port-channel 35.3102
     ip: 192.168.101.101
     mask: 255.255.255.0
     speedmode: auto
     duplexmode: auto
     securityinterfacename: inside
     securitylevelnumber: 0
     devicetype: FORTINET
     routeModificationType: addition
     routeMode:
     hostIPAddress: 192.168.101.101
     hostIPMask: 255.255.255.0
     nextHopIP: 192.168.102.102
     adminDistance: 10
     destIPAddress:
     destIPMask:
     destGatewayIPAddress:
     distanceValue:
     comments:
     portNum:

     cli:
      host:
      username:
      password:
      auth_pass:
      authorize: yes
      timeout: 100

   tasks:

    - name: StaticRouteAddition
      when: action == "StaticRouteAddition" and devicetype == "FORTINET"
      fortios_config:
         vdom: "{{vdomname}}"
         commands:
            - config router static
            - "edit {{portNum}}"
            - "set dst {{$destIPAddress}}"
            - "set gateway {{destGatewayIPAddress}}"
            - "set device {{interfacename2}}"
            - "set comment {{comment}}"
         provider: "{{ cli }}"


    - name: StaticRouteDeletion
      when: action == "StaticRouteDeletion" and devicetype == "FORTINET"
      fortios_config:
         vdom: "{{vdomname}}"
         commands:
            - config router static
            - "edit {{portNum}}"
            - "set dst {{$destIPAddress}}"
            - "set gateway {{destGatewayIPAddress}}"
            - "set device {{interfacename2}}"
            - "set comment {{comment}}"
         provider: "{{ cli }}"

Ansible playbook to add and delete static route on cisco ASA



---
 - name: modifyRoutes
   gather_facts: no
   connection: local
   hosts: ASA
 
   vars:
     action: StaticRouteAddition
     contextname: fw-automation-test
     interfacename: ['interface port-channel 35.3102']
     interfacename2: port-channel 35.3102
     ip: 192.168.101.101
     mask: 255.255.255.0
     speedmode: auto
     duplexmode: auto
     securityinterfacename: inside
     securitylevelnumber: 0
     devicetype: ciscoASA
     routeModificationType: addition
     routeMode:
     hostIPAddress: 192.168.101.101
     hostIPMask: 255.255.255.0
     nextHopIP: 192.168.102.102
     adminDistance: 10
     destIPAddress:
     destIPMask:
     destGatewayIPAddress:
     distanceValue:
     comments:

     cli:
      host:
      username:
      password:
      auth_pass:
      authorize: yes
      timeout: 100

   tasks:

    - name: StaticRouteAddition
      when: action == "StaticRouteAddition" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
            - "route {{interfacename2}} {{hostIPAddress}} {{hostIPMask}} {{nextHopIP}} {{adminDistance}}"
         provider: "{{ cli }}"


    - name: StaticRouteDeletion
      when: action == "StaticRouteDeletion" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
            - "no route {{interfacename2}} {{hostIPAddress}} {{hostIPMask}} {{nextHopIP}} {{adminDistance}}"
         provider: "{{ cli }}"

anisible playbook to manage paloalto interface



---
 - name: PALOALTOInterfaceManagement
   gather_facts: no
   connection: local
   hosts: PALOALTO
 
   vars:
     action: setIPAddress
     vdomname: root
     interfacename: ['interface port-channel 35.3102']
     ip: 192.168.101.101
     mask: 255.255.255.0
     speedmode: auto
     duplexmode: auto
     securityinterfacename: inside
     securitylevelnumber: 0
     devicetype: fortigate
     vlanNumber: 10
     vrName: test
   cli:
      host:
      username: admin
      password: admin@123
      timeout: 30

    - name: setIPAddress 
      when: action == "setIPAddress" and devicetype == "paloalto"
      panos_interface:
         commands:
            - "set network interface {{interfacename}} layer3 ip {{ip}}"


    - name: unsetIPAddress
      when: action == "unsetIPAddress" and devicetype == "paloalto"
      panos_interface:
         commands:
            - "unset network interface {{interfacename}} layer3 ip {{ip}}"

   - name: createSubinterface
      when: action == "createSubinterface" and devicetype == "paloalto"
      pnos_interface:
         commands:
            - "set network interface {{interfacename}} layer3 units 1 tag {{vlanNumber}}"
            - "set network interface {{interfacename}} layer3 units 1 tag {{ip}}"

   - name: addingInterfaceToARouter
      when: action == "addingInterfaceToARouter" and devicetype == "paloalto"
      pnos_interface:
         commands:
            - "set network virtual-router {{vrName}} interface{{interfacename}} layer3 units 1 tag {{ip}}"

ansible playbook to manage fortigate interface


---
 - name: FORTGATEInterfaceManagement
   gather_facts: no
   connection: local
   hosts: FORTTINET
 
   vars:
     action: enableinterface
     vdomname: root
     interfacename: ['interface port-channel 35.3102']
     ip:
     mask: 255.255.255.0
     speedmode: auto
     duplexmode: auto
     securityinterfacename: inside
     securitylevelnumber: 0
     devicetype: fortigate
     cli:
      host:
      username: admin
      password: admin@123
      timeout: 30

    - name: setIPAddress 
      when: action == "setIPAddress" and devicetype == "fortinet"
      fortios_config:
         vdom: "{{vdom}}"
         commands:
            - config system interface
            - edit "interfacename"
            - set ip "ip" "mask"
         provider: "{{ cli }}"

    - name: unsetIPAddress
      when: action == "unsetIPAddress" and devicetype == "fortinet"
      fortios_config:
         vdom: "{{vdom}}"
         commands:
            - config system interface
            - "edit {{interfacename}}"
            - "unset ip {{ip}} {{mask}}"
         provider: "{{ cli }}"

    - name: setSpeed
      when: action == "setSpeed" and devicetype == "fortinet"
      fortios_config:
         vdom: "{{vdomname}}"
         commands:
             - config sys global
             - set interface-switch-speed "{{speedmode}}"
         provider: "{{ cli }}"

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...