Skip to content

Commit

Permalink
Add control to ssh connections
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickB committed May 4, 2015
1 parent 96566df commit 2b5ec69
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 12 deletions.
11 changes: 8 additions & 3 deletions clouder/clouder_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,14 @@ class ClouderBaseLink(models.Model):
required=True)
target = fields.Many2one('clouder.container', 'Target')

target_base = lambda self: self.target.service_ids and \
self.target.service_ids[0].base_ids and \
self.target.service_ids[0].base_ids[0]
@property
def target_base(self):
"""
Property returning the first base of the target container.
"""
return self.target.service_ids and \
self.target.service_ids[0].base_ids and \
self.target.service_ids[0].base_ids[0]

@api.one
@api.constrains('base_id')
Expand Down
8 changes: 8 additions & 0 deletions clouder/clouder_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ def stop_containers(self):
for container in containers:
container.stop()

@api.multi
def test_connection(self):
"""
Test connection to the server.
"""
ssh = self.connect(self.name)
ssh.close()

@api.multi
def deploy(self):
"""
Expand Down
34 changes: 33 additions & 1 deletion clouder/clouder_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,40 @@ def connect(self, host, port=False, username=False):
if not port:
port = user_config['port']

ssh.connect(host, port=int(port), username=username,
if identityfile == None:
raise except_orm(
_('Data error!'),
_("It seems Clouder have no record in the ssh config to "
"connect to your server.\nMake sure there is a '" + host + ""
"' record in the ~/.ssh/config of the Clouder system user.\n"
"To easily add this record, depending if Clouder try to "
"connect to a server or a container, you can click on the "
"'reinstall' button of the server record or 'reset key' "
"button of the container record you try to access."))

if not isinstance(identityfile, basestring):
raise except_orm(
_('Data error!'),
_("For unknown reason, it seems the variable identityfile in "
"the connect ssh function is invalid. Please report "
"this message.\n"
"Identityfile : " + str(identityfile)
+ ", type : " + type(identityfile)))

try:
ssh.connect(host, port=int(port), username=username,
key_filename=os.path.expanduser(identityfile))
except Exception as inst:
raise except_orm(
_('Connect error!'),
_("We were not able to connect to your server. Please make "
"sure you add the public key in the authorized_keys file "
"of your root user on your server.\n"
"If you were trying to connect to a container, a click on "
"the 'reset key' button on the container record may resolve "
"the problem.\n"
"Error : " + str(inst)))

return ssh

@api.multi
Expand Down
1 change: 1 addition & 0 deletions clouder/clouder_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
<field name="partner_id"/>
</group>
<button name="reinstall" string="Reinstall" type="object"/>
<button name="test_connection" string="Test connection" type="object"/>
<button name="start_containers" string="Restart Containers" type="object"/>
<button name="stop_containers" string="Stop Containers" type="object"/>
<field name="log_ids" colspan="4"/>
Expand Down
4 changes: 2 additions & 2 deletions clouder_template_bind/clouder_template_bind_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y -q install bind9
mkdir -m 0775 -p /var/run/named
chown root:bind /var/run/named
#mkdir -m 0775 -p /var/run/named
#chown root:bind /var/run/named
#https://github.com/Supervisor/supervisor/issues/147
#RUN echo 'trap "{ /etc/init.d/bind9 stop; exit 0; }" EXIT' >> /opt/bind_init.sh
Expand Down
4 changes: 3 additions & 1 deletion clouder_template_odoo/clouder_template_odoo_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y -qq -t wheezy-backports install wk
RUN pip install psycogreen
RUN pip install erppeek
echo "deb http://ftp.us.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
#echo "deb http://ftp.us.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
RUN useradd -m -s /bin/bash odoo
USER odoo
Expand Down Expand Up @@ -153,6 +153,7 @@ VOLUME /base-backup
<field name="buildfile"><![CDATA[
git clone http://github.com/odoo/odoo.git parts/odoo -b 8.0
git clone http://github.com/YannickB/odoo-hosting.git extra/odoo-hosting -b master
git clone http://github.com/OCA/website.git extra/website -b 8.0
#[buildout]
#parts = odoo
Expand Down Expand Up @@ -239,6 +240,7 @@ git clone http://github.com/YannickB/odoo-hosting.git extra/odoo-hosting -b mast
git clone http://github.com/odoo/odoo.git parts/odoo -b 8.0
git clone http://github.com/YannickB/odoo-hosting.git extra/odoo-hosting -b master
git clone http://github.com/clouder-community/clouder.git extra/clouder -b 8.0
git clone http://github.com/OCA/website.git extra/website -b 8.0
#[buildout]
#parts = odoo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ git clone http://github.com/OCA/vertical-community.git extra/vertical-community
git clone http://github.com/OCA/account-financial-tools.git extra/account-financial-tools -b 8.0
git clone http://github.com/YannickB/community-web.git extra/community-web -b master
git clone http://github.com/YannickB/odoo-hosting.git extra/odoo-hosting -b master
git clone http://github.com/OCA/website.git extra/website -b 8.0
Expand Down
10 changes: 5 additions & 5 deletions clouder_template_seafile/clouder_template_seafile_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,37 @@ VOLUME /base-backup
</record>
<record id="app_seafile_link1" model="clouder.application.link">
<field name="application_id" ref="app_seafile"/>
<field name="name" ref="clouder_template_bind.app_bind"/>
<field name="name" ref="clouder_bind.app_bind"/>
<field name="required" eval="True"/>
<field name="auto" eval="True"/>
<field name="base" eval="True"/>
</record>
<record id="app_seafile_link2" model="clouder.application.link">
<field name="application_id" ref="app_seafile"/>
<field name="name" ref="clouder_template_shinken.app_shinken"/>
<field name="name" ref="clouder_shinken.app_shinken"/>
<field name="required" eval="True"/>
<field name="auto" eval="True"/>
<field name="container" eval="True"/>
<field name="base" eval="True"/>
</record>
<record id="app_seafile_link3" model="clouder.application.link">
<field name="application_id" ref="app_seafile"/>
<field name="name" ref="clouder_template_mysql.app_mysql"/>
<field name="name" ref="clouder_mysql.app_mysql"/>
<field name="required" eval="True"/>
<field name="auto" eval="True"/>
<field name="make_link" eval="True"/>
<field name="service" eval="True"/>
</record>
<record id="app_seafile_link4" model="clouder.application.link">
<field name="application_id" ref="app_seafile"/>
<field name="name" ref="clouder_template_postfix.app_postfix"/>
<field name="name" ref="clouder_postfix.app_postfix"/>
<field name="required" eval="True"/>
<field name="auto" eval="True"/>
<field name="make_link" eval="True"/>
</record>
<record id="app_seafile_link5" model="clouder.application.link">
<field name="application_id" ref="app_seafile"/>
<field name="name" ref="clouder_template_proxy.app_proxy"/>
<field name="name" ref="clouder_proxy.app_proxy"/>
<field name="required" eval="True"/>
<field name="auto" eval="True"/>
<field name="base" eval="True"/>
Expand Down

0 comments on commit 2b5ec69

Please sign in to comment.