Skip to content

Commit

Permalink
Merge 2054370 into 09562a0
Browse files Browse the repository at this point in the history
  • Loading branch information
zefciu committed Jun 26, 2014
2 parents 09562a0 + 2054370 commit 81c350a
Show file tree
Hide file tree
Showing 69 changed files with 2,268 additions and 157 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ Change Log
----------


2.0.0-stable
~~~~~~~~~~~~

Released on June 20, 2014,

This is a stable release.

2.0.0-rc8
~~~~~~~~~

Expand Down
41 changes: 41 additions & 0 deletions contrib/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Ralph
#
# VERSION 2.0.0-3

FROM ubuntu
MAINTAINER Marcin Kliks marcin.kliks@allegro.pl

RUN apt-get update
RUN apt-get install -y python2.7 python-dev python-virtualenv build-essential libbz2-dev libfreetype6-dev libgdbm-dev libxft-dev
RUN apt-get install -y libjpeg-dev libldap2-dev libltdl-dev libmysqlclient-dev libreadline-dev libsasl2-dev libsqlite3-dev
RUN apt-get install -y libssl-dev libxslt1-dev ncurses-dev zlib1g-dev
RUN apt-get install -y libcap2-bin
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y redis-server mysql-server libmysqlclient-dev libmysqld-dev
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openssh-server apache2 supervisor
RUN apt-get install -y git
RUN /usr/bin/mysqld_safe & \
sleep 10s && \
echo "CREATE DATABASE ralph DEFAULT CHARACTER SET 'utf8'" | mysql && \
echo "GRANT ALL ON ralph.* TO ralph@'%' IDENTIFIED BY 'ralph'; FLUSH PRIVILEGES" | mysql
#RUN echo 'alter database ralph character set utf8 collate utf8_polish_ci' | mysql -u root
RUN pip install -U pip
RUN pip install -U flake8
RUN git clone http://github.com/allegro/ralph.git /root/ralph-git/ralph
RUN cd /root/ralph-git/ralph; make install
RUN ralph makeconf
ADD settings /.ralph/additional-settings
ADD createsuperuser.py /root/createsuperuser.py
RUN cat /.ralph/additional-settings >>/.ralph/settings
RUN /usr/bin/mysqld_safe & \
sleep 10 && \
ralph syncdb --all --noinput && \
ralph migrate --fake && \
ralph createsuperuser ralph --noinput --user ralph --email ralph@allegrogroup.com && \
python /root/createsuperuser.py && \
ralph collectstatic -l --noinput
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 8000 22

CMD ["/usr/bin/supervisord"]

11 changes: 11 additions & 0 deletions contrib/docker/createsuperuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ralph.settings")

from django.contrib.auth.models import User

u = User.objects.get(username='ralph')
u.set_password('ralph')
u.is_superuser = True
u.is_staff = True
u.save()
35 changes: 35 additions & 0 deletions contrib/docker/settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
DEBUG = True
TEMPLATE_DEBUG = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ralph',
'USER': 'ralph',
'PASSWORD': 'ralph',
'HOST': '',
'PORT': '',
'OPTIONS': dict(
),
},
}
CACHES = dict(
default=dict(
BACKEND='django.core.cache.backends.locmem.LocMemCache',
LOCATION='',
TIMEOUT=300,
OPTIONS=dict(
),
KEY_PREFIX='RALPH_',
)
)
RQ_QUEUE_LIST = ('reports', 'reports_pricing', 'default')

RQ_QUEUES = {
'default': {
'HOST': 'localhost',
'PORT': 6379,
'DB': 0,
},
}
for queue in RQ_QUEUE_LIST:
RQ_QUEUES[queue] = dict(RQ_QUEUES['default'])
18 changes: 18 additions & 0 deletions contrib/docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[supervisord]
nodaemon=true

[program:mysql]
command=/usr/bin/mysqld_safe
priority=11

[program:redis]
command=redis-server
priority=12

[program:rqworker]
command=ralph rqworker default reports reports_pricing
priority=13

[program:gunicorn]
command=ralph run_gunicorn -w8 0.0.0.0:8000
priority=14
33 changes: 16 additions & 17 deletions contrib/donpedro_v_2/DonPedro.DTO/BaseDTOResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,34 @@ public string ToJSON()

foreach (var property in this.GetType().GetProperties())
{
if (property.GetValue(this, null) == null)
{
continue;
}
propertyValue = property.GetValue(
this, null
).ToString().Replace(
"\"", "\\\""
).Replace(
@"\", @"\\"
);

if (propertyValue.Length > 0) {
if (propertiesCount == 1)
{
return "\"" + propertyValue + "\"";
}

try
{
parts.Add(
string.Format(
"\"{0}\":\"{1}\"",
Regex.Replace(
property.Name,
@"\B[A-Z]",
new MatchEvaluator(BaseDTOResponse.AppendUnderscore)
).ToLower().Trim(),
propertyValue
)
);
}
catch (NullReferenceException) {}
parts.Add(
string.Format(
"\"{0}\":\"{1}\"",
Regex.Replace(
property.Name,
@"\B[A-Z]",
new MatchEvaluator(BaseDTOResponse.AppendUnderscore)
).ToLower().Trim(),
propertyValue
)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class DiskShareMountDTOResponse : BaseDTOResponse
{
public string Volume { get; set; }
public string SerialNumber { get; set; }
public string Size { get; set; }
}
}
14 changes: 13 additions & 1 deletion contrib/donpedro_v_2/DonPedro.DTO/MacAddressDTOResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace DonPedro.DTO
{
public class MacAddressDTOResponse : BaseDTOResponse
{
public string Mac { get; set; }
private string macAddress;

public string Mac {
get
{
return macAddress;
}

set
{
macAddress = value.Replace(":", "").Replace("-", "").ToUpper();
}
}
}
}
77 changes: 69 additions & 8 deletions contrib/donpedro_v_2/DonPedro.Detectors/FCInfoDetectorSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using DonPedro.DTO;
using DonPedro.Detectors.Exceptions;
using System.Text.RegularExpressions;
using DonPedro.Utils;

namespace DonPedro.Detectors
{
Expand All @@ -16,10 +17,14 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()

try
{
fcinfoResult = ExecuteFcinfoCommand();
fcinfoResult = ExecuteFcinfoCommand("details");
}
catch (ExternalCommandExecutionException)
catch (ExternalCommandExecutionException e)
{
Logger.Instance.LogWarning(
"[GetFCInfo] To get informations about FC cards or disk shares install fcinfo tool."
);
Logger.Instance.LogError(e.ToString());
return fc;
}

Expand All @@ -46,9 +51,10 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()
{
if (modelName.Length > 0)
{
card.ModelName = modelName;
card.ModelName = SanitizeModelName(modelName);
}
fc.Add(card);
modelName = "";
}
card = new FibreChannelDTOResponse();
string[] adapterNameParts = lineParts[1].Trim().Split('-');
Expand All @@ -65,7 +71,7 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()
case "model":
if (modelName.Length > 0)
{
modelName = " " + lineParts[1].Trim();
modelName = modelName + " " + lineParts[1].Trim();
}
else
{
Expand All @@ -87,16 +93,69 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()
}
if (card != null)
{
if (card.ModelName == null)
{
card.ModelName = SanitizeModelName(modelName);
}
fc.Add(card);
}

return fc;
}

protected string ExecuteFcinfoCommand()
public string GetShareWWN(string serialNumber) {
string fcinfoResult = "";
try
{
fcinfoResult = ExecuteFcinfoCommand("mapping");
}
catch (ExternalCommandExecutionException e)
{
Logger.Instance.LogWarning(
"[GetShareWWN] To get informations about FC cards or disk shares install fcinfo tool."
);
Logger.Instance.LogError(e.ToString());
return "";
}

string[] lines = Regex.Split(fcinfoResult, "\r\n");
Regex rgx = new Regex( @"[a-zA-Z0-9]{16}");
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i].Trim();
if (line.Length == 0)
{
continue;
}

if (line.ToLower().Contains(serialNumber.ToLower()))
{
Match m = rgx.Match(line);
if (m.Success)
{
return m.Value;
}
}
}

return "";
}

protected string SanitizeModelName(string modelName)
{
modelName = Regex.Replace(
modelName,
"corporation ",
"",
RegexOptions.IgnoreCase
);
return modelName;
}

protected string ExecuteFcinfoCommand(string option)
{
Process proc = new Process();
proc.StartInfo = PrepareProcessStartInfo();
proc.StartInfo = PrepareProcessStartInfo(option);
try
{
proc.Start();
Expand All @@ -115,9 +174,11 @@ protected string ExecuteFcinfoCommand()
return proc.StandardOutput.ReadToEnd();
}

protected ProcessStartInfo PrepareProcessStartInfo()
protected ProcessStartInfo PrepareProcessStartInfo(string option)
{
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", @"/C %windir%\\Sysnative\\fcinfo.exe /details");
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "fcinfo.exe";
psi.Arguments = "/" + option;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
Expand Down
17 changes: 15 additions & 2 deletions contrib/donpedro_v_2/DonPedro.Detectors/WMIDetectorSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using DonPedro.DTO;
using DonPedro.Utils;
using DonPedro.Detectors;

namespace DonPedro.Detectors
{
Expand Down Expand Up @@ -390,11 +391,12 @@ from Win32_SCSIController
public List<DiskShareMountDTOResponse> GetDiskShareMountInfo()
{
List<DiskShareMountDTOResponse> mounts = new List<DiskShareMountDTOResponse>();
FCInfoDetectorSource fcinfo = new FCInfoDetectorSource();

try
{
SelectQuery query = new SelectQuery(
@"select Model, DeviceID
@"select Model, DeviceID, Size
from Win32_DiskDrive
where Model like '3PARdata%'"
);
Expand All @@ -410,9 +412,20 @@ from Win32_DiskDrive

foreach (ManagementObject snObj in snSearcher.Get())
{
string serialNumber = fcinfo.GetShareWWN(
GetValueAsString(snObj, "SerialNumber")
);
if (serialNumber.Length == 0)
{
continue;
}
DiskShareMountDTOResponse share = new DiskShareMountDTOResponse();
share.Volume = GetValueAsString(obj, "Model");
share.SerialNumber = GetValueAsString(snObj, "SerialNumber");
share.SerialNumber = serialNumber;
share.Size = ConvertSizeToMiB(
Int64.Parse(GetValueAsString(obj, "Size")),
SizeUnits.B
).ToString();

mounts.Add(share);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ public List<SoftwareDTOResponse> GetSoftwareInfo()
List<SoftwareDTOResponse> software = new List<SoftwareDTOResponse>();

software.AddRange(GetSoftwareFromLocalMachine32());
software = MergeSoftwareLists(software, GetSoftwareFromLocalMachine64());
try
{
software = MergeSoftwareLists(software, GetSoftwareFromLocalMachine64());
}
catch (NullReferenceException)
{
// It is a 32 bit machine...
}

return software;
}
Expand Down

0 comments on commit 81c350a

Please sign in to comment.