Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Release IPs #120

Open
wants to merge 30 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
MONGO_DB_ROOT_PASSWORD: ${{ secrets.MONGO_DB_ROOT_PASSWORD }}
AWX_PASSWORD: ${{ secrets.AWX_PASSWORD }}
NLP_SECRET: ${{ secrets.NLP_SECRET }}
AWS_PASSWORD: ${{ secrets.AWS_PASSWORD }}
AWS_PASSWORD: ${{ secrets.AWS_SECRET_ACCESS_KEY_COLAB }}
BOT_ID_DEV: ${{ secrets.BOT_ID_DEV }}
BOT_NAME_DEV: ${{ secrets.BOT_NAME_DEV }}
AUTHORIZED_ROOMS_DEV: ${{ secrets.AUTHORIZED_ROOMS_DEV }}
Expand All @@ -100,11 +100,11 @@ jobs:
NLP_SERVER_DEV: ${{ secrets.NLP_SERVER_DEV }}
VCENTER_SERVER: ${{ secrets.VCENTER_SERVER }}
ADMINISTRATORS_DEV: ${{ secrets.ADMINISTRATORS_DEV }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_REGION_COLAB: ${{ secrets.AWS_REGION_COLAB }}
AWS_ACCESS_KEY_ID_COLAB: ${{ secrets.AWS_ACCESS_KEY_ID_COLAB }}
AWS_PASSWORD_COLAB: ${{ secrets.AWS_SECRET_ACCESS_KEY_COLAB }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_COLAB }}
COLABOT_SECRET: ${{ secrets.COLABOT_SECRET }}
DYNAMO_TABLE: ${{ secrets.DYNAMO_TABLE_DEV }}
NETBOX_URL: ${{ secrets.NETBOX_URL_DEV }}
NETBOX_TOKEN: ${{ secrets.NETBOX_TOKEN_DEV }}
run: python3 process-j2.py

- name: Apply and rollout
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ jobs:
VCENTER_SERVER: ${{ secrets.VCENTER_SERVER }}
ADMINISTRATORS_PROD: ${{ secrets.ADMINISTRATORS_PROD }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_REGION_COLAB: ${{ secrets.AWS_REGION_COLAB }}
AWS_ACCESS_KEY_ID_COLAB: ${{ secrets.AWS_ACCESS_KEY_ID_COLAB }}
AWS_PASSWORD_COLAB: ${{ secrets.AWS_SECRET_ACCESS_KEY_COLAB }}
COLABOT_SECRET: ${{ secrets.COLABOT_SECRET }}
DYNAMO_TABLE: ${{ secrets.DYNAMO_TABLE_PROD }}
NETBOX_URL: ${{ secrets.NETBOX_URL_PROD }}
NETBOX_TOKEN: ${{ secrets.NETBOX_TOKEN_PROD }}
run: python3 process-j2.py

- name: Apply and rollout
Expand Down
21 changes: 21 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import time
import logging
import re
import aiohttp
import pymongo
import urllib3
Expand Down Expand Up @@ -41,6 +42,9 @@
"**CML show IP addresses** > show IP addresses\n",
"**CML show server utilization** > show current CPU and Memory usage\n",
"**CML stop lab** > stop labs of your choice\n",
"**Request IP** > allocates a static ip address for CML\n",
"**List my IPs** > lists static IPs allocated to you for CML\n",
"**Release IPs** all | [ips] > return static IPs allocated to you for CML back to pool\n",
"**Create AWS account** > create AWS COLAB account\n",
"**Create VPN account** > create an AnyConnect to COLAB VPN account\n",
"**Create AWS key** > create aws access key\n",
Expand All @@ -55,6 +59,8 @@
"**help** > display available commands\n",
]

release_ips_pattern = r"release ips (?:all|\d{1,3}(?:\.\d{1,3}){3}(?:/\d{1,2})?(?:\s+\d{1,3}(?:\.\d{1,3}){3}(?:/\d{1,2})?)*)" # command = release ips [all | ips]


class COLABot:
def __init__(self, webex_bot_token=None, webex_client_signing_secret=None):
Expand Down Expand Up @@ -306,6 +312,21 @@ async def process(self, req: Request):
elif self.activity.get("text") == "delete accounts":
await awx.delete_accounts(self.activity)

elif self.activity.get("text") == "request ip":
await awx.request_ip(self.activity)

elif self.activity.get("text") == "list my ips":
await awx.list_my_ips(self.activity)

elif re.findall(
release_ips_pattern, self.activity.get("original_text")
): # command = release ips [all | ips]
matches = re.findall(
release_ips_pattern, self.activity.get("original_text")
)
self.activity["ips_to_release"] = matches[0].split(" ")[2:]
await awx.release_ips(self.activity)

elif (
self.activity.get("text")[:3] == "cml"
): # Add searches for cml dialogue here
Expand Down
8 changes: 4 additions & 4 deletions colabot-manifest-dev.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ spec:
- name: ADMINISTRATORS
value: {{ ADMINISTRATORS_DEV }}
- name: AWS_ACCESS_KEY_ID
value: {{ AWS_ACCESS_KEY_ID_COLAB }}
value: {{ AWS_ACCESS_KEY_ID }}
- name: AWS_REGION
value: 'us-east-1'
- name: AWS_SECRET_ACCESS_KEY
Expand All @@ -121,11 +121,11 @@ spec:
- name: COLABOT_SECRET
value: {{ COLABOT_SECRET }}
- name: AWS_DYNAMO_TABLE
value: {{ DYNAMO_TABLE_DEV }}
value: {{ DYNAMO_TABLE }}
- name: NETBOX_URL
value: {{ NETBOX_URL_DEV }}
value: {{ NETBOX_URL }}
- name: NETBOX_TOKEN
value: {{ NETBOX_TOKEN_DEV }}
value: {{ NETBOX_TOKEN }}


---
Expand Down
6 changes: 3 additions & 3 deletions colabot-manifest-prod.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ spec:
- name: COLABOT_SECRET
value: {{ COLABOT_SECRET }}
- name: AWS_DYNAMO_TABLE
value: {{ DYNAMO_TABLE_PROD }}
value: {{ DYNAMO_TABLE }}
- name: NETBOX_URL
value: {{ NETBOX_URL_PROD }}
value: {{ NETBOX_URL }}
- name: NETBOX_TOKEN
value: {{ NETBOX_TOKEN_PROD }}
value: {{ NETBOX_TOKEN }}

---

Expand Down
2 changes: 1 addition & 1 deletion colabot-secrets-dev.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ stringData:
mongo_initb_root_password: {{ MONGO_DB_ROOT_PASSWORD }}
awx_password: {{ AWX_PASSWORD }}
nlp_secret: {{ NLP_SECRET }}
aws_password: {{ AWS_PASSWORD_COLAB }}
aws_password: {{ AWS_PASSWORD }}
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ class DefaultConfig:
COLABOT_CYPHER = os.environ.get("COLABOT_SECRET")
NETBOX_URL = os.environ.get("NETBOX_URL")
NETBOX_TOKEN = os.environ.get("NETBOX_TOKEN")

Loading