Skip to content

Commit

Permalink
re-pick orphan LV, createtarget without the set -e stuff, admin has t…
Browse files Browse the repository at this point in the history
…emplate change_list for usr total assigned quota value
  • Loading branch information
Sachin Agarwal committed Mar 23, 2015
1 parent 5b6c9d3 commit 88d3af2
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 7 deletions.
24 changes: 19 additions & 5 deletions ssddj/globalstatemanager/bashscripts/createtarget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function VGisThin () {
TARGETMD5=`echo $2 | md5sum | cut -f1 -d" "`
lvolName=lvol-${TARGETMD5:0:8}
VG=`vgdisplay -c | grep $6 | cut -d: -f1 | tr -d ' ' | tr -cd '[[:alnum:]]._-'`
if sudo lvs | egrep -q "$lvolName"; then
echo "Warning: Using previously-created LV "$lvolName
if sudo lvs | grep $VG | egrep -q "$lvolName"; then
echo "Warning: Using previously-created LV "$lvolName "on VG "$VG
else
VGisThin $VG
if [ $? -eq 1 ]; then
Expand All @@ -38,12 +38,10 @@ else
fi
echo $LVCOUTPUT
fi
set -e

lvu=`lvdisplay $VG/$lvolName | grep "LV UUID" | sed 's/LV UUID\s\{0,\}//g' | tr -d '-' | tr -d ' '`
vgu=`echo $6 | tr -d '-' | tr -d ' '`
dmp='/dev/disk/by-id/dm-uuid-LVM-'$vgu$lvu
echo $dmp

#Please use the below line, the other one is a place holder for older saturn server testing on VMs
scstadmin -open_dev disk-${lvu:0:8} -handler vdisk_blockio -attributes filename=$dmp,thin_provisioned=0,rotational=0,write_through=1,blocksize=4096
#scstadmin -open_dev disk-${lvu:0:8} -handler vdisk_blockio -attributes filename=$dmp
Expand All @@ -68,4 +66,20 @@ sudo cp /etc/scst.conf /temp
sudo cp /etc/lvm/backup/$VG /temp/$6
sudo chmod 666 /temp/scst.conf
sudo chmod 666 /temp/$6

#The last thing - checking if everything looks good


if ! grep --quiet "disk-${lvu:0:8}" /etc/scst.conf; then
echo "FAILED = no disk-${lvu:0:8} in /etc/scst.conf"
exit
fi

if ! grep --quiet "$2" /etc/scst.conf; then
echo "FAILED - no entry for target $2 in scst.conf"
exit
fi

echo "SUCCESS: created target $2 on $VG: ($6)"


3 changes: 3 additions & 0 deletions ssddj/globalstatemanager/gsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def ParseLVM(self,strList,delimitStr,paraList):
continue
if len(valueDict) == len(paraList):
rtnDict[valueDict[paraList[0]]] = valueDict

logger.info(rtnDict)
return rtnDict


Expand Down Expand Up @@ -255,6 +257,7 @@ def CreateTarget(self,iqnTarget,iqnInit,sizeinGB,storageip1,storageip2,vguuid):
#self.srv = Connection(self.serverDNS,self.userName,self.keyFile)
cmdStr = " ".join(['sudo',self.rembashpath,self.remoteinstallLoc+'saturn-bashscripts/createtarget.sh',str(sizeinGB),iqnTarget,storageip1,storageip2,iqnInit,vguuid])
#srv.close()
logger.info ("Launching createtarget with \n%s" %(cmdStr,))
exStr=self.Exec(cmdStr)
if exStr == -1:
return -1
Expand Down
1 change: 1 addition & 0 deletions ssddj/ssddj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
TEMPLATE_INFO = True
ALLOWED_HOSTS = ['*']
TEMPLATE_DIRS = (
os.path.join(BASE_DIR,'ssdfrontend','templates'),
os.path.join(BASE_DIR, 'templates'),
)

Expand Down
13 changes: 12 additions & 1 deletion ssddj/ssdfrontend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#limitations under the License.

from django.contrib import admin
from django.contrib.admin.views.main import ChangeList
from django import forms
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
Expand Down Expand Up @@ -342,7 +343,7 @@ def clean_max_alloc_sizeGB(self):
if oldalloc == None:
oldalloc = 0
#logger.info("totalGB = %d, Allocated to all users = %d, This users old allocation = %d" %(totalGB,allocGB,oldalloc))
if totalGB < allocGB+requestedGB-oldalloc:
if (totalGB < allocGB+requestedGB-oldalloc) and (requestedGB > oldalloc):
raise forms.ValidationError("Sorry, cluster capacity exceeded; maximum possible is %d GB" %(totalGB-allocGB+oldalloc,))
except:
logger.error(format_exc())
Expand All @@ -359,10 +360,20 @@ class ProfileInline(admin.StackedInline):
verbose_name_plural = 'Profile'


class UserChangeList(ChangeList):
def get_results(self, *args, **kwargs):
super(UserChangeList,self).get_results(*args, **kwargs)
q = self.result_list.aggregate(total_alloc_GB=db.models.Sum('profile__max_alloc_sizeGB'))
self.total_alloc_GB = q['total_alloc_GB']


class UserAdmin(UserAdmin):
inlines = (ProfileInline,)
list_display = ('username','email', 'max_alloc_GB','used_GB','max_target_GB')

def get_changelist(self, request):
return UserChangeList

def max_target_GB(self, obj):
try:
mts = obj.profile.max_target_sizeGB
Expand Down
100 changes: 100 additions & 0 deletions ssddj/ssdfrontend/templates/admin/change_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls admin_static admin_list %}

{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}" />
{% if cl.formset %}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />
{% endif %}
{% if cl.formset or action_form %}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{% endif %}
{{ media.css }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist table thead th:first-child {width: inherit}
</style>
{% endif %}
{% endblock %}

{% block extrahead %}
{{ block.super }}
{{ media.js }}
{% if action_form %}{% if actions_on_top or actions_on_bottom %}
<script type="text/javascript">
(function($) {
$(document).ready(function($) {
$("tr input.action-select").actions();
});
})(django.jQuery);
</script>
{% endif %}{% endif %}
{% endblock %}

{% block bodyclass %}change-list{% endblock %}

{% if not is_popup %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'admin:app_list' app_label=cl.opts.app_label %}">{{ app_label|capfirst|escape }}</a>
&rsaquo; {{ cl.opts.verbose_name_plural|capfirst }}
</div>
{% endblock %}
{% endif %}

{% block coltype %}flex{% endblock %}

{% block content %}
<div id="content-main">
{% block object-tools %}
{% if has_add_permission %}
<ul class="object-tools">
{% block object-tools-items %}
<li>
{% url cl.opts|admin_urlname:'add' as add_url %}
<a href="{% add_preserved_filters add_url is_popup %}" class="addlink">
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
</a>
</li>
{% endblock %}
</ul>
{% endif %}
{% endblock %}
{% if cl.formset.errors %}
<p class="errornote">
{% if cl.formset.total_error_count == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
</p>
{{ cl.formset.non_form_errors }}
{% endif %}
<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
{% block search %}{% search_form cl %}{% endblock %}
{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}

{% block filters %}
{% if cl.has_filters %}
<div id="changelist-filter">
<h2>{% trans 'Filter' %}</h2>
{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
</div>
{% endif %}
{% endblock %}

<form id="changelist-form" action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
{% if cl.formset %}
<div>{{ cl.formset.management_form }}</div>
{% endif %}

{% block result_list %}
{% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %}
{% result_list cl %}
{% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
{% if cl.total_alloc_GB %} Total quota promised: {{ cl.total_alloc_GB }} GB{% endif %}
{% if cl.total_cluster_GB %} Total cluster size: {{ cl.total_cluster_GB }} GB{% endif %}
{% endblock %}
{% block pagination %}{% pagination cl %}{% endblock %}
</form>
</div>
</div>
{% endblock %}
8 changes: 7 additions & 1 deletion ssddj/utils/targetops.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def ExecMakeTarget(storemedia,targetvguuid,targetHost,clientiqn,serviceName,stor
iqnComponents = t.iqntar.split(':')
if ((serviceName==iqnComponents[1]) and (clientiqnHash==iqnComponents[2])):
logger.info('Target already exists for (serviceName=%s,clientiqn=%s) tuple' % (serviceName,clientiqn))
existingTargetstoremedia = LV.objects.get(target=t).vg.storemedia
try:
existingTargetstoremedia = LV.objects.get(target=t).vg.storemedia
except:
logger.error("Target %s exists in DB but LV does not, inconsistent" %(t.iqntar))
return (-1,"Target %s exists in DB but LV does not, inconsistent" %(t.iqntar))

if (existingTargetstoremedia == storemedia):
return (1,t.iqntar)
else:
Expand Down Expand Up @@ -98,6 +103,7 @@ def ExecMakeTarget(storemedia,targetvguuid,targetHost,clientiqn,serviceName,stor
return (-1, 'Error in host network configuration or ownership for the required subnet, contact storage admin')

if p.CreateTarget(iqnTarget,clientiqn,str(storageSize),storeip1,storeip2,targetvguuid) == 1:
logger.info ("SUCCESSFUL TARGET RUN")
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
config = ConfigParser.RawConfigParser()
config.read(os.path.join(BASE_DIR,'saturn.ini'))
Expand Down

0 comments on commit 88d3af2

Please sign in to comment.