Skip to content

Commit

Permalink
renamed vm to resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Hamilton committed Aug 10, 2018
1 parent 8d35554 commit 0b859f4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
34 changes: 17 additions & 17 deletions testpool/db/testpool_profile/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,29 @@ def profile_acquire(request, profile_name):
LOGGER.info("profile_acquire found %s", profile_name)

try:
vms = profile.resource_set.filter(status=Resource.READY)
rsrcs = profile.resource_set.filter(status=Resource.READY)

if vms.count() == 0:
if rsrcs.count() == 0:
msg = "profile_acquire %s all resources taken" % profile_name
LOGGER.info(msg)
return JsonResponse({"msg": msg}, status=403)
##
# Pick the first resource.
vm1 = vms[0]
rsrc = rsrcs[0]
##
except Resource.DoesNotExist:
msg = "profile %s empty" % profile_name
LOGGER.error(msg)
return JsonResponse({"msg": msg}, status=403)

##
# assert vm1 defined.
vm1.transition(Resource.RESERVED, Resource.ACTION_DESTROY,
expiration_seconds)
# assert resource defined.
rsrc.transition(Resource.RESERVED, Resource.ACTION_DESTROY,
expiration_seconds)

##
LOGGER.info("profile %s resource acquired %s", profile_name, vm1.name)
serializer = ResourceSerializer(vm1)
LOGGER.info("profile %s resource acquired %s", profile_name, rsrc.name)
serializer = ResourceSerializer(rsrc)
return JSONResponse(serializer.data)
##
else:
Expand All @@ -140,27 +140,27 @@ def profile_acquire(request, profile_name):


@csrf_exempt
def profile_release(request, vm_id):
def profile_release(request, rsrc_id):
""" Release Resource. """

LOGGER.info("testpool_profile.api.profile_release %s", vm_id)
LOGGER.info("testpool_profile.api.profile_release %s", rsrc_id)

if request.method == 'GET':
try:
vm1 = Resource.objects.get(id=vm_id)
rsrc = Resource.objects.get(id=rsrc_id)
except Resource.DoesNotExist:
msg = "profile for %s not found" % vm_id
msg = "profile for %s not found" % rsrc_id
logging.error(msg)
return JsonResponse({"msg": msg}, status=403)

if vm1.status != Resource.RESERVED:
raise PermissionDenied("Resource %s is not reserved" % vm_id)
if rsrc.status != Resource.RESERVED:
raise PermissionDenied("Resource %s is not reserved" % rsrc_id)

##
# assert vm1 defined.
vm1.transition(Resource.PENDING, Resource.ACTION_DESTROY, 1)
# assert rsrc defined.
rsrc.transition(Resource.PENDING, Resource.ACTION_DESTROY, 1)
##
content = {"detail": "Resource %s released" % vm_id}
content = {"detail": "Resource %s released" % rsrc_id}

return JSONResponse(content)
else:
Expand Down
6 changes: 3 additions & 3 deletions testpool/db/testpool_profile/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ class ProfileStatsSerializer(serializers.Serializer):
id = serializers.IntegerField()
name = serializers.CharField(max_length=128)
resource_max = serializers.IntegerField()
vm_ready = serializers.IntegerField()
vm_reserved = serializers.IntegerField()
vm_pending = serializers.IntegerField()
rsrc_ready = serializers.IntegerField()
rsrc_reserved = serializers.IntegerField()
rsrc_pending = serializers.IntegerField()
10 changes: 5 additions & 5 deletions testpool/db/testpool_profile/templates/profile/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <H1>Profile</H1>
</tr><tr>
<th>Status</th><td>{{ profile.status_str }}</td>
</tr><tr>
<th>Hosts</th><td>{{profile.vm_set.count}}/{{ profile.resource_max}}</td>
<th>Hosts</th><td>{{profile.resource_set.count}}/{{ profile.resource_max}}</td>
</tr>
</table>

Expand All @@ -27,11 +27,11 @@ <H1>Hosts</H1>
<tr>
<th>Name</th><th>IP Addr</th><th>Status</th>
</tr>
{% for vm in vms %}
{% for rsrc in rsrcs %}
<tr>
<td>{{ vm.name }}</td>
<td>{{ vm.ip_addr }}</td>
<td>{{ vm.status_as_str }}</td>
<td>{{ rsrc.name }}</td>
<td>{{ rsrc.ip_addr }}</td>
<td>{{ rsrc.status_as_str }}</td>
</tr>
{% endfor %}
</table>
Expand Down
8 changes: 4 additions & 4 deletions testpool/db/testpool_profile/templates/profile/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ <H1>Profiles Statistics</H1>
<tr>
<td>{{profile.hostname}}</td>
<td>{{profile.name}}</td>
<td>{{profile.vm_ready}}</td>
<td>{{profile.vm_reserved}}</td>
<td>{{profile.vm_pending}}</td>
<td>{{profile.vm_bad}}</td>
<td>{{profile.rsrc_ready}}</td>
<td>{{profile.rsrc_reserved}}</td>
<td>{{profile.rsrc_pending}}</td>
<td>{{profile.rsrc_bad}}</td>
<td>{{profile.resource_max}}</td>
<td><a href="profile/detail/{{profile.name}}">detail</a></td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion testpool/db/testpool_profile/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# pylint: disable=C0103
urlpatterns = [
url(r'api/v1/profile/release/(?P<vm_id>[\d]+$)', api.profile_release),
url(r'api/v1/profile/release/(?P<rsrc_id>[\d]+$)', api.profile_release),
url(r'api/v1/profile/acquire/(?P<profile_name>[\.\w]+$)',
api.profile_acquire),
url(r'api/v1/profile/detail/(?P<profile_name>[\.\w]+$)',
Expand Down
20 changes: 10 additions & 10 deletions testpool/db/testpool_profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ def __init__(self, profile):
self.connection = profile.host.connection
self.name = profile.name
self.resource_max = profile.resource_max
self.vm_ready = 0
self.vm_reserved = 0
self.vm_pending = 0
self.vm_bad = 0
self.rsrc_ready = 0
self.rsrc_reserved = 0
self.rsrc_pending = 0
self.rsrc_bad = 0

for item in models.Resource.objects.filter(profile=profile):
if item.status == models.Resource.RESERVED:
self.vm_reserved += 1
self.rsrc_reserved += 1
elif item.status == models.Resource.PENDING:
self.vm_pending += 1
self.rsrc_pending += 1
elif item.status == models.Resource.READY:
self.vm_ready += 1
self.rsrc_ready += 1
elif item.status == models.Resource.BAD:
self.vm_bad += 1
self.rsrc_bad += 1


def profile_list(_):
Expand All @@ -74,9 +74,9 @@ def detail(_, profile):
LOGGER.debug("profile/detail/%s", profile)

profile1 = models.Profile.objects.get(name=profile)
vms = [item for item in models.Host.objects.filter(profile=profile1)]
rsrcs = [item for item in models.Host.objects.filter(profile=profile1)]
html_data = {
"vms": vms,
"rsrcs": rsrcs,
"profile": profile1
}

Expand Down

0 comments on commit 0b859f4

Please sign in to comment.