[
  {
    "path": "README.md",
    "content": "\n# Python for DevOps: 8-Week Learning Roadmap\n\nIf you want to understand the importance of python for DevOps, please read the [detailed python for DevOps guide](https://devopscube.com/python-for-devops/).\n\n## 📌 Overview\n\nThis roadmap is designed to help DevOps Engineers and Platform Engineers master Python for automation, cloud operations, infrastructure as code, and Kubernetes. The curriculum includes hands-on projects that mimic real-world DevOps tasks using industry tools like Docker, Terraform, Kubernetes, and CI/CD pipelines.\n\nBy the end of this roadmap, you'll:\n- Automate repetitive tasks with Python\n- Work with cloud APIs and infrastructure automation\n- Build Python-based DevOps tools and microservices\n- Deploy containerized apps with Docker and Kubernetes\n- Use AI-powered tools like LlamaIndex & GenAI for DevOps\n- Be fully prepared for Python-based DevOps interviews\n\n## 👨‍💻 Python Learning Resources\n\nIf you are looking for a guided way to learn Python from scratch., I recommend the following resources.\n\n1. [learnpython.org](https://www.learnpython.org/)\n2. [Learn Python 3 from Scratch](https://www.educative.io/courses/learn-python-3-from-scratch?aff=KNLz)\n3. [Python for Beginners – Full Video Course](https://www.youtube.com/watch?v=eWRfhZUzrAc)\n\n## 🚀 Week 1: Python Fundamentals for DevOps\n\n### 🎯 Goal: Learn the basics of Python for scripting and automation.\n\n✅ Python syntax, variables, loops, functions, and error handling  \n✅ Working with files (reading, writing, and parsing logs)  \n✅ Interacting with OS processes (`subprocess`, `os` modules)  \n✅ Installing and managing packages with `pip` and `venv`  \n\n**🔨 Hands-on Project:**\n- Write a Python script to automate log parsing from `/var/log/` and extract useful insights.\n- Create a script that monitors CPU & memory usage using the `psutil` library.\n\n## 🛠 Week 2: Automating DevOps Tasks with Python\n\n### 🎯 Goal: Automate daily DevOps operations.\n\n✅ Working with APIs (`requests` library for REST APIs)  \n✅ Automating SSH tasks (`paramiko` for remote execution)  \n✅ Automating cloud operations with AWS/GCP SDKs (`boto3` and `google-cloud-sdk`)  \n✅ Writing CLI tools with `argparse`  \n\n**🔨 Hands-on Project:**\n- Build a Python script that automates AWS EC2 instance management (start, stop, terminate instances).\n- Create a CLI tool that checks the status of Kubernetes pods using `kubectl` and `subprocess`.\n\n## 🐳 Week 3: Docker & Python for Containerized Applications\n\n### 🎯 Goal: Learn to containerize Python applications for DevOps automation.\n\n✅ Writing Dockerfiles for Python apps  \n✅ Running Python scripts inside containers  \n✅ Docker Compose for multi-container apps  \n✅ Working with Python SDK for Docker (`docker-py`)  \n\n**🔨 Hands-on Project:**\n- Build a Python script to manage Docker containers (start, stop, restart, delete containers).\n- Create a Flask API that returns system metrics (CPU, RAM) and deploy it in a Docker container.\n\n## 🔧 Week 4: Infrastructure as Code (IaC) with Python\n\n### 🎯 Goal: Automate infrastructure provisioning with Python.\n\n✅ Terraform automation with Python (`python-terraform`)  \n✅ Working with Ansible and Python (`ansible-runner`)  \n✅ Writing Python scripts to automate Kubernetes YAML generation  \n✅ Using `Fabric` for remote automation  \n\n**🔨 Hands-on Project:**\n- Write a Python script that provisions AWS infrastructure (VPC, EC2, S3) using Terraform.\n- Automate Ansible playbook execution using Python.\n\n## ☸️ Week 5: Kubernetes Automation with Python\n\n### 🎯 Goal: Automate Kubernetes operations using Python.\n\n✅ Working with Kubernetes Python SDK (`kubernetes` library)  \n✅ Managing Kubernetes objects dynamically with Python  \n✅ Writing Admission Webhooks in Python  \n✅ Automating Helm deployments with Python  \n\n**🔨 Hands-on Project:**\n- Write a Python script that dynamically creates and deletes Kubernetes namespaces.\n- Build a Mutating Admission Webhook to enforce security policies in a cluster.\n\n## 🔍 Week 6: Python for Security & Monitoring in DevOps.\n\n### 🎯 Goal: Secure infrastructure and monitor logs with Python.\n\n✅ Parsing and analyzing logs (`loguru`, `logging`)  \n✅ Security automation (checking misconfigurations with `PyInfra`)  \n✅ Python for **SIEM (Security Information & Event Management)**  \n✅ Automating RBAC checks for Kubernetes  \n\n**🔨 Hands-on Project:**\n- Build a tool that checks Kubernetes RBAC permissions and finds over-privileged service accounts.\n- Automate security scanning of container images using Trivy and Python.\n\n## 🤖 Week 7: GenAI & LlamaIndex for DevOps\n\n### 🎯 Goal: Use AI for DevOps workflows with Python.\n\n✅ Introduction to **LlamaIndex & GenAI for DevOps**  \n✅ Automating incident response with AI-driven bots  \n✅ Generating YAML/JSON configurations using AI  \n✅ AI-powered log analysis using `LangChain` & `OpenAI API`  \n\n**🔨 Hands-on Project:**\n- Build an AI-powered chatbot that suggests Kubernetes troubleshooting steps.\n- Develop an AI-based log anomaly detection system that detects security threats.\n\n\n## 🤖 Week 8: Agentic AI \n\n### 🎯 Goal: Implement advanced AI-driven DevOps automation\n\n✅ Understanding Agentic AI for DevOps  \n✅ AI-driven CI/CD pipeline optimization  \n✅ Automating incident remediation using AI agents  \n✅ Integrating AI with monitoring tools (Prometheus, Grafana)  \n\n## 💼 Final Capstone Projects\n\n1️⃣ **DevOps Dashboard API:** Build a FastAPI app that displays real-time Kubernetes metrics.  \n2️⃣ **Self-Healing Kubernetes System:** AI-powered Kubernetes operator that auto-heals pods based on anomaly detection.  \n3️⃣ **Intelligent CI/CD Analyzer:** AI-driven CI/CD log analyzer that suggests fixes based on failure patterns.\n\n## 📢 Next Steps\n\n- Contribute to Open Source Python DevOps projects\n- Deploy Python automation scripts in production Kubernetes environments\n- Prepare for DevOps interviews with Python scripting questions\n- Build AI-powered DevOps tools using LangChain & LlamaIndex\n\n🔥 Ready to Master Python for DevOps? Let’s Get Started! 🚀\n\n"
  },
  {
    "path": "awsrdsmysqlp.py",
    "content": "import boto3\nimport json\nimport mysql.connector\nimport tabulate\n\n# Initialize AWS Secrets Manager client\nsecrets_manager = boto3.client('secretsmanager')\ndb_host = \"DB_HOST\"\n\ndef get_secretvalue():\n    secret_name = secrets_manager.get_secret_value(SecretId='YOUR_SECRET_ARN')\n    secret_dict = json.loads(secret_name['SecretString'])\n    db_username = secret_dict['username']\n    db_password = secret_dict['password']\n    return db_username, db_password\n    \ndef execute_query(db_name, query):\n    db_username, db_password = get_secretvalue()\n\n    for db in db_name:\n        try:\n            connection = mysql.connector.connect(\n                host=db_host,\n                user=db_username,\n                password=db_password,\n                database=db\n            )\n            cursor = connection.cursor()\n            cursor.execute(query)\n            result = cursor.fetchall()\n            row_count = cursor.rowcount\n\n            if query.upper().startswith((\"SELECT\", \"SHOW\", \"DESCRIBE\")):\n                if result:\n                    header = [column_name[0] for column_name in cursor.description]\n                    table_output = [header] + list(result)\n                    print(f\"Running query on: {db}\")\n                    print(tabulate.tabulate(table_output, tablefmt=\"pipe\"))\n                else:\n                    print(\"Empty result\")\n            else:\n                connection.commit()\n                print(f\"{row_count} rows affected in {db}\")          \n        \n        except Exception as e:\n            print(\"Error:\", e)\n        finally:\n            if 'connection' in locals():\n                connection.close()\n\ndb_names = input(\"Enter the DB names followed by space:\").split()\nquery = input(\"Enter the query:\")\nexecute_query(db_names, query)\n"
  },
  {
    "path": "azure-openapi/basic-api/main.py",
    "content": "import os\nfrom openai import AzureOpenAI\n\nendpoint = \"<your-endpoint>\"\nmodel_name = \"o4-mini\"\ndeployment = \"o4-mini\"\n\nsubscription_key = os.getenv(\"AZURE_OPENAI_API_KEY\")\napi_version = \"2024-12-01-preview\"\n\nclient = AzureOpenAI(\n    api_version=api_version,\n    azure_endpoint=endpoint,\n    api_key=subscription_key,\n)\n\nresponse = client.chat.completions.create(\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": \"You are a senior DevOps engineer helping beginners.\",\n        },\n        {\n            \"role\": \"user\",\n            \"content\": \"How do I set up CI/CD using GitHub Actions for a Node.js app?\",\n        }\n    ],\n    max_completion_tokens=100000,\n    model=deployment\n)\n\nprint(response.choices[0].message.content)"
  },
  {
    "path": "azure-openapi/basic-api/requirements.txt",
    "content": "openai~=1.60.2\n"
  },
  {
    "path": "boto3/dynamodb/README.md",
    "content": "## Working With DynamoDB Using Boto3\n\nThis example shows loading sample data to dynamoDB and using boto3 to acess the data from the table.\n\nCode Credits: [fernandomc.com Guide](https://www.fernandomc.com/posts/ten-examples-of-getting-data-from-dynamodb-with-python-and-boto3/)"
  },
  {
    "path": "boto3/dynamodb/createTable.py",
    "content": "import boto3\n\ndynamodb = boto3.client(\"dynamodb\")\n\nresponse = dynamodb.create_table(\n  TableName=\"basicSongsTable\",\n  AttributeDefinitions=[\n    {\n      \"AttributeName\": \"artist\",\n      \"AttributeType\": \"S\"\n    },\n    {\n      \"AttributeName\": \"song\",\n      \"AttributeType\": \"S\"\n    }\n  ],\n  KeySchema=[\n    {\n      \"AttributeName\": \"artist\",\n      \"KeyType\": \"HASH\"\n    },\n    {\n      \"AttributeName\": \"song\",\n      \"KeyType\": \"RANGE\"\n    }\n  ],\n  ProvisionedThroughput={\n    \"ReadCapacityUnits\": 1,\n    \"WriteCapacityUnits\": 1\n  }\n)\n\nprint(response)"
  },
  {
    "path": "boto3/dynamodb/data.json",
    "content": "[\n    {\n      \"artist\": \"Romero Allen\",\n      \"song\": \"Atomic Dim\",\n      \"id\": \"b4b0da3f-36e3-4569-b196-3ad982f72bbd\",\n      \"priceUsdCents\": 392,\n      \"publisher\": \"QUAREX\"\n    },\n    {\n      \"artist\": \"Hilda Barnes\",\n      \"song\": \"Almond Dutch\",\n      \"id\": \"eeb58c73-603f-4d6b-9e3b-cf587488f488\",\n      \"priceUsdCents\": 161,\n      \"publisher\": \"LETPRO\"\n    },\n    {\n      \"artist\": \"Hall Ramos\",\n      \"song\": \"Carmine Drab\",\n      \"id\": \"951637bd-59ef-4448-93f5-e179bfbd20a0\",\n      \"priceUsdCents\": 370,\n      \"publisher\": \"BRAINQUIL\"\n    },\n    {\n      \"artist\": \"Chang Vance\",\n      \"song\": \"Aureolin Dodger\",\n      \"id\": \"29f5dea2-2bd1-4d13-bf33-7aadc4f14ef2\",\n      \"priceUsdCents\": 324,\n      \"publisher\": \"DIGIAL\"\n    },\n    {\n      \"artist\": \"May Tanner\",\n      \"song\": \"Cadmium Cultured\",\n      \"id\": \"483b1787-a9fd-4ec8-bf16-5ec122bb559a\",\n      \"priceUsdCents\": 146,\n      \"publisher\": \"CHORIZON\"\n    },\n    {\n      \"artist\": \"Tillman Watkins\",\n      \"song\": \"Cameo Dark\",\n      \"id\": \"18f42c1e-8a91-47f9-829e-836ee1a49a17\",\n      \"priceUsdCents\": 173,\n      \"publisher\": \"OTHERWAY\"\n    },\n    {\n      \"artist\": \"Naomi Petersen\",\n      \"song\": \"Candy Earth\",\n      \"id\": \"0ed05345-3dfa-4ea4-a59a-6c015153c9d5\",\n      \"priceUsdCents\": 249,\n      \"publisher\": \"SONIQUE\"\n    },\n    {\n      \"artist\": \"Kristin Olson\",\n      \"song\": \"Banana Eerie\",\n      \"id\": \"f4ea8c5a-1a5b-4d4b-94cf-74da68c543e6\",\n      \"priceUsdCents\": 246,\n      \"publisher\": \"AMTAP\"\n    },\n    {\n      \"artist\": \"Marta Frost\",\n      \"song\": \"Apple Chinese\",\n      \"id\": \"5cd6c545-655c-491d-bc7c-1aaa8569b26c\",\n      \"priceUsdCents\": 181,\n      \"publisher\": \"ZAGGLES\"\n    },\n    {\n      \"artist\": \"Etta Anderson\",\n      \"song\": \"Antique English\",\n      \"id\": \"ba865a03-8666-4074-8e47-15bcc707fa6e\",\n      \"priceUsdCents\": 143,\n      \"publisher\": \"DATACATOR\"\n    },\n    {\n      \"artist\": \"Charlotte Cooley\",\n      \"song\": \"Amaranth Dim\",\n      \"id\": \"fb4aad81-24c0-4d79-ac34-264923e99464\",\n      \"priceUsdCents\": 121,\n      \"publisher\": \"KEENGEN\"\n    },\n    {\n      \"artist\": \"Elise Pugh\",\n      \"song\": \"Bright Cerulean\",\n      \"id\": \"5ac17e68-e6c3-43f6-a305-5c63ac39307f\",\n      \"priceUsdCents\": 389,\n      \"publisher\": \"CUJO\"\n    },\n    {\n      \"artist\": \"Tamika Austin\",\n      \"song\": \"Camel Flickr\",\n      \"id\": \"a89ac751-89ba-41e9-9e86-60605b3139f4\",\n      \"priceUsdCents\": 392,\n      \"publisher\": \"TECHMANIA\"\n    },\n    {\n      \"artist\": \"Claire Sharp\",\n      \"song\": \"Beaver Electric\",\n      \"id\": \"f9ab6076-3582-479e-877e-f27d5c0919d9\",\n      \"priceUsdCents\": 209,\n      \"publisher\": \"PORTICO\"\n    },\n    {\n      \"artist\": \"Lilian Horton\",\n      \"song\": \"Bright Coral\",\n      \"id\": \"634d096f-edc1-4452-a73c-d417c7e46c04\",\n      \"priceUsdCents\": 227,\n      \"publisher\": \"GUSHKOOL\"\n    },\n    {\n      \"artist\": \"Reba George\",\n      \"song\": \"Bone Coquelicot\",\n      \"id\": \"a0d5a2c1-7086-46a5-98ea-36724a296728\",\n      \"priceUsdCents\": 124,\n      \"publisher\": \"MANGLO\"\n    },\n    {\n      \"artist\": \"Ruiz Vaughn\",\n      \"song\": \"Byzantium Feldgrau\",\n      \"id\": \"202cb417-0b2b-4809-8993-0916aa62ff67\",\n      \"priceUsdCents\": 223,\n      \"publisher\": \"RONBERT\"\n    },\n    {\n      \"artist\": \"Wilcox Contreras\",\n      \"song\": \"Brink Cocoa\",\n      \"id\": \"c7763312-b732-4ad9-8d58-295f36e3f411\",\n      \"priceUsdCents\": 214,\n      \"publisher\": \"ZENTIA\"\n    },\n    {\n      \"artist\": \"Jodi Ruiz\",\n      \"song\": \"Auburn Chartreuse\",\n      \"id\": \"ab89362d-3ef7-461e-a093-60aa2e28eb07\",\n      \"priceUsdCents\": 215,\n      \"publisher\": \"ZOLAVO\"\n    },\n    {\n      \"artist\": \"Potter Keith\",\n      \"song\": \"Arctic CG\",\n      \"id\": \"e52cb1f0-2459-4c60-9841-4497fcdab5a9\",\n      \"priceUsdCents\": 173,\n      \"publisher\": \"CIRCUM\"\n    },\n    {\n      \"artist\": \"Wilson Randall\",\n      \"song\": \"Black Coral\",\n      \"id\": \"6726183b-0b9a-4060-a1c6-6dec1e726070\",\n      \"priceUsdCents\": 206,\n      \"publisher\": \"GEEKUS\"\n    },\n    {\n      \"artist\": \"Morrow Camacho\",\n      \"song\": \"Bittersweet Poetic\",\n      \"id\": \"23edaed1-d443-4e53-bbbd-c54dc8d3bf5f\",\n      \"priceUsdCents\": 182,\n      \"publisher\": \"MEDESIGN\"\n    },\n    {\n      \"artist\": \"Clayton Sears\",\n      \"song\": \"Bitter Dodger\",\n      \"id\": \"17afec57-4fcc-46c0-a63d-04c1ff60f9a2\",\n      \"priceUsdCents\": 275,\n      \"publisher\": \"ZOXY\"\n    },\n    {\n      \"artist\": \"Nicholson Pate\",\n      \"song\": \"Cedar CG\",\n      \"id\": \"af78e70f-67c3-4582-80a5-3b4ae04d4695\",\n      \"priceUsdCents\": 193,\n      \"publisher\": \"MYOPIUM\"\n    },\n    {\n      \"artist\": \"Madeleine Rivers\",\n      \"song\": \"Bisque Congo\",\n      \"id\": \"596626a8-c54b-4d88-9925-0415d4ab589d\",\n      \"priceUsdCents\": 137,\n      \"publisher\": \"LINGOAGE\"\n    },\n    {\n      \"artist\": \"Jeannie Benton\",\n      \"song\": \"Caribbean Denim\",\n      \"id\": \"802afc05-3e72-4c51-b234-7e16a63150e2\",\n      \"priceUsdCents\": 122,\n      \"publisher\": \"XURBAN\"\n    },\n    {\n      \"artist\": \"Jefferson Burks\",\n      \"song\": \"Buff Copper\",\n      \"id\": \"90ad25a1-a562-4b56-8f0b-aac08e13fd02\",\n      \"priceUsdCents\": 162,\n      \"publisher\": \"ZEAM\"\n    },\n    {\n      \"artist\": \"Diann Osborn\",\n      \"song\": \"Carmine Fallow\",\n      \"id\": \"b654e7dd-a907-4fda-8913-d7c12b65b556\",\n      \"priceUsdCents\": 357,\n      \"publisher\": \"HIVEDOM\"\n    },\n    {\n      \"artist\": \"Rose Rowe\",\n      \"song\": \"Air Cornsilk\",\n      \"id\": \"c8c124b1-2f03-4f36-aedd-9bee047914e7\",\n      \"priceUsdCents\": 128,\n      \"publisher\": \"IDETICA\"\n    },\n    {\n      \"artist\": \"Ilene Mays\",\n      \"song\": \"Blanched Celadon\",\n      \"id\": \"e2c2e0b4-bb86-4737-a9c3-3135c345e0a5\",\n      \"priceUsdCents\": 243,\n      \"publisher\": \"FUTURIZE\"\n    },\n    {\n      \"artist\": \"Margarita Dawson\",\n      \"song\": \"Baby Claret\",\n      \"id\": \"fd86fe4f-384e-494a-ae91-f3f2fd49a06d\",\n      \"priceUsdCents\": 244,\n      \"publisher\": \"KATAKANA\"\n    },\n    {\n      \"artist\": \"Dominguez Rocha\",\n      \"song\": \"Brink CG\",\n      \"id\": \"64acc7ea-d104-43d2-8845-33c7678af85d\",\n      \"priceUsdCents\": 100,\n      \"publisher\": \"SLOGANAUT\"\n    },\n    {\n      \"artist\": \"Edith Petty\",\n      \"song\": \"Bistre Chocolate\",\n      \"id\": \"8b250802-7b4d-4fdd-ae44-d68fbcfef386\",\n      \"priceUsdCents\": 144,\n      \"publisher\": \"ZILIDIUM\"\n    },\n    {\n      \"artist\": \"Rutledge Rosario\",\n      \"song\": \"Alabaster Copper\",\n      \"id\": \"b52dc941-f641-4450-9c5f-24ed83593325\",\n      \"priceUsdCents\": 244,\n      \"publisher\": \"SULFAX\"\n    },\n    {\n      \"artist\": \"Lillian Zamora\",\n      \"song\": \"Bittersweet Sunday\",\n      \"id\": \"64b6f717-2524-48ae-b582-c6b059f31a93\",\n      \"priceUsdCents\": 220,\n      \"publisher\": \"SOLAREN\"\n    },\n    {\n      \"artist\": \"Walter Villarreal\",\n      \"song\": \"Candy Flax\",\n      \"id\": \"d043213f-01fc-4086-83df-e852b6450605\",\n      \"priceUsdCents\": 297,\n      \"publisher\": \"RETRACK\"\n    },\n    {\n      \"artist\": \"Christensen Sandoval\",\n      \"song\": \"Buff Cerulean\",\n      \"id\": \"faec7ffb-0df0-4592-9b04-ea04a1ba8620\",\n      \"priceUsdCents\": 125,\n      \"publisher\": \"NITRACYR\"\n    },\n    {\n      \"artist\": \"Frances Hall\",\n      \"song\": \"Amber Poetic\",\n      \"id\": \"b0d3f55a-490c-49f3-a8cb-5bb873e14f27\",\n      \"priceUsdCents\": 209,\n      \"publisher\": \"ZIZZLE\"\n    },\n    {\n      \"artist\": \"Nadia Case\",\n      \"song\": \"Burnt Electric\",\n      \"id\": \"c87719b9-e166-471f-a0f6-209fca526583\",\n      \"priceUsdCents\": 299,\n      \"publisher\": \"TALKOLA\"\n    },\n    {\n      \"artist\": \"Faulkner Casey\",\n      \"song\": \"Cadmium Cinnamon\",\n      \"id\": \"01f63218-1ceb-400c-bbd7-4c33a8733b03\",\n      \"priceUsdCents\": 324,\n      \"publisher\": \"UNI\"\n    },\n    {\n      \"artist\": \"Kristen Gregory\",\n      \"song\": \"Brown English\",\n      \"id\": \"9790b013-ae7c-4afb-b166-37a0a012cc5b\",\n      \"priceUsdCents\": 180,\n      \"publisher\": \"INTERODEO\"\n    },\n    {\n      \"artist\": \"Hardy Alexander\",\n      \"song\": \"Aqua November\",\n      \"id\": \"464cd8a0-b5f6-43c1-a6d6-b548c13602f3\",\n      \"priceUsdCents\": 289,\n      \"publisher\": \"ISOPOP\"\n    },\n    {\n      \"artist\": \"Jerry Floyd\",\n      \"song\": \"Brown Dartmouth\",\n      \"id\": \"6bef9c2e-0610-49fa-b162-3446aa88757e\",\n      \"priceUsdCents\": 338,\n      \"publisher\": \"HOMETOWN\"\n    },\n    {\n      \"artist\": \"Nichole Phelps\",\n      \"song\": \"Blue Cultured\",\n      \"id\": \"c206da83-ad46-4655-86a5-aa95a5bb485e\",\n      \"priceUsdCents\": 397,\n      \"publisher\": \"XIXAN\"\n    },\n    {\n      \"artist\": \"Marguerite Mcclure\",\n      \"song\": \"Cedar Columbia\",\n      \"id\": \"4e01c867-3084-4ae4-9c8a-5b0750465037\",\n      \"priceUsdCents\": 207,\n      \"publisher\": \"TELEQUIET\"\n    },\n    {\n      \"artist\": \"Beach Evans\",\n      \"song\": \"Bright Coffee\",\n      \"id\": \"26d74b66-5bb7-46e6-89cb-b8864b8111bf\",\n      \"priceUsdCents\": 120,\n      \"publisher\": \"OHMNET\"\n    },\n    {\n      \"artist\": \"Clarke Peterson\",\n      \"song\": \"Carnelian Falu\",\n      \"id\": \"d708c366-0580-410b-a0d7-1f7c91ecc7c4\",\n      \"priceUsdCents\": 339,\n      \"publisher\": \"LUMBREX\"\n    },\n    {\n      \"artist\": \"Bertie Michael\",\n      \"song\": \"Ash Chinese\",\n      \"id\": \"d25ff9f9-25ae-459d-8591-7650106a3d11\",\n      \"priceUsdCents\": 204,\n      \"publisher\": \"CRUSTATIA\"\n    },\n    {\n      \"artist\": \"Barr Good\",\n      \"song\": \"Black Earth\",\n      \"id\": \"882c720a-a0ba-4fe1-9e02-eb2640a3677a\",\n      \"priceUsdCents\": 153,\n      \"publisher\": \"OCEANICA\"\n    },\n    {\n      \"artist\": \"Rios Sheppard\",\n      \"song\": \"Blanched Davy\",\n      \"id\": \"38ad21d5-679d-4352-bab6-11a03ea167d3\",\n      \"priceUsdCents\": 222,\n      \"publisher\": \"BUZZMAKER\"\n    },\n    {\n      \"artist\": \"Natalia Wooten\",\n      \"song\": \"Alloy Charleston\",\n      \"id\": \"107adc93-dcbb-4ffe-9259-ebe67cdfce32\",\n      \"priceUsdCents\": 273,\n      \"publisher\": \"GORGANIC\"\n    },\n    {\n      \"artist\": \"Hopkins Levine\",\n      \"song\": \"Blue China\",\n      \"id\": \"5df65ddf-afe7-4514-93c2-93f53885cf71\",\n      \"priceUsdCents\": 248,\n      \"publisher\": \"GINKLE\"\n    },\n    {\n      \"artist\": \"Monique Curry\",\n      \"song\": \"Aqua Cyclamen\",\n      \"id\": \"5148a24f-5c13-4861-96d7-ca957af1b16d\",\n      \"priceUsdCents\": 226,\n      \"publisher\": \"INTRADISK\"\n    },\n    {\n      \"artist\": \"Kirsten Decker\",\n      \"song\": \"Ash Cinnamon\",\n      \"id\": \"ca90e78f-d4d3-4af3-9b20-254254a4d922\",\n      \"priceUsdCents\": 193,\n      \"publisher\": \"COMTOURS\"\n    },\n    {\n      \"artist\": \"DJ DW\",\n      \"song\": \"Battleship Cinnamon\",\n      \"id\": \"ba66eb9d-f8b5-4924-a9e2-e8817e02b03a\",\n      \"priceUsdCents\": 365,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Bright Cerulean\",\n      \"id\": \"84024726-d9ba-4dd4-830d-1022f79eca97\",\n      \"priceUsdCents\": 166,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    },\n    {\n      \"artist\": \"DJ DW\",\n      \"song\": \"Black Crimson\",\n      \"id\": \"c79bcf38-d459-4479-a385-a27a9bdb558a\",\n      \"priceUsdCents\": 370,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    },\n    {\n      \"artist\": \"DJ DW\",\n      \"song\": \"Caribbean Citron\",\n      \"id\": \"8643a896-a7a9-4139-95cc-583e1710b2b1\",\n      \"priceUsdCents\": 360,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Carnelian Cobalt\",\n      \"id\": \"5e8d8ff7-25a7-41c6-a1fa-ac823fda0161\",\n      \"priceUsdCents\": 311,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    },\n    {\n      \"artist\": \"Professor RattyB\",\n      \"song\": \"Big Cyan\",\n      \"id\": \"209e59fb-68a5-45a1-aebb-f84447229a4e\",\n      \"priceUsdCents\": 261,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Bright Electric\",\n      \"id\": \"ced73077-f8c7-40d0-96ee-8d995baa080b\",\n      \"priceUsdCents\": 273,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    },\n    {\n      \"artist\": \"Professor RattyB\",\n      \"song\": \"Blanched Cornsilk\",\n      \"id\": \"88ca6ef9-8cd4-4a52-9c85-f7d7ac81c275\",\n      \"priceUsdCents\": 192,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"DJ DW\",\n      \"song\": \"Amaranth Fever\",\n      \"id\": \"00ea572d-a3ea-41dc-97f6-50af8b26cd13\",\n      \"priceUsdCents\": 199,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Cadmium Eggplant\",\n      \"id\": \"30af38c6-f32d-4e7b-a571-e8641247b975\",\n      \"priceUsdCents\": 168,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Bleu Cinnamon\",\n      \"id\": \"f90cef82-bd0a-44a9-bd3a-bd743c140ced\",\n      \"priceUsdCents\": 153,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Carrot Eton\",\n      \"id\": \"dbea9bd8-fe1f-478a-a98a-5b46d481cf57\",\n      \"priceUsdCents\": 161,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Baker Firebrick\",\n      \"id\": \"1a4e5bc5-4fa3-4b37-9d36-e15dc9ab6b21\",\n      \"priceUsdCents\": 312,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Cadet Celadon\",\n      \"id\": \"fd7667cb-3a41-4777-93bb-ed2d0d8d7458\",\n      \"priceUsdCents\": 142,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"DJ DW\",\n      \"song\": \"Byzantine Charcoal\",\n      \"id\": \"5ab5351f-212a-4fcc-9a76-b5bfbc5d18a0\",\n      \"priceUsdCents\": 174,\n      \"publisher\": \"MUSICMAN INC\"\n    },\n    {\n      \"artist\": \"Arturus Ardvarkian\",\n      \"song\": \"Brick Cerulean\",\n      \"id\": \"65ce7700-c32d-415c-9bf4-26f4e4911372\",\n      \"priceUsdCents\": 381,\n      \"publisher\": \"GLOBOMANTICS MUSIC\"\n    }\n  ]"
  },
  {
    "path": "boto3/dynamodb/loadData.py",
    "content": "import boto3\nimport json\n\ndynamodb = boto3.client('dynamodb')\n\ndef upload():\n    with open('data.json', 'r') as datafile:\n        records = json.load(datafile)\n    for song in records:\n        print(song)\n        item = {\n                'artist':{'S':song['artist']},\n                'song':{'S':song['song']},\n                'id':{'S': song['id']},\n                'priceUsdCents':{'S': str(song['priceUsdCents'])},\n                'publisher':{'S': song['publisher']}\n        }\n        print(item)\n        response = dynamodb.put_item(\n            TableName='basicSongsTable', \n            Item=item\n        )\n        print(\"UPLOADING ITEM\")\n        print(response)\n\nupload()"
  },
  {
    "path": "boto3/dynamodb/query.py",
    "content": "import boto3\nimport json\nfrom boto3.dynamodb.conditions import Key\n\nTABLE_NAME = \"basicSongsTable\"\n\n# Creating the DynamoDB Client\ndynamodb_client = boto3.client('dynamodb', region_name=\"us-west-2\")\n\n# Creating the DynamoDB Table Resource\ndynamodb = boto3.resource('dynamodb', region_name=\"us-west-2\")\ntable = dynamodb.Table(TABLE_NAME)\n\n\nartists = table.scan(AttributesToGet=['artist.'])\n\n\nspecific_artist = table.query(\n  KeyConditionExpression=Key('artist').eq('Arturus Ardvarkian')\n)\n\nartists_object = json.dumps(artists, indent = 4) \nprint(artists_object)\n\nspecific_artist = json.dumps(specific_artist, indent = 4) \nprint(specific_artist)"
  },
  {
    "path": "boto3/ec2/create-instance.py",
    "content": "#! /bin/python3\n\nimport boto3, os\nfrom botocore.exceptions import ClientError\n\nvpc_id = \"vpc-0d42bf2f27be967ff\"\nsubnet_id = \"subnet-00b5ede5e160caa59\"\nami_id = \"ami-0ddf424f81ddb0720\"\ninstance_type = \"t2.small\"\napp_name = \"flask\"\n\ncreate_key = True\nkey_name = \"dev-key\"\nkey_location = \"/Users/bibinwilson/.ssh/devops-class/\"\n\nec2 = boto3.client('ec2')\n\ndef createSecurityGroup():\n    global security_group_id\n    try:\n        response = ec2.create_security_group(GroupName=app_name + \"-sg\",\n                                            Description=app_name + \" Security Group\",\n                                            VpcId=vpc_id,\n                                            TagSpecifications=[\n                                                    {\n                                                        'ResourceType': 'security-group',\n                                                        'Tags': [\n                                                            {\n                                                                'Key': 'Name',\n                                                                'Value': app_name + \"-sg\"\n                                                            }\n                                                        ]\n                                                    },\n                                                ],\n                                            )\n        security_group_id = response['GroupId']\n        print('Security Group Created %s in vpc %s.' % (security_group_id, vpc_id))\n\n        ingress = ec2.authorize_security_group_ingress(\n                            GroupId=security_group_id,\n                            IpPermissions=[\n                                {\n                                    'IpProtocol': 'tcp',\n                                    'FromPort': 80,\n                                    'ToPort': 80,\n                                    'IpRanges': [\n                                        {\n                                            'CidrIp': '0.0.0.0/0'\n                                        }\n                                    ]\n                                },\n                                {\n                                    'IpProtocol': 'tcp',\n                                    'FromPort': 22,\n                                    'ToPort': 22,\n                                    'IpRanges': [\n                                        {\n                                            'CidrIp': '0.0.0.0/0'\n                                        }\n                                    ]\n                                }\n                            ])\n        print('Ingress Successfully Set %s' % ingress)\n    except ClientError as e:\n        print(e)\n\ndef createKeyPair():\n\n    try:\n        key_pair = ec2.create_key_pair(KeyName=key_name)\n\n        ssh_private_key = key_pair[\"KeyMaterial\"]\n        \n        with os.fdopen(os.open(key_location + key_name + \".pem\", os.O_WRONLY | os.O_CREAT, 0o400), \"w+\") as handle:\n            handle.write(ssh_private_key)\n    except ClientError as e:\n        print(e)\n    \ndef createInstance():\n    blockDeviceMappings = [\n        {\n            'DeviceName': \"/dev/sda1\",\n            'Ebs': {\n                'DeleteOnTermination': True,\n                'VolumeSize': 20,\n                'VolumeType': 'gp2'\n            }\n        },\n    ]\n\n    instances = ec2.run_instances(\n        ImageId= ami_id,\n        MinCount=1,\n        MaxCount=1,\n        InstanceType=instance_type,\n        SubnetId=subnet_id,\n        KeyName=key_name,\n        SecurityGroupIds=[security_group_id],\n        BlockDeviceMappings=blockDeviceMappings,\n        TagSpecifications=[\n            {\n                'ResourceType': 'instance',\n                'Tags': [\n                    {\n                        'Key': 'Name',\n                        'Value': app_name + \"-server\"\n                    }\n                ]\n            },\n            {\n                'ResourceType': 'volume',\n                'Tags': [\n                    {\n                        'Key': 'Name',\n                        'Value': app_name + \"-root-disk\"\n                    }\n                ]\n            }\n        ]\n    )\n\n    print(instances[\"Instances\"][0][\"InstanceId\"])\n\n\nif __name__ == \"__main__\":\n    \n    createSecurityGroup()\n\n    if create_key == True:\n        createKeyPair();\n\n    createInstance()\n\n\n# References\n# [1] https://codeflex.co/boto3-create-ec2-with-tags/\n# [2] https://www.learnaws.org/2020/12/16/aws-ec2-boto3-ultimate-guide/\n# [3] https://arjunmohnot.medium.com/aws-ec2-management-with-python-and-boto-3-59d849f1f58f\n\n"
  },
  {
    "path": "database/postgresql.py",
    "content": "import psycopg2\n\ntry:\n    connection = psycopg2.connect(database=\"dvdrental\",\n                        host=\"192.168.5.5\",\n                        user=\"postgres\",\n                        password=\"myPassword\",\n                        port=\"5432\")\n    cursor = connection.cursor()\n    sql_query = \"select * from actor\"\n\n    cursor.execute(sql_query)\n    print(\"Selecting rows from mobile table using cursor.fetchall\")\n    actor_records = cursor.fetchall()\n\n    print(\"Print each row and it's columns values\")\n    for row in actor_records:\n        print(\"Id = \", row[0], )\n        print(\"Model = \", row[1])\n        print(\"Price  = \", row[2], \"\\n\")\n\nexcept (Exception, psycopg2.Error) as error:\n    print(\"Error while fetching data from PostgreSQL\", error)\n\nfinally:\n    if connection:\n        cursor.close()\n        connection.close()\n        print(\"PostgreSQL connection is closed\")\n"
  },
  {
    "path": "generic/command-line-argument.py",
    "content": ""
  },
  {
    "path": "generic/exception-handling.py",
    "content": ""
  },
  {
    "path": "json/files/example.json",
    "content": "{\n    \"name\" : \"test\",\n    \"ip\" : \"198.168.23.45\",\n    \"country\" : \"United States\",\n    \"project\" : \"Data Analytics\",\n    \"website\" : \"scriptscrunch.com\"\n}\n"
  },
  {
    "path": "json/parse-json.py",
    "content": "import json\nimport os\n\n# Script to create absolute path of the JSON file.\n\nscript_dir = os.path.dirname(__file__)\nprint(\"The Script is located at:\" + script_dir )\nscript_absolute_path = os.path.join(script_dir, 'files/example.json')\nprint(\"The Script Path is:\" + script_absolute_path)\n\n# Script to parse JSON\n\njson = json.loads(open(script_absolute_path).read())\nvalue = json['name']\nprint(value)\n\n# Loop through JSON\n\nfor key in json:\n    value = json[key]\n    print(\"The key and value are ({}) = ({})\".format(key, value))"
  },
  {
    "path": "operating-system/README.md",
    "content": "## Python Operating Sytem Based Tasks\n\n1. Create Directory\n2. Delete Directory\n3. List Directory\n4. List total number of folder in a Directory\n5. List total numbers of files in a Directory"
  },
  {
    "path": "operating-system/command-execution.py",
    "content": "import os\n\nos.system('echo \"hello\"')"
  },
  {
    "path": "operating-system/files/param.sh",
    "content": "#!/bin/sh\necho $1\necho $2\necho $3\n\necho \"$@\"\nexit 0"
  },
  {
    "path": "operating-system/files/script.sh",
    "content": "#! /bin/bash\n\necho \"This is a shell script\""
  },
  {
    "path": "operating-system/shell-execution.py",
    "content": "import os\nimport subprocess\n\n# Script execution without parameters\n\nscript_dir = os.path.dirname(__file__)\n\nscript_abosulte_path = os.path.join( script_dir + \"/files/script.sh\")\n\nsubprocess.call(['sh', script_abosulte_path])\n\n# Script execution with parameters\n\nparam_script_abosulte_path = os.path.join( script_dir + \"/files/param.sh\")\n\nsubprocess.call(['sh', param_script_abosulte_path, 'param1 param2'])\n\n\n\n\n\n\n\n"
  }
]