Posts

Showing posts from June, 2019

DevNet 103: Network Automation Using Python

Image
 Configure OSPF on Cisco Router by Python Configure R1: import paramiko import time import getpass ip_address = "192.168.23.103" username = raw_input("Enter your username of : " + ip_address + ": ") password = getpass.getpass() ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip_address,username=username,password=password) print "Successful connection " + ip_address remote_connection = ssh_client.invoke_shell() print "Configure OSPF " remote_connection.send('en\n') time.sleep(1) recv = remote_connection.recv(9999) remote_connection.send('cisco\n') time.sleep(1) recv = remote_connection.recv(9999) remote_connection.send("configure terminal\n") remote_connection.send("interface loop 0\n") remote_connection.send("ip address 1.1.1.1 255.255.255.0\n") remote_connection.send("interface g1/0\n

DevNet 102: Network Automation Using Python

Image
                        How to add  vlans on Multi-Switches  by python Add commands to two switches: ip name-server 8.8.8.8 ip domain name cloud.me username ahmed password cisco enable password cisco line vty 0 4 login local transport input all exit crypto key generate rsa ip ssh version 2 Create text file contain IPs of switches: root@kali:/home# vim myswitches.txt 192.168.23.100 192.168.23.101 Add VLANs on two switches by python script: import paramiko import time import getpass # Open file with list of switches f = open("myswitches.txt") # enter to each switch and configure it: for line in f: ip_address = line.strip() username = raw_input("Enter your username of : " + ip_address + ": ") password = getpass.getpass() ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip_address,username=username,password=password)

DevNet 101: Network Automation Using Python

Image
How to add  vlans on one switch by python Add VLANs on ESW1 by python script: import paramiko import time ip_address = "192.168.23.101" username = "ahmed" password = "cisco" ssh_client =paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip_address,username=username,password=password) print "Successful connection", ip_address remote_connection = ssh_client.invoke_shell() remote_connection.send('en\n') time.sleep(1) recv = remote_connection.recv(9999) remote_connection.send('cisco\n') time.sleep(1) recv = remote_connection.recv(9999) remote_connection.send("configure terminal\n") remote_connection.send("interface loop 0\n") remote_connection.send("ip address 1.1.1.1 255.255.255.255\n") remote_connection.send("interface loop 1\n") remote_connection.send("ip address 2.2.2.2 255.255.255.255\n") remote_co

Kubernetes 102: Exposing an External IP Address to Access an Application in a Cluster

Image
Get kubernetes nodes : k3os-3249 [~]$ kubectl get nodes NAME STATUS ROLES AGE VERSION k3os-22710 Ready <none> 10m v1.14.1-k3s.4 k3os-3249 Ready <none> 17h v1.14.1-k3s.4 Get cluster info: k3os-3249 [~]$ kubectl cluster-info Kubernetes master is running at https://localhost:6443 CoreDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy Creating a service for an application running in two pods: k3os-3249 [ ~ ]$ kubectl run --generator=run-pod/v1 hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080 deployment.apps/hello-world created Display information about the Deployment: k3os-3249 [/kubernetes]$ kubectl get all NAME READY STATUS RESTARTS AGE pod/hello-world-68ff65cf7-bxg6j 0/1 ContainerCreating 0 29s pod/hello-world-68ff6

Ansible 102: copy repositories file and install packages

Image
How to create repo file and install packages using ansible  We need  Create yml files on ansible machine. can add any IPs of machines in hosts file Create local repo file: [root@cloud ansible]# vim /etc/ansible/local.repo [httpRepo] name=http repository baseurl=http://172.17.7.119/repos/rhel/7 enable=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release Create hosts file: [root@cloud ansible]# vim /etc/ansible/hosts [update] 172.17.7.1 172.17.7.2 172.17.7.3 172.17.7.4 172.17.7.5 172.17.7.6 172.17.7.7 172.17.7.8 ...... ...... ######### Create YAML file to copy repo file from local to remote machines  [root@cloud ansible]# vim /etc/ansible/copy-repofile.yaml - hosts: update   tasks:   - name: Ansible copy files remote to remote     copy:       src: /etc/ansible/local.repo       dest: /etc/yum.repos.d/ Run YAML file by ansible: [root@cloud ansible]# ansible-playbook  -s    copy-repofile.yaml