Skip to content

Commit

Permalink
And finally base works, most of the debugging is now done
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickB committed Mar 7, 2015
1 parent ebf94d6 commit bca6778
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 199 deletions.
66 changes: 32 additions & 34 deletions clouder/clouder_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class ClouderBase(models.Model):
'clouder_base_service_rel', 'base_id',
'service_id', 'Alternative Services')
admin_name = fields.Char('Admin name', size=64, required=True)
admin_passwd = fields.Char(
admin_password = fields.Char(
'Admin password', size=64, required=True,
default=clouder_model.generate_random_password(20))
admin_email = fields.Char('Admin email', size=64, required=True)
poweruser_name = fields.Char('PowerUser name', size=64)
poweruser_passwd = fields.Char(
poweruser_password = fields.Char(
'PowerUser password', size=64,
default=clouder_model.generate_random_password(12))
poweruser_email = fields.Char('PowerUser email', size=64)
Expand Down Expand Up @@ -179,11 +179,11 @@ def options(self):
for option in \
self.service_id.container_id.application_id.type_id.option_ids:
if option.type == 'base':
options[option.name] = {'id': option.id, 'name': option.name,
options[option.name] = {'id': option.id, 'name': option.id,
'value': option.default}
for option in self.option_ids:
options[option.name.name] = {'id': option.id,
'name': option.name.name,
'name': option.name.id,
'value': option.value}
return options

Expand All @@ -195,9 +195,9 @@ def options(self):
@api.one
@api.constrains('name', 'admin_name', 'admin_email', 'poweruser_email')
def _validate_data(self):
if not re.match("^[\w\d_]*$", self.name):
if not re.match("^[\w\d-]*$", self.name):
raise except_orm(_('Data error!'), _(
"Name can only contains letters, digits and underscore"))
"Name can only contains letters, digits and -"))
if self.admin_name and not re.match("^[\w\d_]*$", self.admin_name):
raise except_orm(_('Data error!'), _(
"Admin name can only contains letters, digits and underscore"))
Expand All @@ -215,15 +215,18 @@ def _validate_data(self):
@api.one
@api.constrains('service_id', 'service_ids', 'application_id')
def _check_application(self):
if self.application_id.id != self.service_id.application_id.id:
if self.application_id.id != \
self.service_id.container_id.application_id.id:
raise except_orm(_('Data error!'),
_("The application of base must be the same "
"than the application of service."))
for s in self.service_ids:
if self.application_id.id != s.application_id.id:
raise except_orm(_('Data error!'),
_("The application of base must be the same "
"than the application of service."))
if self.application_id.id != s.container_idapplication_id.id:
raise except_orm(
_('Data error!'),
_("The application of base must be the "
"same than the application of service.")
)


@api.one
Expand Down Expand Up @@ -404,10 +407,10 @@ def onchange_application_id(self):
# 'base_title': self.title,
# 'base_domain': self.domain_id.name,
# 'base_admin_name': self.admin_name,
# 'base_admin_passwd': self.admin_passwd,
# 'base_admin_password': self.admin_password,
# 'base_admin_email': self.admin_email,
# 'base_poweruser_name': self.poweruser_name,
# 'base_poweruser_password': self.poweruser_passwd,
# 'base_poweruser_password': self.poweruser_password,
# 'base_poweruser_email': self.poweruser_email,
# 'base_build': self.build,
# 'base_sslonly': self.ssl_only,
Expand Down Expand Up @@ -503,8 +506,8 @@ def unlink(self):

@api.multi
def save(self):
save_obj = self.pool.get('clouder.save.save')
repo_obj = self.pool.get('clouder.save.repository')
save_obj = self.env['clouder.save.save']
repo_obj = self.env['clouder.save.repository']

save = False

Expand Down Expand Up @@ -548,7 +551,7 @@ def save(self):
save_vals = {
'name': self.now_bup + '_' + self.fullname,
'backup_id': backup_server.id,
'repo_id': self.save_repository_id,
'repo_id': self.save_repository_id.id,
'date_expiration': (now + timedelta(
days=self.save_expiration
or self.application_id.base_save_expiration)
Expand Down Expand Up @@ -594,12 +597,12 @@ def _reset_base(self, base_name=False, service_id=False):
if base_name:
vals = {'base_id': False, 'base_restore_to_name': base_name,
'base_restore_to_domain_id': self.domain_id.id,
'service_id': service_id, 'base_nosave': True}
'service_id': service_id.id, 'base_nosave': True}
save.write(vals)
base = save.restore()
base.write({'parent_id': base_parent_id})
base.with_context(base_parent_fullname_=base_parent_id.fullname_)
base.with_context(service_parent_name=base_parent_id.service_id.name)
base.write({'parent_id': base_parent_id.id})
base = base.with_context(base_parent_fullname_=base_parent_id.fullname_)
base = base.with_context(service_parent_name=base_parent_id.service_id.name)
base.update_base()
base.post_reset()
base.deploy_post()
Expand Down Expand Up @@ -642,7 +645,7 @@ def deploy(self):

res = self.deploy_create_database()
if not res:
for key, database in self.databases().iteritems():
for key, database in self.databases.iteritems():
if self.service_id.database_type != 'mysql':
ssh = self.connect(
self.service_id.container_id.fullname,
Expand Down Expand Up @@ -719,7 +722,7 @@ def purge_post(self):

@api.multi
def purge_db(self):
for key, database in self.databases().iteritems():
for key, database in self.databases.iteritems():
if self.service_id.database_type != 'mysql':
ssh = self.connect(self.service_id.database.fullname,
username='postgres')
Expand Down Expand Up @@ -842,28 +845,23 @@ def _check_required(self):
# self.deploy(cr, uid, vals, context=context)
# return

def deploy_link(self, cr, uid, vals, context={}):
@api.multi
def deploy_link(self):
return

def purge_link(self, cr, uid, vals, context={}):
@api.multi
def purge_link(self):
return

def control(self):
if not self.target:
self.log(
'The target isnt configured in the link, skipping deploy link')
return False
app_links = self.env['clouder.application.link'].search([
('application_id', '=', self.base_id.application_id.id),
('name.code', '=', self.target.application_id.code)])
if app_links:
self.log(
'The target isnt in the application link '
'for base, skipping deploy link')
return
if app_links[0].base:
if not self.name.base:
self.log('This application isnt for base, skipping deploy link')
return
return False
return True

@api.multi
def deploy_(self):
Expand Down
13 changes: 3 additions & 10 deletions clouder/clouder_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ def options(self):
options = {}
for option in self.application_id.type_id.option_ids:
if option.type == 'container':
options[option.name] = {'id': option.id, 'name': option.name, 'value': option.default}
options[option.name] = {'id': option.id, 'name': option.id, 'value': option.default}
for option in self.option_ids:
options[option.name.name] = {'id': option.id, 'name': option.name.name, 'value': option.value}
options[option.name.name] = {'id': option.id, 'name': option.name.id, 'value': option.value}
return options

_sql_constraints = [
Expand Down Expand Up @@ -959,14 +959,7 @@ def control(self):
self.log('The target isnt configured in the link, '
'skipping deploy link')
return False
app_links = self.env['clouder.application.link'].search(
[('application_id','=',self.container_id.application_id.id),
('name.code','=', self.target.application_id.code)])
if not app_links:
self.log('The target isnt in the application link for container, '
'skipping deploy link')
return False
if not app_links[0].container:
if not self.name.container:
self.log('This application isnt for container, '
'skipping deploy link')
return False
Expand Down
46 changes: 27 additions & 19 deletions clouder/clouder_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class ClouderSaveSave(models.Model):
base_title = fields.Char('Title', size=64)
base_container_name = fields.Char('Container', size=64)
base_container_server = fields.Char('Server', size=64)
base_admin_passwd = fields.Char('Admin passwd', size=64)
base_admin_name = fields.Char('Admin name', size=64)
base_admin_password = fields.Char('Admin passwd', size=64)
base_admin_email = fields.Char('Admin email', size=64)
base_poweruser_name = fields.Char('Poweruser name', size=64)
base_poweruser_password = fields.Char('Poweruser Password', size=64)
base_poweruser_email = fields.Char('Poweruser email', size=64)
Expand Down Expand Up @@ -249,7 +251,7 @@ def create(self, vals):

service_links = {}
for link in service.link_ids:
service_links[link.name.code] = {
service_links[link.name.name.code] = {
'name': link.name.id,
'code': link.name.name.code,
'target': link.target and link.target.id
Expand Down Expand Up @@ -278,7 +280,9 @@ def create(self, vals):
'base_container_name': base.service_id.container_id.name,
'base_container_server':
base.service_id.container_id.server_id.name,
'base_admin_passwd': base.admin_passwd,
'base_admin_name': base.admin_name,
'base_admin_password': base.admin_password,
'base_admin_email': base.admin_email,
'base_poweruser_name': base.poweruser_name,
'base_poweruser_password': base.poweruser_password,
'base_poweruser_email': base.poweruser_email,
Expand Down Expand Up @@ -392,9 +396,10 @@ def restore(self):
('name.code', '=', link_vals['code']),
('application_id', '=', apps[0])])
if link_apps:
link_vals['name'] = link_apps[0]
link_vals['name'] = link_apps[0].id
else:
continue
del link_vals['code']
links.append((0, 0, link_vals))
container_vals = {
'name': self.computed_container_restore_to_name,
Expand Down Expand Up @@ -458,8 +463,8 @@ def restore(self):
else:
# upgrade = False
app_versions = application_version_obj.search(
[('name', '=', self.base_app_version),
('application_id', '=', apps[0])])
[('name', '=', self.service_app_version),
('application_id', '=', apps[0].id)])
if not app_versions:
self.log(
"Warning, couldn't find the application version, "
Expand All @@ -476,7 +481,7 @@ def restore(self):
if not self.service_id or self.service_id.container_id != container:
services = service_obj.search(
[('name', '=', self.service_name),
('container_id.id', '=', container)])
('container_id', '=', container.id)])

if not services:
self.log("Can't find any corresponding service, "
Expand All @@ -497,7 +502,7 @@ def restore(self):
link_vals['name'] = link_apps[0]
else:
continue
del link_vals['name_name']
del link_vals['code']
links.append((0, 0, link_vals))
service_vals = {
'name': self.service_name,
Expand Down Expand Up @@ -550,34 +555,37 @@ def restore(self):
link_vals['name'] = link_apps[0]
else:
continue
del link_vals['name_name']
del link_vals['code']
links.append((0, 0, link_vals))
base_vals = {
'name': self.computed_base_restore_to_name,
'service_id': service,
'application_id': apps[0],
'domain_id': domains[0],
'service_id': service.id,
'application_id': apps[0].id,
'domain_id': domains[0].id,
'title': self.base_title,
'admin_passwd': self.base_admin_passwd,
'admin_name': self.base_admin_name,
'admin_password': self.base_admin_password,
'admin_email': self.base_admin_email,
'poweruser_name': self.base_poweruser_name,
'poweruser_passwd': self.base_poweruser_password,
'poweruser_password': self.base_poweruser_password,
'poweruser_email': self.base_poweruser_email,
'build': self.base_build,
'test': self.base_test,
'lang': self.base_lang,
'nosave': self.base_nosave,
'option_ids': options,
'link_ids': links,
'backup_ids': [(6,0,[self.backup_id.id])]
}
self = self.with_context(base_restoration=True)
base = base_obj.create(base_vals)
base = self.env['clouder.base'].create(base_vals)

else:
self.log("A corresponding base was found")
base = bases[0]
else:
self.log("A base_id was linked in the save")
base = self.base_id.id
base = self.base_id

if base.service_id.application_version_id != app_versions[0]:
# if upgrade:
Expand All @@ -593,7 +601,7 @@ def restore(self):
ssh = self.connect(
base.service_id.container_id.fullname,
username=base.application_id.type_id.system_user)
for key, database in base.databases().iteritems():
for key, database in base.databases.iteritems():
if base.service_id.database_type != 'mysql':
self.execute(ssh, ['createdb', '-h',
base.service_id.database_server, '-U',
Expand Down Expand Up @@ -730,7 +738,7 @@ def deploy(self):
username=base.application_id.type_id.system_user)
self.execute(ssh,
['mkdir', '-p', '/base-backup/' + self.repo_id.name])
for key, database in base.databases().iteritems():
for key, database in base.databases.iteritems():
if base.service_id.database_type != 'mysql':
self.execute(ssh, [
'pg_dump', '-O', ''
Expand All @@ -746,7 +754,7 @@ def deploy(self):
'-p' + base.service_id.database_password(),
database, '>', '/base-backup/' + self.repo_id.name +
'/' + database + '.dump'])
base.deploy_base()
self.deploy_base()
self.execute(ssh, ['chmod', '-R', '777',
'/base-backup/' + self.repo_id.name])
ssh.close()
Expand Down
Loading

0 comments on commit bca6778

Please sign in to comment.