Skip to content

Commit

Permalink
Service now working
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickB committed Mar 6, 2015
1 parent b477229 commit ebf94d6
Show file tree
Hide file tree
Showing 26 changed files with 349 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def deploy_build(self):
's/gitlabhq_production/' + self.fullname_ + '/g',
database_file])
self.execute(ssh, ['sed', '-i', 's/#\ username:\ git/username:\ ' +
self.service_id.db_user() + '/g',
self.service_id.db_user + '/g',
database_file])
self.execute(ssh, ['sed', '-i', 's/#\ password:/password:\ ' +
self.service_id.database_password + '/g',
Expand Down
22 changes: 12 additions & 10 deletions clouder/clouder_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class ClouderApplicationType(models.Model):
@api.constrains('name', 'system_user')
def _validate_data(self):
if not re.match("^[\w\d_]*$", self.name) \
or not re.match("^[\w\d_]*$", self.system_user):
or not re.match("^[\w\d-]*$", self.system_user):
raise except_orm(_('Data error!'), _(
"Name and system_user can only contains letters, "
"digits and underscore")
"digits and -")
)

# @api.multi
Expand Down Expand Up @@ -127,6 +127,8 @@ class ClouderApplication(models.Model):
'application_id', 'Options')
link_ids = fields.One2many('clouder.application.link', 'application_id',
'Links')
link_target_ids = fields.One2many('clouder.application.link', 'name',
'Links Targets')
version_ids = fields.One2many('clouder.application.version',
'application_id', 'Versions')
buildfile = fields.Text('Build File')
Expand Down Expand Up @@ -161,17 +163,17 @@ class ClouderApplication(models.Model):

@property
def full_archivepath(self):
return self.archive_path + '/' \
+ self.type_id.name + '-' + self.code
return self.env['clouder.model'].archive_path + '/' \
+ self.type_id.name + '-' + self.code

@property
def full_hostpath(self):
return self.services_hostpath() + '/' \
+ self.type_id.name + '-' + self.code
return self.env['clouder.model'].services_hostpath + '/' \
+ self.type_id.name + '-' + self.code

@property
def full_localpath(self):
return self.type_id.localpath and self.type_id.localpath() + '/' \
return self.type_id.localpath and self.type_id.localpath + '/' \
+ self.type_id.name + '-' + self.code or ''

@property
Expand Down Expand Up @@ -294,7 +296,7 @@ def build(self):
self.write({'current_version': current_version})
current_version = current_version or self.current_version
now = datetime.now()
version = current_version + '.' + now.strftime('%Y%m%d.%H%M')
version = current_version + '.' + now.strftime('%Y%m%d.%H%M%S')
self.env['clouder.application.version'].create(
{'application_id': self.id, 'name': version,
'archive_id': self.archive_id and self.archive_id.id})
Expand Down Expand Up @@ -414,7 +416,7 @@ def deploy(self):
self.build_application()
self.execute(ssh, ['echo "' + self.name + '" >> '
+ self.full_archivepath + '/VERSION.txt'])
self.execute(ssh, ['tar', 'czf', self.full_archivepath_targz(), '-C',
self.execute(ssh, ['tar', 'czf', self.full_archivepath_targz, '-C',
self.application_id.full_archivepath + '/'
+ self.name, '.'])
ssh.close()
Expand All @@ -423,7 +425,7 @@ def deploy(self):
def purge(self):
ssh = self.connect(self.archive_id.fullname)
self.execute(ssh, ['rm', '-rf', self.full_archivepath])
self.execute(ssh, ['rm', self.full_archivepath_targz()])
self.execute(ssh, ['rm', self.full_archivepath_targz])
ssh.close()


Expand Down
34 changes: 17 additions & 17 deletions clouder/clouder_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,27 +643,27 @@ def deploy(self):
res = self.deploy_create_database()
if not res:
for key, database in self.databases().iteritems():
if self.service_id.database_type() != 'mysql':
if self.service_id.database_type != 'mysql':
ssh = self.connect(
self.service_id.container_id.fullname,
username=self.application_id.type_id.system_user)
self.execute(ssh, ['createdb', '-h',
self.service_id.database_server(), '-U',
self.db_user(), database])
self.service_id.database_server, '-U',
self.db_user, database])
ssh.close()
else:
ssh = self.connect(
self.service_id.database().fullname)
self.service_id.database.fullname)
self.execute(ssh, [
"mysql -u root -p'"
+ self.service_id.database().root_password
+ self.service_id.database.root_password
+ "' -se \"create database " + database + ";\""
])
self.execute(ssh, [
"mysql -u root -p'"
+ self.service_id.database().root_password
+ self.service_id.database.root_password
+ "' -se \"grant all on " + database
+ ".* to '" + self.service_id.db_user() + "';\""
+ ".* to '" + self.service_id.db_user + "';\""
])
ssh.close()

Expand All @@ -672,26 +672,26 @@ def deploy(self):
self.deploy_build()

elif self.build == 'restore':
if self.service_id.database_type() != 'mysql':
if self.service_id.database_type != 'mysql':
ssh = self.connect(
self.service_id.container_id.fullname,
username=self.application_id.type_id.system_user)
self.execute(ssh, [
'pg_restore', '-h', self.service_id.database_server(),
'-U', self.service_id.db_user(), '--no-owner',
'pg_restore', '-h', self.service_id.database_server,
'-U', self.service_id.db_user, '--no-owner',
'-Fc', '-d', self.fullname_,
self.service_id.application_version_id.full_localpath
+ '/' + self.service_id.database_type() + '/build.sql'
+ '/' + self.service_id.database_type + '/build.sql'
])
ssh.close()
else:
ssh = self.connect(
self.service_id.container_id.fullname,
username=self.application_id.type_id.system_user)
self.execute(ssh, [
'mysql', '-h', self.service_id.database_server(),
'-u', self.service_id.db_user(),
'-p' + self.service_id.database().root_password,
'mysql', '-h', self.service_id.database_server,
'-u', self.service_id.db_user,
'-p' + self.service_id.database.root_password,
self.fullname_, '<',
self.service_id.application_version_id.full_localpath
+ '/' + self.service_id.database_type + '/build.sql'
Expand Down Expand Up @@ -721,7 +721,7 @@ def purge_post(self):
def purge_db(self):
for key, database in self.databases().iteritems():
if self.service_id.database_type != 'mysql':
ssh = self.connect(self.service_id.database().fullname,
ssh = self.connect(self.service_id.database.fullname,
username='postgres')
self.execute(ssh, [
'psql', '-c',
Expand All @@ -734,10 +734,10 @@ def purge_db(self):
self.execute(ssh, ['dropdb', database])
ssh.close()
else:
ssh = self.connect(self.service_id.database().fullname)
ssh = self.connect(self.service_id.database.fullname)
self.execute(ssh, [
"mysql -u root -p'"
+ self.service_id.database().root_password
+ self.service_id.database.root_password
+ "' -se \"drop database " + database + ";\""
])
ssh.close()
Expand Down
5 changes: 3 additions & 2 deletions clouder/clouder_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def onchange_application_id(self):

links = []
for app_link in self.application_id.link_ids:
if app_link.container and app_link.auto:
if app_link.container and app_link.auto or app_link.make_link:
test = False
for link in self.link_ids:
if link.name == app_link:
Expand Down Expand Up @@ -692,7 +692,8 @@ def deploy(self):
cmd.extend(['-v', arg])
for link in self.link_ids:
if link.name.make_link and link.target.server_id== self.server_id:
cmd.extend(['--link', link.target.name + ':' + link.name.code])
cmd.extend(['--link', link.target.name +
':' + link.name.name.code])
if self.privileged:
cmd.extend(['--privileged'])
cmd.extend(['-v', '/opt/keys/' + self.fullname +
Expand Down
5 changes: 4 additions & 1 deletion clouder/clouder_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,17 @@ def execute_local(self, cmd, path=False, shell=False):
return out

@api.multi
def exist(self, sftp, path):
def exist(self, ssh, path):
sftp = ssh.open_sftp()
try:
sftp.stat(path)
except IOError, e:
if e.errno == errno.ENOENT:
sftp.close()
return False
raise
else:
sftp.close()
return True

@api.multi
Expand Down
32 changes: 16 additions & 16 deletions clouder/clouder_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,34 +594,34 @@ def restore(self):
base.service_id.container_id.fullname,
username=base.application_id.type_id.system_user)
for key, database in base.databases().iteritems():
if base.service_id.database_type() != 'mysql':
if base.service_id.database_type != 'mysql':
self.execute(ssh, ['createdb', '-h',
base.service_id.database_server(), '-U',
base.service_id.db_user(),
base.service_id.database_server, '-U',
base.service_id.db_user,
base.fullname_])
self.execute(ssh, ['cat',
'/base-backup/' + self.repo_id.name
+ '/' + self.base_dumpfile,
'|', 'psql', '-q', '-h',
base.service_id.database_server(), '-U',
base.service_id.db_user(),
base.service_id.database_server, '-U',
base.service_id.db_user,
base.fullname_])
else:
ssh_mysql, sftp_mysql = self.connect(
base.service_id.database().fullname)
base.service_id.database.fullname)
self.execute(ssh_mysql, [
"mysql -u root -p'" +
base.service_id.database().root_password +
base.service_id.database.root_password +
"' -se \"create database " + database + ";\""])
self.execute(ssh_mysql, [
"mysql -u root -p'" +
base.service_id.database().root_password +
base.service_id.database.root_password +
"' -se \"grant all on " + database + ".* to '" +
base.service_id.db_user() + "';\""])
base.service_id.db_user + "';\""])
ssh_mysql.close(), sftp_mysql.close()
self.execute(ssh, [
'mysql', '-h', base.service_id.database_server(), '-u',
base.service_id.db_user(),
'mysql', '-h', base.service_id.database_server, '-u',
base.service_id.db_user,
'-p' + base.service_id.database_password, database,
'<', '/base-backup/' + self.repo_id.name + '/' +
database + '.dump'])
Expand Down Expand Up @@ -731,18 +731,18 @@ def deploy(self):
self.execute(ssh,
['mkdir', '-p', '/base-backup/' + self.repo_id.name])
for key, database in base.databases().iteritems():
if base.service_id.database_type() != 'mysql':
if base.service_id.database_type != 'mysql':
self.execute(ssh, [
'pg_dump', '-O', ''
'-h', base.service_id.database_server(),
'-U', base.service_id.db_user(), database,
'-h', base.service_id.database_server,
'-U', base.service_id.db_user, database,
'>', '/base-backup/' + self.repo_id.name + '/' +
database + '.dump'])
else:
self.execute(ssh, [
'mysqldump',
'-h', base.service_id.database_server(),
'-u', base.service_id.db_user(),
'-h', base.service_id.database_server,
'-u', base.service_id.db_user,
'-p' + base.service_id.database_password(),
database, '>', '/base-backup/' + self.repo_id.name +
'/' + database + '.dump'])
Expand Down
Loading

0 comments on commit ebf94d6

Please sign in to comment.