From 70f5215b3065007069175df9a7bdcac44b13ce05 Mon Sep 17 00:00:00 2001 From: Abhishek Veeramalla Date: Mon, 27 Nov 2023 16:05:06 +0000 Subject: [PATCH 1/6] add files for day-14 --- Day-14/examples/create-jira.py | 54 ++++++++++++++++++++++++++++++++ Day-14/examples/list_projects.py | 28 +++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Day-14/examples/create-jira.py create mode 100644 Day-14/examples/list_projects.py diff --git a/Day-14/examples/create-jira.py b/Day-14/examples/create-jira.py new file mode 100644 index 00000000..e9618ad0 --- /dev/null +++ b/Day-14/examples/create-jira.py @@ -0,0 +1,54 @@ +# This code sample uses the 'requests' library: +# http://docs.python-requests.org +import requests +from requests.auth import HTTPBasicAuth +import json + +url = "https://veeramallaabhishek.atlassian.net/rest/api/3/issue" + +API_TOKEN = "" + +auth = HTTPBasicAuth("", API_TOKEN) + +headers = { + "Accept": "application/json", + "Content-Type": "application/json" +} + +payload = json.dumps( { + "fields": { + "description": { + "content": [ + { + "content": [ + { + "text": "My first jira ticket", + "type": "text" + } + ], + "type": "paragraph" + } + ], + "type": "doc", + "version": 1 + }, + "project": { + "key": "AB" + }, + "issuetype": { + "id": "10006" + }, + "summary": "First JIRA Ticket", + }, + "update": {} +} ) + +response = requests.request( + "POST", + url, + data=payload, + headers=headers, + auth=auth +) + +print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))) \ No newline at end of file diff --git a/Day-14/examples/list_projects.py b/Day-14/examples/list_projects.py new file mode 100644 index 00000000..93ecf2ca --- /dev/null +++ b/Day-14/examples/list_projects.py @@ -0,0 +1,28 @@ +# This code sample uses the 'requests' library: +# http://docs.python-requests.org +import requests +from requests.auth import HTTPBasicAuth +import json + +url = "https://veeramallaabhishek.atlassian.net/rest/api/3/project" + +API_TOKEN="" + +auth = HTTPBasicAuth("", API_TOKEN) + +headers = { + "Accept": "application/json" +} + +response = requests.request( + "GET", + url, + headers=headers, + auth=auth +) + +output = json.loads(response.text) + +name = output[0]["name"] + +print(name) \ No newline at end of file From 1cc122bb6ee06447e6778949c826720900b752b2 Mon Sep 17 00:00:00 2001 From: Abhishek Veeramalla Date: Thu, 30 Nov 2023 13:24:07 +0530 Subject: [PATCH 2/6] Update README.md --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 23ecf82a..f32309c8 100644 --- a/README.md +++ b/README.md @@ -62,38 +62,38 @@ - Practice exercises and examples: - Example: Print list of files in the list of folders provided -## Day 11: Working with Dictionaries and Sets +## Day 11: Working with Dictionaries and Sets (Project-1) - Dictionaries and key-value pairs. - Sets and set operations. - Practice exercises and examples: - Example: Managing a dictionary of server configurations and optimizing retrieval. -## Day 12: Python Tasks for DevOps (Part 1) - File Operations +## Day 12: Python Tasks for DevOps (Part 1) - File Operations (Project-2) - Introduction to File Operations and Boto3. - Automating File operations. - Practice exercises and examples: - Example: Update a server resources in the server.conf file up on external notification. -## Day 13: Python Tasks for DevOps (Part 2) +## Day 13: Python Tasks for DevOps (Part 2) (Project-3) - Using Fabric for remote task automation. - AWS automation with Boto3. - Managing EC2 instances, S3 buckets, and more. - Practice exercises and examples: - Example: Creating a aws script for deploying applications to remote servers. -## Day 14: Working with RESTful APIs +## Day 14: Github-JIRA intergration Project - (Project-4) - Introduction to RESTful APIs. - Making HTTP requests using Python. - Parsing JSON responses and error handling. - Practice exercises and examples: - - Example: Developing a script to monitor RESTful API endpoints for your DevOps tools. + - Example: Write a Python API which listens on a github comment and creates a ticket in JIRA. -## Day 15: Data Serialization and Configuration Files -- Serializing and deserializing data (JSON, YAML). -- Managing configuration data. -- DevOps use cases for configuration files. +## Day 15: Github-JIRA intergration Project - (Project-4) - (Part-2) +- Introduction to Flask. +- Write your first API in python. +- How to handle API calls and deploy your API to a server. - Practice exercises and examples: - - Example: Building a configuration manager to handle application settings in JSON format. + - Example: Write a Python API which listens on a github comment and creates a ticket in JIRA. ## Day 16: Automation with Cron Jobs - Scheduling automated tasks using cron. From b5e1c516754107dad67bf1b9396e17f383349b12 Mon Sep 17 00:00:00 2001 From: Abhishek Veeramalla Date: Thu, 30 Nov 2023 16:53:09 +0000 Subject: [PATCH 3/6] add files for day-15 --- Day-14/README.md | 1 + Day-15/README.md | 1 + Day-15/examples/hello-world.py | 10 ++++++ Day-15/github-jira.py | 65 ++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 Day-15/examples/hello-world.py create mode 100644 Day-15/github-jira.py diff --git a/Day-14/README.md b/Day-14/README.md index e69de29b..9b1a3075 100644 --- a/Day-14/README.md +++ b/Day-14/README.md @@ -0,0 +1 @@ +# Github-JIRA intergration Project \ No newline at end of file diff --git a/Day-15/README.md b/Day-15/README.md index e69de29b..781a8c42 100644 --- a/Day-15/README.md +++ b/Day-15/README.md @@ -0,0 +1 @@ +# Github-JIRA intergration Project - (Part-2) \ No newline at end of file diff --git a/Day-15/examples/hello-world.py b/Day-15/examples/hello-world.py new file mode 100644 index 00000000..3d602756 --- /dev/null +++ b/Day-15/examples/hello-world.py @@ -0,0 +1,10 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World!' + +if __name__ == '__main__': + app.run("0.0.0.0") diff --git a/Day-15/github-jira.py b/Day-15/github-jira.py new file mode 100644 index 00000000..c5003813 --- /dev/null +++ b/Day-15/github-jira.py @@ -0,0 +1,65 @@ +# This code sample uses the 'requests' library: +# http://docs.python-requests.org +import requests +from requests.auth import HTTPBasicAuth +import json +from flask import Flask + +app = Flask(__name__) + +# Define a route that handles GET requests +@app.route('/createJira', methods=['POST']) +def createJira(): + + url = "https://veeramallaabhishek.atlassian.net/rest/api/3/issue" + + API_TOKEN="" + + auth = HTTPBasicAuth("", API_TOKEN) + + headers = { + "Accept": "application/json", + "Content-Type": "application/json" + } + + payload = json.dumps( { + "fields": { + "description": { + "content": [ + { + "content": [ + { + "text": "Order entry fails when selecting supplier.", + "type": "text" + } + ], + "type": "paragraph" + } + ], + "type": "doc", + "version": 1 + }, + "project": { + "key": "AB" + }, + "issuetype": { + "id": "10006" + }, + "summary": "Main order flow broken", + }, + "update": {} + } ) + + + response = requests.request( + "POST", + url, + data=payload, + headers=headers, + auth=auth + ) + + return json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")) + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) \ No newline at end of file From 0d962b852e0b2a909da49fb1f4332e221f01cb4b Mon Sep 17 00:00:00 2001 From: Abhishek Veeramalla Date: Mon, 11 Dec 2023 20:30:42 +0530 Subject: [PATCH 4/6] Update README.md --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f32309c8..0dc09cb5 100644 --- a/README.md +++ b/README.md @@ -95,12 +95,8 @@ - Practice exercises and examples: - Example: Write a Python API which listens on a github comment and creates a ticket in JIRA. -## Day 16: Automation with Cron Jobs -- Scheduling automated tasks using cron. -- Creating Python scripts for scheduled automation. -- Handling periodic tasks and reports. -- Practice exercises and examples: - - Example: Using cron and Python to schedule regular backups of your data. +## Day 16: Python Interview Questions & Answers +- Beginner and intermediate Level ## Day 17: Python Interview Questions & Answers - +- Advanced Level From 7a2982acfe5e3b03de4db121366332e0e6140ce7 Mon Sep 17 00:00:00 2001 From: Abhishek Veeramalla Date: Mon, 11 Dec 2023 20:48:57 +0530 Subject: [PATCH 5/6] Update README.md --- Day-16/README.md | 244 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) diff --git a/Day-16/README.md b/Day-16/README.md index e69de29b..d8728f2d 100644 --- a/Day-16/README.md +++ b/Day-16/README.md @@ -0,0 +1,244 @@ +# Interview Questions (Beginner and Intermediate) + +## Describe a real-world example of how you used Python to solve a DevOps challenge. + +- Here you can talk about the projects that we did in this series + - GitHub Webhooks + - JIRA integration + - File Operations + +## Discuss the challenges that you faced while using Python for DevOps and how did you overcome it. + +- Here you can mention about a challenge that you faced while implementating a Python project for DevOps that we learnt. + +## How can you secure your Python code and scripts? + +- Handle any sensetive information using Input variables, command line arguments or env vars. + +## Explain the difference between mutable and immutable objects. + +In Python, mutable objects can be altered after creation, while immutable objects cannot be changed once created. For instance: + +Mutable objects like lists can be modified: + +``` +my_list = [1, 2, 3] +my_list[0] = 0 # Modifying an element in the list +print(my_list) # Output: [0, 2, 3] +``` + +Immutable objects like tuples cannot be altered: + +``` +my_tuple = (1, 2, 3) +# Attempting to change a tuple will result in an error +# my_tuple[0] = 0 +``` + +## Differentiate between list and tuple in Python. + +Lists are mutable and typically used for storing collections of items that can be changed, while tuples are immutable and commonly used to store collections of items that shouldn't change. Examples: + +List: + +``` +my_list = [1, 2, 3] +my_list.append(4) # Modifying by adding an element +print(my_list) # Output: [1, 2, 3, 4] +``` + +Tuple: + +``` +my_tuple = (1, 2, 3) +# Attempting to modify a tuple will result in an error +# my_tuple.append(4) +``` + +## Explain the use of virtualenv. + +Virtualenv creates isolated Python environments, allowing different projects to use different versions of packages without conflicts. Example: + +Creating a virtual environment: + +### Creating a virtual environment named 'myenv' +virtualenv myenv + +Activating the virtual environment: + +### On Windows +``` +myenv\Scripts\activate +``` + +### On Unix or MacOS +``` +source myenv/bin/activate +``` + +## What are decorators in Python? + +Decorators modify the behavior of functions. They take a function as an argument, add some functionality, and return another function without modifying the original function's code. Example: + +Defining a simple decorator: + +``` +def my_decorator(func): + def wrapper(): + print("Something is happening before the function is called.") + func() + print("Something is happening after the function is called.") + return wrapper + +@my_decorator +def say_hello(): + print("Hello!") + +say_hello() +``` + +## How does exception handling work in Python? + +Exception handling in Python uses try, except, else, and finally blocks. Example: + +Handling division by zero exception: + +``` +try: + result = 10 / 0 +except ZeroDivisionError: + print("Division by zero is not allowed.") +else: + print("Division successful:", result) +finally: + print("Execution completed.") +``` + +## What's the difference between append() and extend() for lists? + +append() adds a single element to the end of a list, while extend() adds multiple elements by appending elements from an iterable. Example: + +Using append(): +``` +my_list = [1, 2, 3] +my_list.append(4) +print(my_list) # Output: [1, 2, 3, 4] +``` + +Using extend(): + +``` +my_list = [1, 2, 3] +my_list.extend([4, 5]) +print(my_list) # Output: [1, 2, 3, 4, 5] +``` + +## Explain the use of lambda functions in Python. + +Lambda functions are anonymous functions used for short tasks. Example: + +Defining and using a lambda function: + +``` +square = lambda x: x**2 +print(square(5)) # Output: 25 +``` + +## What are the different types of loops in Python? + +Python has for loops and while loops. + +Example: + +Using for loop: +``` +for i in range(5): + print(i) +``` + +Using while loop: +``` +i = 0 +while i < 5: + print(i) + i += 1 +``` + +## Explain the difference between == and is operators. + +The == operator compares the values of two objects, while the is operator checks if two variables point to the same object in memory. + +Example: + +Using ==: + +``` +a = [1, 2, 3] +b = [1, 2, 3] +print(a == b) # Output: True (because values are equal) +``` + +Using is: + +``` +a = [1, 2, 3] +b = a +print(a is b) # Output: True (because they reference the same object) +``` + +## What is the use of the pass keyword? + +The pass keyword is a no-operation placeholder used when a statement is syntactically needed but no action is required. Example: + +Using pass: +``` +def placeholder_function(): + pass # To be implemented later +``` + +## What is the difference between global and local variables? + +Global variables are defined outside functions and can be accessed anywhere in the code, while local variables are defined inside functions and are only accessible within that function's scope. Example: + +Using a global variable: +``` +global_var = 10 + +def my_function(): + print(global_var) + +my_function() # Output: 10 +``` + +Using a local variable: + +``` +def my_function(): + local_var = 5 + print(local_var) + +my_function() # Output: 5 +# Attempting to access local_var outside the function will result in an error +``` + +## Explain the difference between open() and with open() statement. + +open() is a built-in function used to open a file and return a file object. +However, it's crucial to manually close the file using file_object.close(). +Conversely, with open() is a context manager that automatically handles file closure, ensuring clean-up even if exceptions occur. + +Example: +``` +file = open('example.txt', 'r') +content = file.read() +file.close() +``` + +Using with open(): +``` +with open('example.txt', 'r') as file: + content = file.read() +# File is automatically closed when the block exits +``` + + From 14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb Mon Sep 17 00:00:00 2001 From: Abhishek Veeramalla Date: Wed, 3 Apr 2024 21:34:24 +0530 Subject: [PATCH 6/6] simple python app --- simple-python-app/app.py | 10 ++++++++++ simple-python-app/requirements.txt | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 simple-python-app/app.py create mode 100644 simple-python-app/requirements.txt diff --git a/simple-python-app/app.py b/simple-python-app/app.py new file mode 100644 index 00000000..0c9d9e60 --- /dev/null +++ b/simple-python-app/app.py @@ -0,0 +1,10 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World!' + +if __name__ == '__main__': + app.run(debug=True, host='0.0.0.0', port=8000) \ No newline at end of file diff --git a/simple-python-app/requirements.txt b/simple-python-app/requirements.txt new file mode 100644 index 00000000..fdceace4 --- /dev/null +++ b/simple-python-app/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.1.0 +Werkzeug==2.2.2 \ No newline at end of file