Fixed small issues.
This commit is contained in:
parent
009ec0519f
commit
1273092b6a
@ -22,11 +22,8 @@ import logging
|
||||
import urlparse
|
||||
|
||||
from django.utils.decorators import available_attrs
|
||||
|
||||
from windcclient.v1 import client as windc_client
|
||||
|
||||
#from horizon.api import base
|
||||
|
||||
|
||||
__all__ = ('datacenter_get','datacenter_list',
|
||||
'datacenter_create','datacenter_delete')
|
||||
@ -42,23 +39,28 @@ def windcclient(request):
|
||||
% (request.user.token, url))
|
||||
return windc_client.Client(endpoint=url, token=None)
|
||||
|
||||
def datacenter_create(request, parameters):
|
||||
name = parameters.get('name')
|
||||
_type = parameters.get('type')
|
||||
version = parameters.get('version')
|
||||
ip = parameters.get('ip')
|
||||
port = parameters.get('port')
|
||||
user = parameters.get('user')
|
||||
password = parameters.get('password')
|
||||
return windcclient(request).datacenters.create(name, _type,
|
||||
version, ip,
|
||||
port, user, password)
|
||||
def datacenters_create(request, parameters):
|
||||
name = parameters.get('name', '')
|
||||
return windcclient(request).datacenters.create(name)
|
||||
|
||||
def datacenter_delete(request, datacenter_id):
|
||||
def datacenters_delete(request, datacenter_id):
|
||||
return windcclient(request).datacenters.delete(datacenter_id)
|
||||
|
||||
def datacenter_get(request, datacenter_id):
|
||||
def datacenters_get(request, datacenter_id):
|
||||
return windcclient(request).datacenters.get(datacenter_id)
|
||||
|
||||
def datacenter_list(request):
|
||||
def datacenters_list(request):
|
||||
return windcclient(request).datacenters.list()
|
||||
|
||||
def services_create(request, datacenter, parameters):
|
||||
name = parameters.get('name', '')
|
||||
return windcclient(request).services.create(datacenter, name)
|
||||
|
||||
def services_list(request, datacenter):
|
||||
return windcclient(request).services.list(datacenter)
|
||||
|
||||
def services_get(request, datacenter, service_id):
|
||||
return windcclient(request).services.get(datacenter, service_id)
|
||||
|
||||
def services_delete(request, datacenter, service_id):
|
||||
return windcclient(request).services.delete(datacenter, service_id)
|
||||
|
@ -51,9 +51,9 @@ class CreateService(tables.LinkAction):
|
||||
def allowed(self, request, datum):
|
||||
return True
|
||||
|
||||
def action(self, request, obj_id):
|
||||
def action(self, request, service):
|
||||
# FIX ME
|
||||
api.windc.datacenter.create_service(request, obj_id)
|
||||
api.windc.services_create(request, service)
|
||||
|
||||
|
||||
class CreateDataCenter(tables.LinkAction):
|
||||
@ -65,9 +65,8 @@ class CreateDataCenter(tables.LinkAction):
|
||||
def allowed(self, request, datum):
|
||||
return True
|
||||
|
||||
def action(self, request, obj_id):
|
||||
# FIX ME
|
||||
api.windc.datacenter.create(request, obj_id)
|
||||
def action(self, request, datacenter):
|
||||
api.windc.datacenters_create(request, datacenter)
|
||||
|
||||
|
||||
class DeleteDataCenter(tables.BatchAction):
|
||||
@ -82,9 +81,8 @@ class DeleteDataCenter(tables.BatchAction):
|
||||
return True
|
||||
|
||||
def action(self, request, datacenter_id):
|
||||
# FIX ME
|
||||
datacenter = api.windc.datacenter_get(request, datacenter_id)
|
||||
api.windc.datacenter_delete(request, datacenter)
|
||||
datacenter = api.windc.datacenters_get(request, datacenter_id)
|
||||
api.windc.datacenters_delete(request, datacenter)
|
||||
|
||||
|
||||
class EditService(tables.LinkAction):
|
||||
@ -117,15 +115,6 @@ class UpdateRow(tables.Row):
|
||||
|
||||
|
||||
class WinDCTable(tables.DataTable):
|
||||
TASK_STATUS_CHOICES = (
|
||||
(None, True),
|
||||
("none", True)
|
||||
)
|
||||
STATUS_CHOICES = (
|
||||
("active", True),
|
||||
("shutoff", True),
|
||||
("error", False),
|
||||
)
|
||||
name = tables.Column("name",
|
||||
link=("horizon:project:windc:services"),
|
||||
verbose_name=_("Name"))
|
||||
@ -139,15 +128,6 @@ class WinDCTable(tables.DataTable):
|
||||
|
||||
|
||||
class WinServicesTable(tables.DataTable):
|
||||
TASK_STATUS_CHOICES = (
|
||||
(None, True),
|
||||
("none", True)
|
||||
)
|
||||
STATUS_CHOICES = (
|
||||
("active", True),
|
||||
("shutoff", True),
|
||||
("error", False),
|
||||
)
|
||||
name = tables.Column("name",
|
||||
link=("horizon:project:windc"),
|
||||
verbose_name=_("Name"))
|
||||
|
@ -3,7 +3,7 @@
|
||||
{% block title %}{% trans "Data Center Services" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include "horizon/common/_page_header.html" with title="Data Center "|add:domain_controller_name %}
|
||||
{% include "horizon/common/_page_header.html" with title="Data Center "|add:dc_name %}
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
|
@ -36,7 +36,6 @@ from horizon import workflows
|
||||
|
||||
from openstack_dashboard import api
|
||||
from .tables import WinDCTable, WinServicesTable
|
||||
from .tabs import WinServicesTab
|
||||
from .workflows import CreateWinService, CreateWinDC
|
||||
|
||||
|
||||
@ -48,9 +47,9 @@ class IndexView(tables.DataTableView):
|
||||
template_name = 'project/windc/index.html'
|
||||
|
||||
def get_data(self):
|
||||
# Gather our instances
|
||||
# Gather our datacenters
|
||||
try:
|
||||
data_centers = api.windc.datacenter_list(self.request)
|
||||
data_centers = api.windc.datacenters_list(self.request)
|
||||
except:
|
||||
data_centers = []
|
||||
exceptions.handle(self.request,
|
||||
@ -64,21 +63,22 @@ class WinServices(tables.DataTableView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(WinServices, self).get_context_data(**kwargs)
|
||||
context["domain_controller_name"] = self.get_data()[0].name
|
||||
data = self.get_data()
|
||||
context["dc_name"] = self.dc_name
|
||||
return context
|
||||
|
||||
def get_data(self):
|
||||
try:
|
||||
dc_id = self.kwargs['domain_controller_id']
|
||||
domain_controller = api.windc.datacenter_get(self.request, dc_id)
|
||||
datacenter = api.windc.datacenters_get(self.request, dc_id)
|
||||
self.dc_name = datacenter.name
|
||||
services = api.windc.services_list(self.request, datacenter)
|
||||
except:
|
||||
redirect = reverse('horizon:project:windc:index')
|
||||
services = []
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve details for '
|
||||
'domain_controller "%s".') % dc_id,
|
||||
redirect=redirect)
|
||||
self._domain_controller = [domain_controller,]
|
||||
return self._domain_controller
|
||||
_('Unable to retrieve list of services for '
|
||||
'data center "%s".') % dc_id)
|
||||
return services
|
||||
|
||||
|
||||
class CreateWinDCView(workflows.WorkflowView):
|
||||
|
@ -143,23 +143,26 @@ class CreateWinService(workflows.Workflow):
|
||||
slug = "create"
|
||||
name = _("Create Service")
|
||||
finalize_button_name = _("Deploy")
|
||||
success_message = _('Deployed %(count)s named "%(name)s".')
|
||||
failure_message = _('Unable to deploy %(count)s named "%(name)s".')
|
||||
success_message = _('Created service "%s".')
|
||||
failure_message = _('Unable to create service "%s".')
|
||||
success_url = "horizon:project:windc:services"
|
||||
default_steps = (SelectProjectUser,
|
||||
ConfigureWinDC,
|
||||
ConfigureWinIIS)
|
||||
|
||||
## TO DO:
|
||||
## Need to rewrite the following code:
|
||||
def format_status_message(self, message):
|
||||
name = self.context.get('name', 'noname')
|
||||
return message % name
|
||||
|
||||
def handle(self, request, context):
|
||||
try:
|
||||
datacenter = context.get('domain_controller_name', '')
|
||||
service = api.windc.services_create(request, context)
|
||||
return True
|
||||
except:
|
||||
exceptions.handle(request)
|
||||
return False
|
||||
|
||||
#def handle(self, request, context):
|
||||
# try:
|
||||
# api.windc.create(request,...)
|
||||
# return True
|
||||
# except:
|
||||
# exceptions.handle(request)
|
||||
# return False
|
||||
|
||||
|
||||
class CreateWinDC(workflows.Workflow):
|
||||
@ -178,14 +181,7 @@ class CreateWinDC(workflows.Workflow):
|
||||
|
||||
def handle(self, request, context):
|
||||
try:
|
||||
# FIX ME:
|
||||
context['type'] = 'datacenter'
|
||||
context['version'] = '1.0'
|
||||
context['ip'] = '1.1.1.1'
|
||||
context['port'] = '80'
|
||||
context['user'] = 'administrator'
|
||||
context['password'] = 'swordfish'
|
||||
datacenter = api.windc.datacenter_create(request, context)
|
||||
datacenter = api.windc.datacenters_create(request, context)
|
||||
return True
|
||||
except:
|
||||
exceptions.handle(request)
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
from windcclient.common import client
|
||||
from . import datacenters
|
||||
from . import dcservices
|
||||
|
||||
|
||||
class Client(object):
|
||||
@ -25,3 +26,4 @@ class Client(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.client = client.HTTPClient(**kwargs)
|
||||
self.datacenters = datacenters.DCManager(self)
|
||||
self.services = dcservices.DCServiceManager(self)
|
||||
|
@ -31,14 +31,8 @@ class DCManager(base.Manager):
|
||||
def list(self):
|
||||
return self._list('/datacenters', 'datacenters')
|
||||
|
||||
def create(self, name, type, version, ip, port, user, password, **extra):
|
||||
body = {'name': name,
|
||||
'type': type,
|
||||
'version': version,
|
||||
'ip': ip,
|
||||
'port': port,
|
||||
'user': user,
|
||||
'password': password}
|
||||
def create(self, name, **extra):
|
||||
body = {'name': name, 'services': {}}
|
||||
body.update(extra)
|
||||
return self._create('/datacenters', body, 'datacenter')
|
||||
|
||||
|
@ -26,24 +26,17 @@ from windc.db import api as db_api
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Controller(object):
|
||||
class Datacenters_Controller(object):
|
||||
def __init__(self, conf):
|
||||
LOG.debug("Creating data centers controller with config:"
|
||||
"datacenters.py %s", conf)
|
||||
self.conf = conf
|
||||
|
||||
@utils.verify_tenant
|
||||
def findLBforVM(self, req, tenant_id, vm_id):
|
||||
LOG.debug("Got index request. Request: %s", req)
|
||||
result = core_api.lb_find_for_vm(self.conf, tenant_id, vm_id)
|
||||
return {'loadbalancers': result}
|
||||
|
||||
@utils.verify_tenant
|
||||
def index(self, req, tenant_id):
|
||||
LOG.debug("Got index request. Request: %s", req)
|
||||
result = core_api.dc_get_index(self.conf, tenant_id)
|
||||
LOG.debug("Got list of datacenters: %s", result)
|
||||
result
|
||||
return {'datacenters': result}
|
||||
|
||||
@utils.http_success_code(202)
|
||||
@ -80,4 +73,4 @@ def create_resource(conf):
|
||||
"""Datacenters resource factory method"""
|
||||
deserializer = wsgi.JSONRequestDeserializer()
|
||||
serializer = wsgi.JSONResponseSerializer()
|
||||
return wsgi.Resource(Controller(conf), deserializer, serializer)
|
||||
return wsgi.Resource(Datacenters_Controller(conf), deserializer, serializer)
|
||||
|
@ -20,10 +20,6 @@ import routes
|
||||
|
||||
from windc.api.v1 import datacenters
|
||||
from windc.api.v1 import services
|
||||
|
||||
#from . import tasks
|
||||
|
||||
|
||||
from openstack.common import wsgi
|
||||
|
||||
|
||||
@ -32,7 +28,7 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class API(wsgi.Router):
|
||||
|
||||
"""WSGI router for balancer v1 API requests."""
|
||||
"""WSGI router for windc v1 API requests."""
|
||||
|
||||
def __init__(self, conf, **local_conf):
|
||||
self.conf = conf
|
||||
@ -41,16 +37,20 @@ class API(wsgi.Router):
|
||||
datacenter_resource = datacenters.create_resource(self.conf)
|
||||
datacenter_collection = tenant_mapper.collection(
|
||||
"datacenters", "datacenter",
|
||||
controller=datacenter_resource, member_prefix="/{datacenter_id}",
|
||||
controller=datacenter_resource,
|
||||
member_prefix="/{datacenter_id}",
|
||||
formatted=False)
|
||||
service_resource = services.create_resource(self.conf)
|
||||
service_collection = datacenter_collection.member.collection('services', 'service',
|
||||
controller=service_resource, member_prefix="/{service_id}",
|
||||
formatted=False)
|
||||
service_collection.member.connect("/{status}", action="changeServiceStatus",
|
||||
conditions={'method': ["PUT"]})
|
||||
service_collection = datacenter_collection.member.\
|
||||
collection('services','service',
|
||||
controller=service_resource,
|
||||
member_prefix="/{service_id}",
|
||||
formatted=False)
|
||||
service_collection.member.connect("/{status}",
|
||||
action="changeServiceStatus",
|
||||
conditions={'method': ["PUT"]})
|
||||
mapper.connect("/servicetypes",
|
||||
controller=datacenter_resource,
|
||||
action="show_servicetypes",
|
||||
conditions={'method': ["GET"]})
|
||||
controller=datacenter_resource,
|
||||
action="show_servicetypes",
|
||||
conditions={'method': ["GET"]})
|
||||
super(API, self).__init__(mapper)
|
||||
|
@ -26,22 +26,17 @@ from windc.db import api as db_api
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Controller(object):
|
||||
class Services_Controller(object):
|
||||
def __init__(self, conf):
|
||||
LOG.debug("Creating services controller with config:"
|
||||
"services.py %s", conf)
|
||||
self.conf = conf
|
||||
|
||||
@utils.verify_tenant
|
||||
def findLBforVM(self, req, tenant_id, vm_id):
|
||||
LOG.debug("Got index request. Request: %s", req)
|
||||
result = core_api.lb_find_for_vm(self.conf, tenant_id, vm_id)
|
||||
return {'loadbalancers': result}
|
||||
|
||||
@utils.verify_tenant
|
||||
def index(self, req, tenant_id, datacenter_id):
|
||||
LOG.debug("Got index request. Request: %s", req)
|
||||
result = core_api.service_get_index(self.conf, tenant_id, datacenter_id)
|
||||
result = core_api.service_get_index(self.conf, tenant_id,
|
||||
datacenter_id)
|
||||
return {'services': result}
|
||||
|
||||
@utils.http_success_code(202)
|
||||
@ -61,19 +56,22 @@ class Controller(object):
|
||||
@utils.verify_tenant
|
||||
def delete(self, req, tenant_id, datacenter_id, service_id):
|
||||
LOG.debug("Got delete request. Request: %s", req)
|
||||
core_api.delete_service(self.conf, tenant_id, datacenter_id, service_id)
|
||||
core_api.delete_service(self.conf, tenant_id,
|
||||
datacenter_id, service_id)
|
||||
|
||||
@utils.verify_tenant
|
||||
def show(self, req, tenant_id, datacenter_id, service_id):
|
||||
LOG.debug("Got loadbalancerr info request. Request: %s", req)
|
||||
result = core_api.service_get_data(self.conf, tenant_id, datacenter_id, service_id)
|
||||
result = core_api.service_get_data(self.conf, tenant_id,
|
||||
datacenter_id, service_id)
|
||||
return {'service': result}
|
||||
|
||||
@utils.http_success_code(202)
|
||||
@utils.verify_tenant
|
||||
def update(self, req, tenant_id, datacenter_id, service_id, body):
|
||||
LOG.debug("Got update request. Request: %s", req)
|
||||
core_api.update_service(self.conf, tenant_id, datacenter_id, service_id, body)
|
||||
core_api.update_service(self.conf, tenant_id, datacenter_id,
|
||||
service_id, body)
|
||||
return {'service': {'id': service_id}}
|
||||
|
||||
|
||||
@ -81,7 +79,4 @@ def create_resource(conf):
|
||||
"""Services resource factory method"""
|
||||
deserializer = wsgi.JSONRequestDeserializer()
|
||||
serializer = wsgi.JSONResponseSerializer()
|
||||
return wsgi.Resource(Controller(conf), deserializer, serializer)
|
||||
|
||||
|
||||
|
||||
return wsgi.Resource(Services_Controller(conf), deserializer, serializer)
|
||||
|
@ -46,7 +46,7 @@ from windc.common import utils
|
||||
|
||||
|
||||
bind_opts = [
|
||||
cfg.StrOpt('bind_host', default='0.0.0.0'),
|
||||
cfg.StrOpt('bind_host', default='localhost'),
|
||||
cfg.IntOpt('bind_port'),
|
||||
]
|
||||
|
||||
|
@ -51,19 +51,22 @@ def update_dc(conf, tenant_id, datacenter_id, body):
|
||||
old_dc = copy.deepcopy(dc)
|
||||
db_api.pack_update(dc, body)
|
||||
dc = db_api.datacenter_update(conf, datacenter_id, dc)
|
||||
event = events.Event(events.SCOPE_DATACENTER_CHANGE, events.ACTION_MODIFY)
|
||||
event = events.Event(events.SCOPE_DATACENTER_CHANGE,
|
||||
events.ACTION_MODIFY)
|
||||
event.previous_state = old_dc
|
||||
events.change_event(conf, event, dc)
|
||||
pass
|
||||
|
||||
def service_get_index(conf, tenant_id, datacenter_id):
|
||||
srvcs = db_api.service_get_all_by_datacenter_id(conf, tenant_id, dtacenter_id)
|
||||
srvcs = db_api.service_get_all_by_datacenter_id(conf, tenant_id,
|
||||
datacenter_id)
|
||||
srv_list = [db_api.unpack_extra(srv) for srv in srvcs]
|
||||
return srv_list
|
||||
pass
|
||||
|
||||
def create_service(conf, params):
|
||||
# We need to pack all attributes which are not defined by the model explicitly
|
||||
# We need to pack all attributes which are not defined
|
||||
# by the model explicitly
|
||||
srv_params = db_api.service_pack_extra(params)
|
||||
srv = db_api.service_create(conf, srv_params)
|
||||
event = events.Event(events.SCOPE_SERVICE_CHANGE, events.ACTION_ADD)
|
||||
@ -80,7 +83,7 @@ def delete_service(conf, tenant_id, datacenter_id, service_id):
|
||||
pass
|
||||
|
||||
def service_get_data(conf, tenant_id, datacenter_id, service_id):
|
||||
srv = db_api.service_get(conf,service_id, tenant_id)
|
||||
srv = db_api.service_get(conf, service_id, tenant_id)
|
||||
srv_data = db_api.unpack_extra(srv)
|
||||
return srv_data
|
||||
pass
|
||||
@ -93,4 +96,4 @@ def update_service(conf, tenant_id, datacenter_id, service_id, body):
|
||||
event = events.Event(events.SCOPE_SERVICE_CHANGE, events.ACTION_MODIFY)
|
||||
event.previous_state = old_srv
|
||||
events.change_event(conf, event, srv)
|
||||
pass
|
||||
pass
|
||||
|
@ -115,31 +115,10 @@ def service_get(conf, service_id, tenant_id=None, session=None):
|
||||
raise exception.ServiceNotFound(service_ref=service_ref)
|
||||
return service_ref
|
||||
|
||||
|
||||
def service_get_all_by_project(conf, tenant_id):
|
||||
session = get_session(conf)
|
||||
query = session.query(models.Service).filter_by(tenant_id=tenant_id)
|
||||
return query.all()
|
||||
|
||||
|
||||
def service_get_all_by_vm_id(conf, tenant_id, vm_id):
|
||||
session = get_session(conf)
|
||||
query = session.query(models.Service).distinct().\
|
||||
filter_by(tenant_id=tenant_id).\
|
||||
filter(vm_id == vm_id)
|
||||
return query.all()
|
||||
|
||||
|
||||
def service_get_all_by_datacenter_id(conf, tenant_id, datacenter_id):
|
||||
session = get_session(conf)
|
||||
query = session.query(models.Service).filter_by(datacenter_id=datacenter_id)
|
||||
service_refs = query.all()
|
||||
if not service_refs:
|
||||
raise exception.ServiceNotFound('No service '
|
||||
'for the datacenter %s found'
|
||||
% datacenter_id)
|
||||
return service_refs
|
||||
|
||||
return query.all()
|
||||
|
||||
def service_create(conf, values):
|
||||
session = get_session(conf)
|
||||
@ -149,7 +128,6 @@ def service_create(conf, values):
|
||||
session.add(service_ref)
|
||||
return service_ref
|
||||
|
||||
|
||||
def service_update(conf, service_id, values):
|
||||
session = get_session(conf)
|
||||
with session.begin():
|
||||
@ -158,13 +136,23 @@ def service_update(conf, service_id, values):
|
||||
service_ref['updated_at'] = datetime.datetime.utcnow()
|
||||
return service_ref
|
||||
|
||||
|
||||
def service_destroy(conf, service_id):
|
||||
session = get_session(conf)
|
||||
with session.begin():
|
||||
service_ref = service_get(conf, service_id, session=session)
|
||||
session.delete(service_ref)
|
||||
|
||||
def service_get_all_by_project(conf, tenant_id):
|
||||
session = get_session(conf)
|
||||
query = session.query(models.Service).filter_by(tenant_id=tenant_id)
|
||||
return query.all()
|
||||
|
||||
def service_get_all_by_vm_id(conf, tenant_id, vm_id):
|
||||
session = get_session(conf)
|
||||
query = session.query(models.Service).distinct().\
|
||||
filter_by(tenant_id=tenant_id).\
|
||||
filter(vm_id == vm_id)
|
||||
return query.all()
|
||||
|
||||
def service_count_active_by_datacenter(conf, datacenter_id):
|
||||
session = get_session(conf)
|
||||
@ -174,5 +162,3 @@ def service_count_active_by_datacenter(conf, datacenter_id):
|
||||
filter_by(status=service_status.ACTIVE).\
|
||||
count()
|
||||
return service_count
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user