Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
scoping by user
Browse files Browse the repository at this point in the history
  • Loading branch information
buzztroll authored and priteau committed Oct 26, 2012
1 parent cdf619a commit caf32f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions phantomweb/models.py
Expand Up @@ -2,6 +2,11 @@

class LaunchConfigurationDB(models.Model):
name = models.CharField(max_length=128)
username = models.CharField(max_length=128)

class Meta(object):
unique_together = ("name", "username")


class HostMaxPairDB(models.Model):
cloud_name = models.CharField(max_length=128)
Expand Down
22 changes: 11 additions & 11 deletions phantomweb/workload.py
Expand Up @@ -50,9 +50,9 @@ def _get_launch_configuration(phantom_con, lc_db_object):

return site_dict

def _get_all_launch_configurations(phantom_con):
def _get_all_launch_configurations(phantom_con, username):
all_lc_dict = {}
lc_db_objects_a = LaunchConfigurationDB.objects.all()
lc_db_objects_a = LaunchConfigurationDB.objects.all(username=username)
for lc_db_object in lc_db_objects_a:
site_dict = _get_launch_configuration(phantom_con, lc_db_object)
all_lc_dict[lc_db_object.name] = site_dict
Expand Down Expand Up @@ -272,7 +272,7 @@ def phantom_lc_load(request_params, userobj):

phantom_con = _get_phantom_con(userobj)

all_lc_dict = _get_all_launch_configurations(phantom_con)
all_lc_dict = _get_all_launch_configurations(phantom_con, userobj._user_dbobject.access_key)
iaas_info = {}
for cloud_name in clouds_d:
try:
Expand Down Expand Up @@ -314,9 +314,9 @@ def phantom_lc_save(request_params, userobj):
_parse_param_name("common", param_name, request_params, lc_dict)
_parse_param_name("rank", param_name, request_params, lc_dict)

lc_db_object = LaunchConfigurationDB.objects.filter(name=lc_name)
lc_db_object = LaunchConfigurationDB.objects.filter(name=lc_name, username=userobj._user_dbobject.access_key)
if not lc_db_object:
lc_db_object = LaunchConfigurationDB.objects.create(name=lc_name)
lc_db_object = LaunchConfigurationDB.objects.create(name=lc_name, username=userobj._user_dbobject.access_key)
else:
lc_db_object = lc_db_object[0]
lc_db_object.save()
Expand Down Expand Up @@ -387,9 +387,9 @@ def phantom_lc_delete(request_params, userobj):
raise PhantomWebException("Error communication with Phantom REST: %s" % (str(ex)))

error_message = ""
lc_db_object = LaunchConfigurationDB.objects.filter(name=lc_name)
lc_db_object = LaunchConfigurationDB.objects.filter(name=lc_name, username=userobj._user_dbobject.access_key)
if not lc_db_object or len(lc_db_object) < 1:
raise PhantomWebException("No such launch configuration %s. Misconfigured service" % (lc.name))
raise PhantomWebException("No such launch configuration %s. Misconfigured service" % (lc_name))
lc_db_object = lc_db_object[0]
host_vm_db_a = HostMaxPairDB.objects.filter(launch_config=lc_db_object)
if not host_vm_db_a:
Expand Down Expand Up @@ -428,7 +428,7 @@ def phantom_domain_load(request_params, userobj):
phantom_con = _get_phantom_con(userobj)

domains = _get_all_domains(phantom_con)
all_lc_dict = _get_all_launch_configurations(phantom_con)
all_lc_dict = _get_all_launch_configurations(phantom_con, userobj._user_dbobject.access_key)

lc_names = []
for name in all_lc_dict.keys():
Expand All @@ -453,7 +453,7 @@ def phantom_domain_start(request_params, userobj):
vm_count = request_params["vm_count"]


lc_db_object = LaunchConfigurationDB.objects.filter(name=lc_name)
lc_db_object = LaunchConfigurationDB.objects.filter(name=lc_name, username=userobj._user_dbobject.access_key)
if not lc_db_object or len(lc_db_object) < 1:
raise PhantomWebException("The launch configuration %s is not known to the web application." % (lc_name))

Expand Down Expand Up @@ -567,12 +567,12 @@ def phantom_domain_details(request_params, userobj):
cloud_edit_dict = userobj.get_clouds()

lc_name = asg.launch_config_name
lc_db_objects_a = LaunchConfigurationDB.objects.filter(name=lc_name)
lc_db_objects_a = LaunchConfigurationDB.objects.filter(name=lc_name, username=userobj._user_dbobject.access_key)
if not lc_db_objects_a:
msg = "Could not find the launch configuration '%s' associated with the domain '%s'" % (lc_name, domain_name)
g_general_log.error(msg)
raise PhantomWebException(msg)

lc_db_object = lc_db_objects_a[0]
site_dict = _get_launch_configuration(phantom_con, lc_db_object)

Expand Down

0 comments on commit caf32f7

Please sign in to comment.