diff --git a/docs/management-cmd.md b/docs/management-cmd.md new file mode 100644 index 0000000..c3ac0f7 --- /dev/null +++ b/docs/management-cmd.md @@ -0,0 +1,28 @@ +## Manage Virtual Machines + +### 1. Create VM: Creates a new VM, bypasing payments + +#### Pre-requisites: + +1. A registered and active/email-verified user + +#### Example: + +```bash +python manage.py vm create --owner= --flavor= +# flavor=[small,medium,large] +``` + +This command is not idempotent. The command throws an error when a +supplied flavor is not available or when a VM with the same name exists. + +### 2. Delete VM: + +#### Example + +```bash +python manage.py vm delete +``` + +This command is not idempotent. The command throws an error when a +a VM with the given name doesn't exist. diff --git a/infrastructure/management/commands/tests.py b/infrastructure/management/commands/tests.py deleted file mode 100644 index 3dac69b..0000000 --- a/infrastructure/management/commands/tests.py +++ /dev/null @@ -1,77 +0,0 @@ -# Create your tests here. - -# Copyright © 2022 Aravinth Manivannan -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -import time -import os -from io import StringIO -from urllib.parse import urlparse, urlunparse - -import requests - -from django.core import mail -from django.contrib.auth import get_user_model -from django.core.management import call_command -from django.urls import reverse -from django.test import TestCase, Client, override_settings -from django.utils.http import urlencode -from django.contrib.auth import authenticate -from django.conf import settings - - -from accounts.tests import register_util -from dash.models import Instance -from infrastructure.models import InstanceCreated, InstanceConfiguration - - -class VMCommands(TestCase): - """ - Test command: manage.py create_oidc - """ - - def setUp(self): - self.username = "hosteacustomer" - register_util(t=self, username=self.username) - self.vm_name = "MyHosteaVM" - - def test_cmd(self): - - Application = get_application_model() - - stdout = StringIO() - stderr = StringIO() - - redirect_uri = "http://example.org" - app_name = "test_cmd_oidc" - - self.assertEqual(Instance.objects.filter(name=vm_name).exists(), False) - # username exists - call_command( - "vm", "create", self.vm_name, f"--owner={self.username}", "==flavor=medium" - ) - out = stdout.getvalue() - - self.assertIn(f"Instance created", out) - - instance = Instance.objects.get(name=self.vm_name) - self.assertEqual(instance.owned_by, self.user) - self.assertEqual( - instance.configuration_id, InstanceConfiguration.objects.get(name="s1-4") - ) - - instance_created = InstanceCreated.objects.get(name=self.vm_name) - self.assertEqual(instance_created.instance, instance) - - self.assertEqual(instance_created.created, True)