Skip to content
Snippets Groups Projects
Commit 8a878e58 authored by Chris Hines's avatar Chris Hines
Browse files
parents 7da69d7e 47058e4a
No related branches found
No related tags found
No related merge requests found
Showing
with 511 additions and 31 deletions
#!/usr/bin/env python
import sys, os, string, socket, re
import shlex, multiprocessing, time, shutil, json
import novaclient.v1_1.client as nvclient
from novaclient import client as nvclient
import novaclient.exceptions as nvexceptions
import keystoneclient.v2_0.client as ksclient
from joblib import Parallel, delayed
from multiprocessing import Process, Manager, Pool
from libnmap.process import NmapProcess
from libnmap.parser import NmapParser, NmapParserException
def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
## Fetch the Nova Object
projectName = os.path.basename(sys.argv[0])
nc = nvclient.Client( auth_url=authUrl,
......@@ -16,24 +17,23 @@ def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
api_key=passwd,
project_id=tenantName,
tenant_id=tenantID,
service_type="compute"
version="2"
)
for server in nc.servers.list():
if server.metadata and \
'ansible_host_groups' in server.metadata and \
server.metadata['project_name'] == projectName.strip():
'project_name' in server.metadata:
if server.metadata['project_name'].strip() != projectName.strip(): continue
unwantedChars = """][")("""
rgx = re.compile('[%s]' % unwantedChars)
ansible_groups = rgx.sub('', server.metadata['ansible_host_groups']).split(',')
hostname = socket.gethostbyaddr(server.networks.values()[0][0])[0]
closed=True
while closed:
hostSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if not hostSocket.connect_ex((hostname, 22)):
closed = False
break
time.sleep(5)
hostSocket.close()
novaVolumes = nc.volumes.get_server_volumes(server.id)
# Let's do some port scanning using nmap
nmproc = NmapProcess(hostname, "-p 22 -sV -Pn")
rc = nmproc.run()
if rc != 0: continue
parsed = NmapParser.parse(nmproc.stdout)
# Set Ansible Host Group
for group in ansible_groups:
groupName = group.strip()
......@@ -43,11 +43,12 @@ def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
for key, value in server.metadata.iteritems():
if key not in ('project_name','ansible_host_groups'):
inventory['_meta']['hostvars'][hostname] = { key:value }
if novaVolumes:
inventory['_meta']['hostvars'][hostname]['volumeList'] = [ volume.id for volume in novaVolumes ]
inventory['_meta']['hostvars'][hostname]['status'] = parsed.hosts[0].status
else:
continue
#print inventory
#inventoryList.append(inventory)
#print json.dumps(inventory)
if __name__ == "__main__":
inventory = {}
......
---
-
name: Removing the RDO repository
file: path=/etc/yum.repos.d/rdo-release.repo state=absent
sudo: true
-
name: Install epel-release
yum: name=epel-release-7-5.noarch state=present
sudo: true
-
name: Enable epel
command: yum-config-manager --enable epel
sudo: true
-
name: Installing Base Packages
yum: name={{ item }} state=present
with_items:
- yum-utils
- deltarpm-3.6-3.el7.x86_64
- yum-plugin-versionlock
sudo: true
-
name: Installing Core packages
yum: name="{{ item.software }}-{{ item.version }}.{{ item.arch }}" state=present
with_items: package_list
sudo: true
-
name: Performing version lock on the packages
shell: yum versionlock \*
sudo: true
---
- include: installBasePackages.yml
This diff is collapsed.
......@@ -60,8 +60,8 @@
- name: restart_host
command: shutdown -r now "Reboot triggered by Ansible"
async: 0
poll: 0
async: 900
poll: 60
sudo: true
ignore_errors: true
when: has_been_compiled | failed
......
......@@ -166,7 +166,6 @@
sudo: true
when: karaage_db_init.stdout.find("0") == 0
- name: install postfix
apt: name=postfix state=present
sudo: true
......
......@@ -8,7 +8,8 @@ from karaage.institutes.models import Institute
from karaage.machines.models import MachineCategory
from karaage.people.models import Person, Group
DEBUG = False
CONSOLE_DEBUG = False
class HpcIdInit():
import django
django.setup()
......@@ -18,6 +19,9 @@ class HpcIdInit():
self.path = configfile
self.password = password
self.debug = debug
if not debug:
self.logfile = open("/tmp/kg_init.log", "w")
if self.path and os.path.exists(self.path):
with open(self.path) as data:
config_data = json.load(data)
......@@ -27,11 +31,14 @@ class HpcIdInit():
else:
log("Invalid input data")
def __del__(self):
self.logfile.close()
def log(self, message):
if self.debug:
print message
else:
pass
self.logfile.write(message + "\n")
def getGroup(self, name):
group = None
......@@ -72,6 +79,7 @@ class HpcIdInit():
self.log("Find insititute %s" %(institute.name))
project = Project.objects.create(pid = pid, name = name, institute = institute, group = institute.group, is_active = True, is_approved = True, approved_by = superuser)
if project:
project.leaders.add(superuser)
self.log("Create project OK")
else:
self.log("Create project failed")
......@@ -156,11 +164,32 @@ class HpcIdInit():
institute = Institute.objects.get(name = user["institute_name"])
if institute:
person = Person.objects.create(username = user["username"], email = user["email"], password = self.password, short_name = user["short_name"], full_name = user["full_name"], is_admin = True, is_active = True, institute = institute)
person.full_clean()
if person:
person.set_password(self.password)
person.save()
result = self.addInstituteDelegate(person, institute)
if result:
log("Add super user %s to institute %s delegate" %(person.username, institute.name))
else:
log("Faired to add super user %s to institute %s delegate" %(person.username, institute.name))
person.full_clean()
except:
log("Create super user exception: %s" %(traceback.format_exc()))
finally:
return person
def addInstituteDelegate(self, su, institute):
result = True
try:
delegates = institute.delegates.all().filter(username = su.username)
if len(delegates) == 0:
self.log("Create institution delegate %s"%(su.username))
institute.delegates.add(su)
except:
result = False
self.log("Create institution delegate exception: %s" %(traceback.format_exc()))
finally:
return result
def setup(self):
self.log("Password = %s, debug = %s" %(self.password, self.debug))
......@@ -176,7 +205,7 @@ class HpcIdInit():
if self.mc:
mc = self.getOrCreateMachineCategory(self.mc)
if mc:
self.log("Get machine category = '%s'" %(mc.name))
self.log("Get machine category = '%s'" %(self.mc))
else:
self.log("Failed to get machine category = '%s'" %(self.mc))
if su:
......@@ -198,7 +227,7 @@ def main(argv):
if len(sys.argv) > 2:
config_path = argv[0]
password = argv[1]
debug = DEBUG
debug = CONSOLE_DEBUG
if len(sys.argv) > 3:
debug = argv[2]
init = HpcIdInit(config_path, password, debug)
......
......@@ -31,6 +31,10 @@
#
# DEBUG = True
{% if user_id_file is defined %}
USER_ID_FILES = {{ user_id_file }}
{% endif %}
# Implemented by Shahaan due to the django-pipeline bug
PIPELINE_ENABLED = False
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
......
......@@ -25,3 +25,4 @@
line: /usr/local/Modules/modulefiles
ignore_errors: true
sudo: true
when: ansible_os_family == 'Debian'
---
- name: "Restart MySQL"
service: name=mysql state=restarted
service: name={{ sqlServiceName }} state=restarted
sudo: true
when: ansible_os_family == "Debian"
- name: "Restart MySQL"
service: name=mysqld state=restarted
sudo: true
when: ansible_os_family == "RedHat"
......@@ -32,3 +32,7 @@
args:
chdir: /tmp/slurm-{{ slurm_version }}
creates: "{{ slurm_dir }}/bin/srun"
- name: add slurm log rotate config
template: src=slurmlog.j2 dest=/etc/logrotate.d/slurm mode=644
sudo: true
......@@ -4,6 +4,7 @@
missingok
notifempty
weekly
size 200k
compress
size 800k
}
{% if slurmctrl == inventory_hostname %}
{{ slurmctlddebug.log }}
{{ slurmschedlog.log }}
{% else %}
{{ slurmddebug.log }}
{% endif %}
{
compress
missingok
nocopytruncate
nocreate
nodelaycompress
nomail
notifempty
noolddir
rotate 5
sharedscripts
size=5M
create 640 slurm root
{% if ansible_os_family == 'RedHat' and ansible_distribution_version >= '7' %}
postrotate
{% if slurmctrl == inventory_hostname %}
{{ slurm_dir }}/sbin/slurmctld flushlogs 1>/dev/null || true
{% else %}
{{ slurm_dir }}/sbin/slurmd flushlogs 1>/dev/null || true
{% endif %}
{% else %}
postrotate /etc/init.d/slurm reconfig
{% endif %}
endscript
}
......@@ -32,3 +32,7 @@
sudo: true
when: slurm_dir is not defined
- name: add slurm db log rotate config
template: src=slurmdblog.j2 dest=/etc/logrotate.d/slurmdb mode=644
sudo: true
{{ slurmdbdlog.log }}
{% endif %}
{
compress
missingok
nocopytruncate
nocreate
nodelaycompress
nomail
notifempty
noolddir
rotate 5
sharedscripts
size=5M
create 640 slurm root
{% if ansible_os_family == 'RedHat' and ansible_distribution_version >= '7' %}
postrotate
{{ slurm_dir }}/sbin/slurmdbd flushlogs 1>/dev/null || true
{% else %}
postrotate /etc/init.d/slurmdbd reconfig
{% endif %}
endscript
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment