diff options
| author | Carlos Konstanski <carlos.konstanski@verizonwireless.com> | 2020-04-30 08:34:07 -0600 |
|---|---|---|
| committer | Carlos Konstanski <carlos.konstanski@verizonwireless.com> | 2020-04-30 08:34:07 -0600 |
| commit | 08203a6cb7889e55975d1568e9f4a9187fad8306 (patch) | |
| tree | 49ca07c8c2a44b213c0bfe23303bfbbda41d965a | |
initial commit
34 files changed, 529 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac9782e --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*~ +*swp +README.html +db.sqlite3 +venv +*.pyc +__pyccache__ diff --git a/django-ctl.sh b/django-ctl.sh new file mode 100755 index 0000000..5564e75 --- /dev/null +++ b/django-ctl.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +for pkg in virtualenv; do + which ${pkg} + ret=${?} + if [ "${ret}" != "0" ]; then + echo "${pkg} not found. Please install it and try again." 1>&2 + exit ${ret} + fi +done + +basedir=$(dirname $0) + +if [ ! -d ${basedir}/venv ] || [ "$(ls -A ${basedir}/venv)" == "" ]; then + virtualenv -p python3 ${basedir}/venv +fi + +pushd ${basedir} >/dev/null 2>&1 + +. venv/bin/activate +pip install --upgrade -r requirements.txt + +pushd src/ >/dev/null 2>&1 + +python manage.py runserver + +popd >/dev/null 2>&1 +popd >/dev/null 2>&1 + +exit 0 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8be9a44 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +dj-database-url +dj-static +Django +asgiref +pymysql +mysqlclient diff --git a/sql/schema/.gitignore b/sql/schema/.gitignore new file mode 100644 index 0000000..f659c75 --- /dev/null +++ b/sql/schema/.gitignore @@ -0,0 +1 @@ +faredge.sql diff --git a/sql/schema/faredge.sql.example b/sql/schema/faredge.sql.example new file mode 100644 index 0000000..e324d8a --- /dev/null +++ b/sql/schema/faredge.sql.example @@ -0,0 +1,46 @@ +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +/*!40000 DROP DATABASE IF EXISTS `faredge`*/; + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `faredge` /*!40100 DEFAULT CHARACTER SET utf8 */; + +GRANT ALL PRIVILEGES ON faredge.* TO faredge@'%' IDENTIFIED BY 'password_changeme'; +GRANT ALL PRIVILEGES ON faredge.* TO faredge@localhost IDENTIFIED BY 'password_changeme'; +FLUSH PRIVILEGES; + +USE `faredge`; + +DROP TABLE IF EXISTS orch_image_sync; +CREATE TABLE orch_image_sync ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + remote_region_name varchar(64) not null, + docker_image text not null, + upload_start_time datetime not null, + upload_end_time datetime, + upload_status enum('STARTED', 'UPLOADING', 'COMPLETE', 'FAILED'), + upload_message varchar(255), + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +DROP TABLE IF EXISTS orch_remote_region_setup; +CREATE TABLE orch_remote_region_setup ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + caas_vendor_version varchar(20) not null, + kubernetes_version varchar(20) not null, + central_region_name varchar(64) not null, + remote_region_name varchar(64) not null, + kubernetes_namespace varchar(64) not null, + serviceaccount varchar(64) not null, + kubeconfig mediumtext, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/src/caas/__init__.py b/src/caas/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/caas/__init__.py diff --git a/src/caas/admin.py b/src/caas/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/caas/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/caas/apps.py b/src/caas/apps.py new file mode 100644 index 0000000..5e92d0b --- /dev/null +++ b/src/caas/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CaasConfig(AppConfig): + name = 'caas' diff --git a/src/caas/migrations/__init__.py b/src/caas/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/caas/migrations/__init__.py diff --git a/src/caas/models.py b/src/caas/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/src/caas/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/src/caas/tests.py b/src/caas/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/caas/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/caas/views.py b/src/caas/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/src/caas/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/src/far_edge_ops_api/.gitignore b/src/far_edge_ops_api/.gitignore new file mode 100644 index 0000000..fce19e4 --- /dev/null +++ b/src/far_edge_ops_api/.gitignore @@ -0,0 +1 @@ +settings.py diff --git a/src/far_edge_ops_api/__init__.py b/src/far_edge_ops_api/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/far_edge_ops_api/__init__.py diff --git a/src/far_edge_ops_api/asgi.py b/src/far_edge_ops_api/asgi.py new file mode 100644 index 0000000..de8b0be --- /dev/null +++ b/src/far_edge_ops_api/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for far_edge_ops_api project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'far_edge_ops_api.settings') + +application = get_asgi_application() diff --git a/src/far_edge_ops_api/setting.py.example b/src/far_edge_ops_api/setting.py.example new file mode 100644 index 0000000..f89eeea --- /dev/null +++ b/src/far_edge_ops_api/setting.py.example @@ -0,0 +1,124 @@ +""" +Django settings for far_edge_ops_api project. + +Generated by 'django-admin startproject' using Django 3.0.5. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '_%q*cv!0fu&z%#17ved2zq-6y^*#^1pt#gma))h6g(=jw!q14o' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +ALLOWED_HOSTS = ['*'] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'far_edge_ops_api.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'far_edge_ops_api.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'faredge', + 'HOST': 'localhost', + 'PORT': '3306', + 'USER': 'faredge', + 'PASSWORD': 'neweboy' + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/src/far_edge_ops_api/urls.py b/src/far_edge_ops_api/urls.py new file mode 100644 index 0000000..298a4a7 --- /dev/null +++ b/src/far_edge_ops_api/urls.py @@ -0,0 +1,22 @@ +"""far_edge_ops_api URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [ + path('orchestration/', include('orchestration.urls')), + path('admin/', admin.site.urls) +] diff --git a/src/far_edge_ops_api/wsgi.py b/src/far_edge_ops_api/wsgi.py new file mode 100644 index 0000000..3b5d6a6 --- /dev/null +++ b/src/far_edge_ops_api/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for far_edge_ops_api project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'far_edge_ops_api.settings') + +application = get_wsgi_application() diff --git a/src/manage.py b/src/manage.py new file mode 100755 index 0000000..6f1cc4b --- /dev/null +++ b/src/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'far_edge_ops_api.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/src/orchestration/__init__.py b/src/orchestration/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/orchestration/__init__.py diff --git a/src/orchestration/admin.py b/src/orchestration/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/orchestration/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/orchestration/apps.py b/src/orchestration/apps.py new file mode 100644 index 0000000..f92ec6d --- /dev/null +++ b/src/orchestration/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class OrchestrationConfig(AppConfig): + name = 'orchestration' diff --git a/src/orchestration/migrations/0001_initial.py b/src/orchestration/migrations/0001_initial.py new file mode 100644 index 0000000..f2ff405 --- /dev/null +++ b/src/orchestration/migrations/0001_initial.py @@ -0,0 +1,39 @@ +# Generated by Django 3.0.5 on 2020-04-30 00:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='ImageSync', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('remote_region_name', models.CharField(max_length=64)), + ('docker_image', models.TextField(max_length=65535)), + ('upload_start_time', models.DateTimeField()), + ('upload_end_time', models.DateTimeField(blank=True)), + ('upload_status', models.CharField(choices=[('STARTED', 'STARTED'), ('UPLOADING', 'UPLOADING'), ('COMPLETE', 'COMPLETE'), ('FAILED', 'FAILED')], max_length=9)), + ('upload_message', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='RemoteRegionSetup', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('caas_vendor_version', models.CharField(max_length=20)), + ('kubernetes_version', models.CharField(max_length=20)), + ('central_region_name', models.CharField(max_length=64)), + ('remote_region_name', models.CharField(max_length=64)), + ('kubernetes_namespace', models.CharField(max_length=64)), + ('serviceaccount', models.CharField(max_length=64)), + ('kubeconfig', models.TextField(max_length=16777215)), + ], + ), + ] diff --git a/src/orchestration/migrations/0002_auto_20200429_1826.py b/src/orchestration/migrations/0002_auto_20200429_1826.py new file mode 100644 index 0000000..176b8b9 --- /dev/null +++ b/src/orchestration/migrations/0002_auto_20200429_1826.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.5 on 2020-04-30 00:26 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('orchestration', '0001_initial'), + ] + + operations = [ + migrations.RenameModel( + old_name='ImageSync', + new_name='Image_Sync', + ), + migrations.RenameModel( + old_name='RemoteRegionSetup', + new_name='Remote_Region_Setup', + ), + ] diff --git a/src/orchestration/migrations/0003_auto_20200429_1827.py b/src/orchestration/migrations/0003_auto_20200429_1827.py new file mode 100644 index 0000000..24c919c --- /dev/null +++ b/src/orchestration/migrations/0003_auto_20200429_1827.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.5 on 2020-04-30 00:27 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('orchestration', '0002_auto_20200429_1826'), + ] + + operations = [ + migrations.RenameModel( + old_name='Image_Sync', + new_name='ImageSync', + ), + migrations.RenameModel( + old_name='Remote_Region_Setup', + new_name='RemoteRegionSetup', + ), + ] diff --git a/src/orchestration/migrations/0004_auto_20200429_1831.py b/src/orchestration/migrations/0004_auto_20200429_1831.py new file mode 100644 index 0000000..ef7d71d --- /dev/null +++ b/src/orchestration/migrations/0004_auto_20200429_1831.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-04-30 00:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orchestration', '0003_auto_20200429_1827'), + ] + + operations = [ + migrations.AlterField( + model_name='imagesync', + name='upload_end_time', + field=models.DateTimeField(null=True), + ), + ] diff --git a/src/orchestration/migrations/0005_auto_20200429_1836.py b/src/orchestration/migrations/0005_auto_20200429_1836.py new file mode 100644 index 0000000..f4215d0 --- /dev/null +++ b/src/orchestration/migrations/0005_auto_20200429_1836.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-04-30 00:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orchestration', '0004_auto_20200429_1831'), + ] + + operations = [ + migrations.AlterField( + model_name='remoteregionsetup', + name='kubeconfig', + field=models.TextField(blank=True, default='', max_length=16777215), + ), + ] diff --git a/src/orchestration/migrations/0006_auto_20200429_1836.py b/src/orchestration/migrations/0006_auto_20200429_1836.py new file mode 100644 index 0000000..d624ebf --- /dev/null +++ b/src/orchestration/migrations/0006_auto_20200429_1836.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-04-30 00:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orchestration', '0005_auto_20200429_1836'), + ] + + operations = [ + migrations.AlterField( + model_name='remoteregionsetup', + name='kubeconfig', + field=models.TextField(blank=True, default='', max_length=16777215, null=True), + ), + ] diff --git a/src/orchestration/migrations/0007_auto_20200429_1837.py b/src/orchestration/migrations/0007_auto_20200429_1837.py new file mode 100644 index 0000000..210bf23 --- /dev/null +++ b/src/orchestration/migrations/0007_auto_20200429_1837.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-04-30 00:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orchestration', '0006_auto_20200429_1836'), + ] + + operations = [ + migrations.AlterField( + model_name='remoteregionsetup', + name='kubeconfig', + field=models.TextField(blank=True, max_length=16777215, null=True), + ), + ] diff --git a/src/orchestration/migrations/__init__.py b/src/orchestration/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/orchestration/migrations/__init__.py diff --git a/src/orchestration/models.py b/src/orchestration/models.py new file mode 100644 index 0000000..8e79d8d --- /dev/null +++ b/src/orchestration/models.py @@ -0,0 +1,26 @@ +from django.db import models + + +class ImageSync(models.Model): + remote_region_name = models.CharField(max_length=64) + docker_image = models.TextField(max_length=65535) + upload_start_time = models.DateTimeField() + upload_end_time = models.DateTimeField(null=True) + upload_status = models.CharField(max_length=9, choices=[('STARTED', 'STARTED'), ('UPLOADING', 'UPLOADING'), ('COMPLETE', 'COMPLETE'), ('FAILED', 'FAILED')]) + upload_message = models.CharField(max_length=255) + + def __str__(self): + return "%s : %s" % (self.remote_region_name, self.docker_image) + + +class RemoteRegionSetup(models.Model): + caas_vendor_version = models.CharField(max_length=20) + kubernetes_version = models.CharField(max_length=20) + central_region_name = models.CharField(max_length=64) + remote_region_name = models.CharField(max_length=64) + kubernetes_namespace = models.CharField(max_length=64) + serviceaccount = models.CharField(max_length=64) + kubeconfig = models.TextField(max_length=16777215, null=True, blank=True) + + def __str__(self): + return "%s : %s" % (self.remote_region_name, self.kubernetes_namespace) diff --git a/src/orchestration/tests.py b/src/orchestration/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/orchestration/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/orchestration/urls.py b/src/orchestration/urls.py new file mode 100644 index 0000000..6b7dbbc --- /dev/null +++ b/src/orchestration/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), + path('count/<int:count>/', views.count, name='count'), + path('imagesync/', views.imagesync, name='imagesync') +] diff --git a/src/orchestration/views.py b/src/orchestration/views.py new file mode 100644 index 0000000..4c3910c --- /dev/null +++ b/src/orchestration/views.py @@ -0,0 +1,24 @@ +from django.shortcuts import render +from django.core import serializers +from django.http import HttpResponse, JsonResponse +from .models import ImageSync, RemoteRegionSetup + + +def index(request): + return HttpResponse("Hello world") + + +def count(request, count): + data = { + 'name': 'Vitor', + 'location': 'Finland', + 'is_active': True, + 'count': count + } + return JsonResponse(data) + + +def imagesync(request): + rec = ImageSync.objects.order_by('-remote_region_name') + return JsonResponse(serializers.serialize('json', rec), safe=False) + |
