Exemplo n.º 1
0
 def on_Deploy(self, message, define_operation=True, raise_exc=False):
     msg_body = dicts.encode(message.body, encoding='ascii')        
     
     try:
         if define_operation:
             op = operation(name='Deploy')
             op.phases = self._get_phase_definition(message)
             op.define()
         else:
             op = bus.initialization_op
         
         with op.phase(self._phase_deploy):
                         
             assert 'deploy_task_id' in msg_body, 'deploy task is undefined'
             assert 'source' in msg_body, 'source is undefined'
             assert 'type' in msg_body['source'], 'source type is undefined'
             assert 'remote_path' in msg_body and msg_body['remote_path'], 'remote path is undefined'
             assert 'body' in msg_body['pre_deploy_routines'] if 'pre_deploy_routines' in msg_body else True
             assert 'body' in msg_body['post_deploy_routines'] if 'post_deploy_routines' in msg_body else True
 
             self._log_hdlr.deploy_task_id = msg_body['deploy_task_id']
             self._logger.addHandler(self._log_hdlr)
 
             src_type = msg_body['source'].pop('type')
             src = Source.from_type(src_type, **msg_body['source'])
             
             if msg_body.get('pre_deploy_routines') and msg_body['pre_deploy_routines'].get('body'):
                 with op.step(self._step_execute_pre_deploy_script):
                     self._exec_script(name='PreDeploy', **msg_body['pre_deploy_routines'])
                     
             with op.step(self._step_update_from_scm):
                 src.update(msg_body['remote_path'])
                 
             if msg_body.get('post_deploy_routines') and msg_body['post_deploy_routines'].get('body'):
                 with op.step(self._step_execute_post_deploy_script):
                     self._exec_script(name='PostDeploy', **msg_body['post_deploy_routines'])
 
             self.send_message(
                 Messages.DEPLOY_RESULT, 
                 dict(
                     status='ok', 
                     deploy_task_id=msg_body['deploy_task_id']
                 )
             )
             
         if define_operation:
             op.ok()
         
     except (Exception, BaseException), e:
         self._logger.exception(e)
         self.send_message(
             Messages.DEPLOY_RESULT, 
             dict(
                 status='error', 
                 last_error=str(e), 
                 deploy_task_id=msg_body['deploy_task_id']
             )
         )
         if raise_exc:
             raise
Exemplo n.º 2
0
    def on_Deploy(self, message, define_operation=True):
        msg_body = dicts.encode(message.body, encoding='ascii')

        try:
            if define_operation:
                op = operation(name='Deploy')
                op.phases = self._get_phase_definition(message)
                op.define()
            else:
                op = bus.initialization_op

            with op.phase(self._phase_deploy):

                assert 'deploy_task_id' in msg_body, 'deploy task is undefined'
                assert 'source' in msg_body, 'source is undefined'
                assert 'type' in msg_body['source'], 'source type is undefined'
                assert 'remote_path' in msg_body and msg_body[
                    'remote_path'], 'remote path is undefined'
                assert 'body' in msg_body[
                    'pre_deploy_routines'] if 'pre_deploy_routines' in msg_body else True
                assert 'body' in msg_body[
                    'post_deploy_routines'] if 'post_deploy_routines' in msg_body else True

                self._log_hdlr.deploy_task_id = msg_body['deploy_task_id']
                self._logger.addHandler(self._log_hdlr)

                src_type = msg_body['source'].pop('type')
                src = Source.from_type(src_type, **msg_body['source'])

                if msg_body.get('pre_deploy_routines') and msg_body[
                        'pre_deploy_routines'].get('body'):
                    with op.step(self._step_execute_pre_deploy_script):
                        self._exec_script(name='PreDeploy',
                                          **msg_body['pre_deploy_routines'])

                with op.step(self._step_update_from_scm):
                    src.update(msg_body['remote_path'])

                if msg_body.get('post_deploy_routines') and msg_body[
                        'post_deploy_routines'].get('body'):
                    with op.step(self._step_execute_post_deploy_script):
                        self._exec_script(name='PostDeploy',
                                          **msg_body['post_deploy_routines'])

                self.send_message(
                    Messages.DEPLOY_RESULT,
                    dict(status='ok',
                         deploy_task_id=msg_body['deploy_task_id']))

            if define_operation:
                op.ok()

        except (Exception, BaseException), e:
            self._logger.exception(e)
            self.send_message(
                Messages.DEPLOY_RESULT,
                dict(status='error',
                     last_error=str(e),
                     deploy_task_id=msg_body['deploy_task_id']))
Exemplo n.º 3
0
    def on_Deploy(self, message, define_operation=True, raise_exc=False):
        msg_body = dicts.encode(message.body, encoding='ascii')

        def handler(op):
            try:
                assert 'deploy_task_id' in msg_body, 'deploy task is undefined'
                assert 'source' in msg_body, 'source is undefined'
                assert 'type' in msg_body['source'], 'source type is undefined'
                assert 'remote_path' in msg_body and msg_body[
                    'remote_path'], 'remote path is undefined'
                assert 'body' in msg_body[
                    'pre_deploy_routines'] if 'pre_deploy_routines' in msg_body else True
                assert 'body' in msg_body[
                    'post_deploy_routines'] if 'post_deploy_routines' in msg_body else True

                self._log_hdlr.deploy_task_id = msg_body['deploy_task_id']
                self._logger.addHandler(self._log_hdlr)

                src_type = msg_body['source'].pop('type')
                src = deploy.Source.from_type(src_type, **msg_body['source'])

                if msg_body.get('pre_deploy_routines') and msg_body[
                        'pre_deploy_routines'].get('body'):
                    op.logger.info('Execute pre deploy script')
                    self._exec_script(name='PreDeploy',
                                      **msg_body['pre_deploy_routines'])

                op.logger.info('Update from SCM')
                src.update(msg_body['remote_path'])

                if msg_body.get('post_deploy_routines') and msg_body[
                        'post_deploy_routines'].get('body'):
                    op.logger.info('Execute post deploy script')
                    self._exec_script(name='PostDeploy',
                                      **msg_body['post_deploy_routines'])

                self.send_message(
                    Messages.DEPLOY_RESULT,
                    dict(status='ok',
                         deploy_task_id=msg_body['deploy_task_id']))

            except (Exception, BaseException), e:
                if not raise_exc:
                    self._logger.exception(e)
                self.send_message(
                    Messages.DEPLOY_RESULT,
                    dict(status='error',
                         last_error=str(e),
                         deploy_task_id=msg_body['deploy_task_id']))
                if raise_exc:
                    raise

            finally:
Exemplo n.º 4
0
    def on_Deploy(self, message, define_operation=True, raise_exc=False):
        msg_body = dicts.encode(message.body, encoding='ascii')        
     
        def handler(op):
            try:            
                assert 'deploy_task_id' in msg_body, 'deploy task is undefined'
                assert 'source' in msg_body, 'source is undefined'
                assert 'type' in msg_body['source'], 'source type is undefined'
                assert 'remote_path' in msg_body and msg_body['remote_path'], 'remote path is undefined'
                assert 'body' in msg_body['pre_deploy_routines'] if 'pre_deploy_routines' in msg_body else True
                assert 'body' in msg_body['post_deploy_routines'] if 'post_deploy_routines' in msg_body else True
    
                self._log_hdlr.deploy_task_id = msg_body['deploy_task_id']
                self._logger.addHandler(self._log_hdlr)
    
                src_type = msg_body['source'].pop('type')
                src = Source.from_type(src_type, **msg_body['source'])
                
                if msg_body.get('pre_deploy_routines') and msg_body['pre_deploy_routines'].get('body'):
                    op.logger.info('Execute pre deploy script')
                    self._exec_script(name='PreDeploy', **msg_body['pre_deploy_routines'])
                        
                op.logger.info('Update from SCM')
                src.update(msg_body['remote_path'])
                    
                if msg_body.get('post_deploy_routines') and msg_body['post_deploy_routines'].get('body'):
                    op.logger.info('Execute post deploy script')
                    self._exec_script(name='PostDeploy', **msg_body['post_deploy_routines'])
    
                self.send_message(
                    Messages.DEPLOY_RESULT, 
                    dict(
                        status='ok', 
                        deploy_task_id=msg_body['deploy_task_id']
                    )
                )

            except (Exception, BaseException), e:
                if not raise_exc:
                    self._logger.exception(e)
                self.send_message(
                    Messages.DEPLOY_RESULT, 
                    dict(
                        status='error', 
                        last_error=str(e), 
                        deploy_task_id=msg_body['deploy_task_id']
                    )
                )
                if raise_exc:
                    raise
                
            finally:
Exemplo n.º 5
0
	def add_snapshot(self, instance, machineimage=None):
		if machineimage:
			machineimage = os.path.join(self.username, machineimage)
		try:
			f = self._request(os.path.join(self.api_url, 'snapshot/'), 
						data=json.dumps(dict(instance=instance, machineimage=machineimage)), 
						query_method='POST')
		except:
			err_msg='Not enough privelegies to add snapshot'
			exc_info = sys.exc_info()
			raise NimbulaError, err_msg if 'Unauthorized' in exc_info[1] else exc_info[1], exc_info[2]	

		return Snapshot(self, **dicts.encode(json.load(f), 'ascii'))
Exemplo n.º 6
0
	def get_snapshot(self, name=None, snap=None):
		assert name or snap
		name = name or snap.name
		uri = self._get_object_URI(name, 'snapshot')
		try:
			f = self._request(uri, query_method='GET')
		except:
			err_msg='Not enough privelegies to get snapshot'
			exc_info = sys.exc_info()
			raise NimbulaError, err_msg if 'Unauthorized' in exc_info[1] else exc_info[1], exc_info[2]
		data = dicts.encode(json.load(f), 'ascii')
		if snap:
			return snap.set_data(**data)
		return Snapshot(self, **data)
Exemplo n.º 7
0
 def get_snapshot(self, name=None, snap=None):
     assert name or snap
     name = name or snap.name
     uri = self._get_object_URI(name, 'snapshot')
     try:
         f = self._request(uri, query_method='GET')
     except:
         err_msg = 'Not enough privelegies to get snapshot'
         exc_info = sys.exc_info()
         raise NimbulaError, err_msg if 'Unauthorized' in exc_info[
             1] else exc_info[1], exc_info[2]
     data = dicts.encode(json.load(f), 'ascii')
     if snap:
         return snap.set_data(**data)
     return Snapshot(self, **data)
Exemplo n.º 8
0
    def add_snapshot(self, instance, machineimage=None):
        if machineimage:
            machineimage = os.path.join(self.username, machineimage)
        try:
            f = self._request(os.path.join(self.api_url, 'snapshot/'),
                              data=json.dumps(
                                  dict(instance=instance,
                                       machineimage=machineimage)),
                              query_method='POST')
        except:
            err_msg = 'Not enough privelegies to add snapshot'
            exc_info = sys.exc_info()
            raise NimbulaError, err_msg if 'Unauthorized' in exc_info[
                1] else exc_info[1], exc_info[2]

        return Snapshot(self, **dicts.encode(json.load(f), 'ascii'))