-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completed and tested API for getting and deleting an appliance
- Loading branch information
Showing
11 changed files
with
161 additions
and
276 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,66 @@ | ||
from util import Singleton, Loggable, MotorClient, SecureAsyncHttpClient | ||
from appliance.base import Appliance | ||
from container.manager import ContainerManager | ||
|
||
|
||
class ApplianceManager(Loggable, metaclass=Singleton): | ||
|
||
def __init__(self): | ||
def __init__(self, config): | ||
self.__config = config | ||
self.__app_col = MotorClient().requester.appliance | ||
self.__contr_mgr = ContainerManager() | ||
self.__http_cli = SecureAsyncHttpClient() | ||
|
||
async def get_appliance(self, app_id, verbose=True): | ||
pass | ||
self.__contr_mgr = ContainerManager(config) | ||
self.__http_cli = SecureAsyncHttpClient(config) | ||
|
||
async def get_appliance(self, app_id): | ||
status, app, err = await self._get_appliance_from_db(app_id) | ||
if status != 200: | ||
return status, app, err | ||
app = Appliance(**app) | ||
_, app.containers, _ = await self.__contr_mgr.get_containers(app_id) | ||
return 200, app, None | ||
|
||
async def create_appliance(self, app): | ||
pass | ||
|
||
async def delete_appliance(self, app_id): | ||
pass | ||
status, app, err = await self._get_appliance_from_db(app_id) | ||
if err: | ||
self.logger.error(err) | ||
return status, None, err | ||
status, msg, err = await self.__contr_mgr.delete_containers(appliance=app_id) | ||
if err: | ||
self.logger.error(err) | ||
return 400, None, "Failed to deprovision containers of appliance '%s'"%app_id | ||
self.logger.info(msg) | ||
status, msg, err = await self._deprovision_group(app_id) | ||
if err: | ||
self.logger.error(err) | ||
return 400, None, "Failed to deprovision group of appliance '%s'"%app_id | ||
self.logger.info(msg) | ||
status, msg, err = await self._delete_appliance_from_db(app_id) | ||
if err: | ||
self.logger.error(err) | ||
return status, None, err | ||
self.logger.info(msg) | ||
return status, msg, None | ||
|
||
async def save_appliance(self, app, upsert=True): | ||
await self.__app_col.replace_one(dict(id=app.id), app.to_save(), upsert=upsert) | ||
|
||
async def _get_appliance_from_db(self, app_id): | ||
app = await self.__app_col.find_one(dict(id=app_id)) | ||
if not app: | ||
return 404, None, "Appliance '%s' is not found"%app_id | ||
return 200, app, None | ||
|
||
async def _delete_appliance_from_db(self, app_id): | ||
await self.__app_col.delete_one(dict(id=app_id)) | ||
return 200, "Appliance '%s' has been deleted"%app_id, None | ||
|
||
async def _deprovision_group(self, app_id): | ||
url = '%s/groups/%s?force=true'%(self.__config.url.service_scheduler, app_id) | ||
status, msg, err = await self.__http_cli.delete(url) | ||
if err: | ||
return status, None, err | ||
return 200, "Services of appliance '%s' have been deprovisioned"%app_id, None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
{ | ||
"dcos": { | ||
"master_url": "http://18.188.11.136", | ||
"mesos_master_route": "mesos/master", | ||
"service_scheduler_route": "service/marathon/v2", | ||
"job_scheduler_route": "service/chronos/v1/scheduler", | ||
"mesos_master_endpoint": "mesos/master", | ||
"service_scheduler_endpoint": "service/marathon/v2", | ||
"job_scheduler_endpoint": "service/chronos/v1/scheduler", | ||
"token_file_path": "/Users/fanjiang/.dcos_token" | ||
}, | ||
"port": 9090, | ||
"n_parallel": 1, | ||
"vnet_cidr": "172.16.0.0/16" | ||
"n_parallel": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.