Factor code.

parent 5c14a39e
...@@ -505,7 +505,7 @@ def prepare_from_scratch(config): ...@@ -505,7 +505,7 @@ def prepare_from_scratch(config):
computer_id = get_computer_name( computer_id = get_computer_name(
os.path.join('/', slapos_configuration, 'slapos.cfg')) os.path.join('/', slapos_configuration, 'slapos.cfg'))
print "$Your Computer is : %s" % computer_id print "Your Computer is : %s" % computer_id
config.slaposConfig(mount_dir_path = '/', config.slaposConfig(mount_dir_path = '/',
slapos_configuration=slapos_configuration, slapos_configuration=slapos_configuration,
...@@ -555,51 +555,45 @@ def prepare_from_scratch(config): ...@@ -555,51 +555,45 @@ def prepare_from_scratch(config):
def chownSlaposDirectory(): def chownSlaposDirectory():
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
# search slapos.cfg # Search slapos.cfg
slapos_path_configuration_old = "/etc/slapos/slapos.cfg" slapos_configuration_file_path = "/etc/opt/slapos/slapos.cfg"
slapos_path_configuration = "/etc/opt/slapos/slapos.cfg" slapos_configuration_file_path_old = "/etc/slapos/slapos.cfg"
# check path slapos.cfg
if os.path.isfile(slapos_path_configuration_old) == True: if not os.path.isfile(slapos_configuration_file_path):
path_slapos = "/etc/slapos/" if os.path.isfile(slapos_configuration_file_path_old):
slapos_configuration_file_path = slapos_configuration_file_path_old
if os.path.isfile(slapos_path_configuration) == True: else:
path_slapos = "/etc/opt/slapos/" # No configuration found : returning
return
# deplacement the real folder
os.chdir(path_slapos) # Reading slapos paths from configuration file
# read slapos.cfg config.read(slapos_configuration_file_path)
config.read('slapos.cfg')
slapos_slapgrid_instance = config.get('slapos', 'instance_root') slapos_slapgrid_instance = config.get('slapos', 'instance_root')
slapos_slapgrid_software = config.get('slapos', 'software_root') slapos_slapgrid_software = config.get('slapos', 'software_root')
slapformat_partition = config.get('slapformat', 'partition_amount') slapformat_partition = config.get('slapformat', 'partition_amount')
slapformat_partition_base_name = config.get('slapformat', 'partition_base_name') slapformat_partition_base_name = config.get('slapformat', 'partition_base_name')
slapformat_user_base_name = config.get('slapformat', 'user_base_name') slapformat_user_base_name = config.get('slapformat', 'user_base_name')
path = slapos_slapgrid_instance print "Changing owners of software directory and partitions directories..."
# chown of partitions (/srv/slapgrid/slappart*)
print "Changing owners of software directory and partitions directories…"
for i in range(int(slapformat_partition)): for i in range(int(slapformat_partition)):
uid = getpwnam('%s%s' % (slapformat_user_base_name, i) )[2] uid = getpwnam('%s%s' % (slapformat_user_base_name, i) )[2]
gid = getpwnam('%s%s' % (slapformat_user_base_name, i) )[3] gid = getpwnam('%s%s' % (slapformat_user_base_name, i) )[3]
item = '%s%s' % (slapformat_partition_base_name, i) item = '%s%s' % (slapformat_partition_base_name, i)
itempath = os.path.join(path, item) itempath = os.path.join(slapos_slapgrid_instance, item)
os.chown(itempath, uid, gid) os.chown(itempath, uid, gid)
slapos_slapgrid_instance = "%s/%s%s" % ( slapos_slapgrid_instance, slapformat_partition_base_name, i)
for root, dirs, files in os.walk(slapos_slapgrid_instance):
for i in range(int(slapformat_partition)): for items in dirs, files:
path = "%s/%s%s" % ( slapos_slapgrid_instance, slapformat_partition_base_name, i) for item in items:
for root, dirs, files in os.walk(path): if not os.path.islink(item):
os.chown(os.path.join(root, item), getpwnam('%s%s' % (slapformat_user_base_name, i) )[2], getpwnam('%s%s' % (slapformat_user_base_name, i) )[3])
# chown of software root (/opt/slapgrid)
for root, dirs, files in os.walk(slapos_slapgrid_software):
for items in dirs, files: for items in dirs, files:
for item in items: for item in items:
if not os.path.islink(item): os.chown(os.path.join(root, item), getpwnam('slapsoft')[2], getpwnam('slapsoft')[3])
os.chown(os.path.join(root, item), getpwnam('%s%s' % (slapformat_user_base_name, i) )[2], getpwnam('%s%s' % (slapformat_user_base_name, i) )[3])
path = slapos_slapgrid_software
for root, dirs, files in os.walk(path):
for items in dirs, files:
for item in items:
os.chown(os.path.join(root, item), getpwnam('slapsoft')[2], getpwnam('slapsoft')[3])
def slapprepare(): def slapprepare():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment