Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index f4a78a3..296098f 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -769,14 +769,6 @@
(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),
#('Deployment Networks', {'fields': ['deployments'], 'classes':['suit-tab suit-tab-deployments']}),
]
- suit_form_tabs =(('general', 'Site Details'),
- ('users','Users'),
- ('siteprivileges','Privileges'),
- ('deployments','Deployments'),
- ('slices','Slices'),
- #('nodes','Nodes'),
- ('tags','Tags'),
- )
readonly_fields = ['backend_status_text', 'accountLink']
user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'accountLink']
@@ -785,8 +777,26 @@
list_display_links = ('backend_status_icon', 'name', )
filter_horizontal = ('deployments',)
inlines = [SliceInline,UserInline,TagInline, SitePrivilegeInline, SiteDeploymentInline]
+ admin_inlines = [ControllerSite]
search_fields = ['name']
+ @property
+ def suit_form_tabs(self):
+ tabs = [('general', 'Site Details'),
+ ('users','Users'),
+ ('siteprivileges','Privileges'),
+ ('deployments','Deployments'),
+ ('slices','Slices'),
+ #('nodes','Nodes'),
+ ('tags','Tags'),
+ ]
+
+ request=getattr(_thread_locals, "request", None)
+ if request and request.user.is_admin:
+ tabs.append( ('admin-only', 'Admin-Only') )
+
+ return tabs
+
def queryset(self, request):
return Site.select_by_user(request.user)
@@ -892,7 +902,7 @@
verbose_name_plural = "Controller Slices"
suit_classes = 'suit-tab suit-tab-admin-only'
fields = ['backend_status_icon', 'controller', 'tenant_id']
- readonly_fields = ('backend_status_icon', )
+ readonly_fields = ('backend_status_icon', 'controller' )
class SliceAdmin(PlanetStackBaseAdmin):
form = SliceForm
@@ -1191,6 +1201,14 @@
suit_classes = 'suit-tab suit-tab-dashboards'
fields = ['user', 'dashboardView', 'order']
+class ControllerUserInline(PlStackTabularInline):
+ model = ControllerUser
+ extra = 0
+ suit_classes = 'suit-tab suit-tab-admin-only'
+ fields = ['controller', 'user', 'kuser_id']
+ readonly_fields=['controller']
+
+
class UserAdmin(PermissionCheckingAdminMixin, UserAdmin):
# Note: Make sure PermissionCheckingAdminMixin is listed before
# admin.ModelAdmin in the class declaration.
@@ -1208,7 +1226,7 @@
list_display = ('email', 'firstname', 'lastname', 'site', 'last_login')
list_filter = ('site',)
inlines = [SlicePrivilegeInline,SitePrivilegeInline,UserDashboardViewInline]
-
+ admin_inlines = [ControllerUserInline]
fieldListLoginDetails = ['backend_status_text', 'email','site','password','is_active','is_readonly','is_admin','public_key']
fieldListContactInfo = ['firstname','lastname','phone','timezone']
@@ -1236,12 +1254,17 @@
if getattr(_thread_locals, "obj", None) is None:
return []
else:
- return (('general','Login Details'),
+ tabs = [('general','Login Details'),
('contact','Contact Information'),
('sliceprivileges','Slice Privileges'),
('siteprivileges','Site Privileges'),
- ('controllerprivileges','Controller Privileges'),
- ('dashboards','Dashboard Views'))
+ ('dashboards','Dashboard Views')]
+
+ request=getattr(_thread_locals, "request", None)
+ if request and request.user.is_admin:
+ tabs.append( ('admin-only', 'Admin-Only') )
+
+ return tabs
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'site':
diff --git a/planetstack/core/dashboard/views/view_common.py b/planetstack/core/dashboard/views/view_common.py
index bccd7d2..9d979e6 100644
--- a/planetstack/core/dashboard/views/view_common.py
+++ b/planetstack/core/dashboard/views/view_common.py
@@ -73,7 +73,7 @@
for sliver in slice.slivers.all():
#sites_used['deploymentSites'] = sliver.node.deployment.name
# sites_used[sliver.image.name] = sliver.image.name
- sites_used[sliver.node.site_deployment.site.name] = 1 #sliver.numberCores
+ sites_used[sliver.node.site_deployment.site] = 1 #sliver.numberCores
sliceid = Slice.objects.get(id=entry.slice.id).id
try:
sliverList = Sliver.objects.filter(slice=entry.slice.id)
diff --git a/planetstack/core/models/site.py b/planetstack/core/models/site.py
index 881468a..4b42815 100644
--- a/planetstack/core/models/site.py
+++ b/planetstack/core/models/site.py
@@ -282,9 +282,9 @@
objects = ControllerLinkManager()
deleted_objects = ControllerLinkDeletionManager()
- site = models.ForeignKey(Site,related_name='sitedeployment')
- deployment = models.ForeignKey(Deployment,related_name='sitedeployment')
- controller = models.ForeignKey(Controller, null=True, blank=True, related_name='sitedeployment')
+ site = models.ForeignKey(Site,related_name='sitedeployments')
+ deployment = models.ForeignKey(Deployment,related_name='sitedeployments')
+ controller = models.ForeignKey(Controller, null=True, blank=True, related_name='sitedeployments')
availability_zone = models.CharField(max_length=200, null=True, blank=True, help_text="OpenStack availability zone")
def __unicode__(self): return u'%s %s' % (self.deployment, self.site)
diff --git a/planetstack/core/views/stats.py b/planetstack/core/views/stats.py
index 46ebe2e..421fbfe 100644
--- a/planetstack/core/views/stats.py
+++ b/planetstack/core/views/stats.py
@@ -5,7 +5,8 @@
def Stats(request):
model = request.GET['model_name']
pk = int(request.GET['pk'])
- meter = int(request.GET['meter'])
+ meter = request.GET['meter']
+ controller_name = request.GET['controller_name']
- meters = monitor.get_meters(meter, model, pk)
- return json.dumps(meters)
+ meters = driver.get_meter(meter, model, pk)
+ return HttpResponse(json.dumps(meters))
diff --git a/planetstack/model_policies/model_policy_Controller.py b/planetstack/model_policies/model_policy_Controller.py
new file mode 100644
index 0000000..9415bb5
--- /dev/null
+++ b/planetstack/model_policies/model_policy_Controller.py
@@ -0,0 +1,41 @@
+
+def handle(controller):
+ from core.models import Controller, Site, ControllerSite, Slice, ControllerSlice, User, ControllerUser
+ from collections import defaultdict
+ # relations for all sites
+ ctrls_by_site = defaultdict(list)
+ ctrl_sites = ControllerSite.objects.all()
+ for ctrl_site in ctrl_sites:
+ ctrls_by_site[ctrl_site.site].append(ctrl_site.controller)
+ sites = Site.objects.all()
+ for site in sites:
+ if site not in ctrls_by_site or \
+ controller not in ctrls_by_site[site]:
+ controller_site = ControllerSite(controller=controller, site=site)
+ controller_site.save()
+ # relations for all slices
+ ctrls_by_slice = defaultdict(list)
+ ctrl_slices = ControllerSlice.objects.all()
+ for ctrl_slice in ctrl_slices:
+ ctrls_by_slice[ctrl_slice.slice].append(ctrl_slice.controller)
+ slices = Slice.objects.all()
+ for slice in slices:
+ if slice not in ctrls_by_slice or \
+ controller not in ctrls_by_slice:
+ controller_slice = ControllerSlice(controller=controller, slice=slice)
+ controller_slice.save()
+ # relations for all users
+ ctrls_by_user = defaultdict(list)
+ ctrl_users = ControllerUser.objects.all()
+ for ctrl_user in ctrl_users:
+ ctrls_by_user[ctrl_user.user].append(ctrl_user.controller)
+ users = User.objects.all()
+ for user in users:
+ if user not in ctrls_by_user or \
+ controller not in ctrls_by_user[user]:
+ controller_user = ControllerUser(controller=controller, user=user)
+ controller_user.save()
+
+
+
+
diff --git a/planetstack/monitor/monitordriver.py b/planetstack/monitor/monitordriver.py
index 77e8bfd..50e208c 100644
--- a/planetstack/monitor/monitordriver.py
+++ b/planetstack/monitor/monitordriver.py
@@ -7,6 +7,7 @@
self['average'] = 0
self['sum'] = 0
self['unit'] = 'units'
+ self['stat_list']=[]
# stat_list is a list of dicts
# [ {'timestamp': datetime, 'value': value} ]
diff --git a/planetstack/openstack_observer/ceilometer.py b/planetstack/openstack_observer/ceilometer.py
index 7383524..00c1238 100644
--- a/planetstack/openstack_observer/ceilometer.py
+++ b/planetstack/openstack_observer/ceilometer.py
@@ -8,9 +8,10 @@
import datetime
import time
from monitor.monitordriver import *
-from core.models import *
+import pdb
def object_to_filter(model_name, pk):
+ from core.models import *
filter_dict = {
'Slice':[Slice, 'tenant_id', 'project_id'],
'Sliver':[Sliver, 'instance_id', 'resource_id'],
@@ -19,7 +20,7 @@
mod,field,tag = filter_dict[model_name]
obj = mod.objects.get(pk=pk)
- return '%s=%s'%(tag,mod[field])
+ return '%s=%s'%(tag,getattr(obj,field))
def cli_to_array(cli_query):
@@ -70,35 +71,40 @@
def meters_to_stats(meters):
stats = DashboardStatistics()
for m in meters:
- timestamp = datetime.datetime.strptime(m.duration_start,'%Y-%m-%dT%H:%M:%S')
- stats.stat_list.append({'timestamp':timestamp, 'value':m.sum})
- stats.sum+=m.sum
- stats.average+=m.sum
- stats.unit = 'ns'
+ timestamp = m.duration_start
+ stats['stat_list'].append({'timestamp':timestamp, 'value':m.sum})
+ stats['sum']+=m.sum
+ stats['average']+=m.sum
+ stats['unit'] = 'ns'
- stats.average/=len(meters)
+ if (len(meters)):
+ stats['average']/=len(meters)
+ else:
+ stats['average']=0
return stats
-
class CeilometerDriver(MonitorDriver):
def get_meter(self, meter, obj, pk, keystone=None):
- if (not keystone):
- keystone = {}
- keystone['username']=env['OS_USERNAME']
- keystone['password']=env['OS_PASSWORD']
- keystone['auth_url']=env['OS_AUTH_URL']
- keystone['tenant_name']=env['OS_TENANT_NAME']
- keystone['os_cacert']=env['OS_CACERT']
+ keystone = {}
+ keystone['os_username']=env['OS_USERNAME']
+ keystone['os_password']=env['OS_PASSWORD']
+ keystone['os_auth_url']=env['OS_AUTH_URL']
+ keystone['os_tenant_name']=env['OS_TENANT_NAME']
+ keystone['os_cacert']=env['OS_CACERT']
+ keystone['os_region_name']=env['OS_REGION_NAME']
- ceilometer_client = client._get_ksclient(**keystone)
- token = ceilometer_client.auth_token
+ keystone['username']=env['OS_USERNAME']
+ keystone['password']=env['OS_PASSWORD']
+ keystone['auth_url']=env['OS_AUTH_URL']
+ keystone['tenant_name']=env['OS_TENANT_NAME']
+ keystone['cacert']=env['OS_CACERT']
+ keystone['region_name']=env['OS_REGION_NAME']
- ceilo_endpoint = client._get_endpoint(ceilometer_client, **keystone)
- #ceilometer = client.get_client(2, username=keystone['username'], password=keystone['password'], tenant_name=keystone['tenant_name'], auth_url=keystone['auth_url'])
+ keystone['auth_plugin']=client.AuthPlugin(**keystone)
- ceilometer = client.Client('2',endpoint = ceilo_endpoint, token = lambda: token)
-
+ ceilometer = client.get_client(2,**keystone)
+
cur_ts = datetime.datetime.fromtimestamp(time.time()-86400)
str_ts = cur_ts.strftime('%Y-%m-%dT%H:%M:%S')
diff --git a/planetstack/openstack_observer/steps/__init__.py b/planetstack/openstack_observer/steps/__init__.py
index 6eec315..c70b0c0 100644
--- a/planetstack/openstack_observer/steps/__init__.py
+++ b/planetstack/openstack_observer/steps/__init__.py
@@ -1,6 +1,6 @@
-from .sync_controller_sites import SyncControllerSites
-from .sync_controller_slices import SyncControllerSlices
-from .sync_controller_users import SyncControllerUsers
-from .sync_controller_site_privileges import SyncControllerSitePrivileges
-from .sync_controller_slice_privileges import SyncControllerSlicePrivileges
-from .sync_controller_networks import SyncControllerNetworks
+#from .sync_controller_sites import SyncControllerSites
+#from .sync_controller_slices import SyncControllerSlices
+#from .sync_controller_users import SyncControllerUsers
+#from .sync_controller_site_privileges import SyncControllerSitePrivileges
+#from .sync_controller_slice_privileges import SyncControllerSlicePrivileges
+#from .sync_controller_networks import SyncControllerNetworks
diff --git a/planetstack/openstack_observer/steps/sync_slivers.py b/planetstack/openstack_observer/steps/sync_slivers.py
index 8488b66..75b0b1e 100644
--- a/planetstack/openstack_observer/steps/sync_slivers.py
+++ b/planetstack/openstack_observer/steps/sync_slivers.py
@@ -104,8 +104,8 @@
controller = sliver.node.site_deployment.controller
tenant_fields = {'endpoint':controller.auth_url,
- 'admin_user': sliver.creator.username,
- 'admin_password': sliver.creator.password,
+ 'admin_user': sliver.creator.email,
+ 'admin_password': sliver.creator.reomote_password,
'admin_tenant': sliver.slice.name,
'tenant': sliver.slice.name,
'tenant_description': sliver.slice.description,
diff --git a/planetstack/openstack_observer/steps/sync_slivers.yaml b/planetstack/openstack_observer/steps/sync_slivers.yaml
index 9ec5283..0cf30df 100644
--- a/planetstack/openstack_observer/steps/sync_slivers.yaml
+++ b/planetstack/openstack_observer/steps/sync_slivers.yaml
@@ -39,22 +39,4 @@
{{ k }} : "{{ v }}"
{% endfor %}
{% endif %}
- {% else %}
- state: present
- image_id: {{ image_id }}
- key_name: {{ key_name }}
- wait_for: 200
- flavor_id: {{ flavor_id }}
- user_data: "{{ user_data }}"
- nics:
- {% for net in nics %}
- - net-id: {{ net }}
- {% endfor %}
-
- {% if meta %}
- meta:
- {% for k,v in meta.items() %}
- {{ k }} : "{{ v }}"
- {% endfor %}
- {% endif %}
{% endif %}