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

Migrations as replicas refactor #343

Merged
merged 24 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0e2bc49
Fix in literal identity check which happened to work.
aznashwan Apr 11, 2024
6edecbb
Add 'scenario' field in DB models layer.
aznashwan Apr 9, 2024
edb6770
Update conductor layer for Live Migrations and Deployments.
aznashwan Apr 9, 2024
af04469
Add 'deployments' and update 'replicas' middle APIs.
aznashwan Apr 10, 2024
fcc84c0
Add 'scenario' fields to /replicas API paths.
aznashwan Apr 10, 2024
5da265d
Add deployments API controller and views.
aznashwan Apr 10, 2024
2683310
Hook in '/deployments' path to API router.
aznashwan Apr 10, 2024
b26bd9f
Add dedicated deployments oslo_policy definitions.
aznashwan Apr 10, 2024
253fbef
Fix POST /deployment API body key error.
aznashwan Apr 11, 2024
3ebecdd
Fix licensing client env flag loading.
aznashwan May 27, 2024
c119df3
Postpone task execution status setting.
aznashwan May 30, 2024
1093a00
Fix deployment cancellation action API route.
aznashwan May 30, 2024
7286ce3
Hook in new reservation fulfillment logic in conductor.
aznashwan May 30, 2024
5dbbd77
Minor bug fixes.
aznashwan Jun 17, 2024
fd7e1d8
Remove `/migrations` API path and update unit tests accordingly
Dany9966 Aug 8, 2024
1c68790
Do not delete reservation on action error or cancellation
Dany9966 Aug 9, 2024
f86f74a
Fix running deployment message
Dany9966 Oct 16, 2024
01010f5
Fix reservation management on minion pool errors
Dany9966 Oct 21, 2024
bd24817
Fix fulfilled migration exception
Dany9966 Oct 22, 2024
d038551
Update unit tests
Dany9966 Oct 28, 2024
efc0876
Refactor DB layer
Dany9966 Oct 29, 2024
3bad643
Add DB API unit tests
Dany9966 Nov 5, 2024
37570a2
Refactor conductor layer
Dany9966 Nov 15, 2024
ee49009
Refactor API layer
Dany9966 Nov 19, 2024
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
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# Copyright 2016 Cloudbase Solutions Srl
# Copyright 2024 Cloudbase Solutions Srl
# All Rights Reserved.

from webob import exc

from coriolis.api import wsgi as api_wsgi
from coriolis.deployments import api
from coriolis import exception
from coriolis.migrations import api
from coriolis.policies import migrations as migration_policies

from webob import exc
from coriolis.policies import deployments as deployment_policies


class MigrationActionsController(api_wsgi.Controller):
class DeploymentActionsController(api_wsgi.Controller):
def __init__(self):
self._migration_api = api.API()
super(MigrationActionsController, self).__init__()
self._deployment_api = api.API()
super(DeploymentActionsController, self).__init__()

@api_wsgi.action('cancel')
def _cancel(self, req, id, body):
context = req.environ['coriolis.context']
context.can(migration_policies.get_migrations_policy_label("cancel"))
context.can(deployment_policies.get_deployments_policy_label("cancel"))
try:
force = (body["cancel"] or {}).get("force", False)

self._migration_api.cancel(context, id, force)
self._deployment_api.cancel(context, id, force)
raise exc.HTTPNoContent()
except exception.NotFound as ex:
raise exc.HTTPNotFound(explanation=ex.msg)
Expand All @@ -30,4 +30,4 @@ def _cancel(self, req, id, body):


def create_resource():
return api_wsgi.Resource(MigrationActionsController())
return api_wsgi.Resource(DeploymentActionsController())
120 changes: 120 additions & 0 deletions coriolis/api/v1/deployments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright 2024 Cloudbase Solutions Srl
# All Rights Reserved.

from oslo_config import cfg as conf
from oslo_log import log as logging
from webob import exc

from coriolis.api.v1 import utils as api_utils
from coriolis.api.v1.views import deployment_view
from coriolis.api import wsgi as api_wsgi
from coriolis.deployments import api
from coriolis.endpoints import api as endpoints_api
from coriolis import exception
from coriolis.policies import deployments as deployment_policies

DEPLOYMENTS_API_OPTS = [
conf.BoolOpt("include_task_info_in_deployments_api",
default=False,
help="Whether or not to expose the internal 'info' field of "
"a Deployment as part of a `GET` request.")]

CONF = conf.CONF
CONF.register_opts(DEPLOYMENTS_API_OPTS, 'api')

LOG = logging.getLogger(__name__)


class DeploymentsController(api_wsgi.Controller):
def __init__(self):
self._deployment_api = api.API()
self._endpoints_api = endpoints_api.API()
super(DeploymentsController, self).__init__()

def show(self, req, id):
context = req.environ["coriolis.context"]
context.can(deployment_policies.get_deployments_policy_label("show"))
deployment = self._deployment_api.get_deployment(
context, id,
include_task_info=CONF.api.include_task_info_in_deployments_api)
if not deployment:
raise exc.HTTPNotFound()

return deployment_view.single(deployment)

def _list(self, req):
show_deleted = api_utils._get_show_deleted(
req.GET.get("show_deleted", None))
context = req.environ["coriolis.context"]
context.show_deleted = show_deleted
context.can(deployment_policies.get_deployments_policy_label("list"))
return deployment_view.collection(
self._deployment_api.get_deployments(
context,
include_tasks=CONF.api.include_task_info_in_deployments_api,
include_task_info=CONF.api.include_task_info_in_deployments_api
))

def index(self, req):
return self._list(req)

def detail(self, req):
return self._list(req)

@api_utils.format_keyerror_message(resource='deployment', method='create')
def _validate_deployment_input(self, context, body):
deployment = body["deployment"]

transfer_id = deployment.get("transfer_id", "")

if not transfer_id:
raise exc.HTTPBadRequest(
explanation="Missing 'transfer_id' field from deployment "
"body. A deployment can be created strictly "
"based on an existing Transfer.")

clone_disks = deployment.get("clone_disks", True)
force = deployment.get("force", False)
skip_os_morphing = deployment.get("skip_os_morphing", False)
instance_osmorphing_minion_pool_mappings = deployment.get(
'instance_osmorphing_minion_pool_mappings', {})
user_scripts = deployment.get('user_scripts', {})
api_utils.validate_user_scripts(user_scripts)
user_scripts = api_utils.normalize_user_scripts(
user_scripts, deployment.get("instances", []))

return (
transfer_id, force, clone_disks, skip_os_morphing,
instance_osmorphing_minion_pool_mappings,
user_scripts)

def create(self, req, body):
context = req.environ['coriolis.context']
context.can(deployment_policies.get_deployments_policy_label("create"))

(transfer_id, force, clone_disks, skip_os_morphing,
instance_osmorphing_minion_pool_mappings,
user_scripts) = self._validate_deployment_input(
context, body)

# NOTE: destination environment for transfer should have been
# validated upon its creation.
deployment = self._deployment_api.deploy_transfer_instances(
context, transfer_id, instance_osmorphing_minion_pool_mappings,
clone_disks, force, skip_os_morphing,
user_scripts=user_scripts)

return deployment_view.single(deployment)

def delete(self, req, id):
context = req.environ['coriolis.context']
context.can(deployment_policies.get_deployments_policy_label("delete"))
try:
self._deployment_api.delete(context, id)
raise exc.HTTPNoContent()
except exception.NotFound as ex:
raise exc.HTTPNotFound(explanation=ex.msg)


def create_resource():
return api_wsgi.Resource(DeploymentsController())
189 changes: 0 additions & 189 deletions coriolis/api/v1/migrations.py

This file was deleted.

Loading