def resolve_gw(gateways):
    """
    Resolve gateways to references. If these gateways do not exist,
    then an exception is raised. This is done before any operations
    are performed to prevent partial / incomplete changes before
    failure.
    
    :param list gateways: list of central or satellite gateways by
        name provided from the playbook.
    :return list of elements
    :raises PolicyCommandFailed: failure during deletion
    """
    if gateways:
        gw_as_element = []
        try:
            for gateway in gateways:
                typeof = gateway.get('type')
                if typeof == 'internal_gateway':
                    element = Engine.get(gateway.get('name'))
                    gw_as_element.append(element.internal_gateway)
                else: #type external
                    element = ExternalGateway.get(gateway.get('name'))
                    gw_as_element.append(element)
        except SMCException:
            raise SMCException('Gateway %s specified does not exist. No changes '
                'will be made' % gateway.get('name'))
        return gw_as_element
Beispiel #2
0
 def exec_module(self, **kwargs):
     for name, value in kwargs.items():
         setattr(self, name, value)
     
     # Verify the engine specified
     if self.engine:
         try:
             fw = Engine.get(self.engine)
         except ElementNotFound:
             self.fail(
                 msg='Specified engine was not found: {}. Called from: {}'
                 .format(self.engine, self.__class__.__name__))
     
     if self.engine and not self.filter:
         result = list(fw.alias_resolving())
         aliases = [{'name': alias.name, 'type': alias.typeof, 'resolved_value': alias.resolved_value}
                    for alias in result]
 
     else:
                 
         result = self.search_by_type(Alias)
         
         if self.filter:
             aliases = [alias_dict_from_obj(alias, self.engine) for alias in result]
         else:
             aliases = [{'name': alias.name, 'type': alias.typeof} for alias in result]
     
     self.results['ansible_facts'] = {'aliases': aliases}
     return self.results
Beispiel #3
0
 def get_managed_gateway(self, gw):
     """
     If the gateway is a locally managed SMC gateway, tunnel interface and
     an IPSEC interface is required.
     
     :param dict local_gw,remote_gw: yaml definition
     :rtype: Engine
     """
     for req in ('name', 'tunnel_interface', 'interface_id'):
         if req not in gw:
             self.fail(msg='Managed gateway requires name, interface_id and '
                 'tunnel_interface fields')
     
     managed_gw = Engine.get(gw.get('name'), raise_exc=False)
     if not managed_gw:
         self.fail(msg='The specified managed gateway specified does not '
             'exist: %s' % gw.get('name'))
     return managed_gw
    def exec_module(self, **kwargs):
        for name, value in kwargs.items():
            setattr(self, name, value)

        failed = False

        try:
            engine = Engine.get(self.name)
            msg = ''
            # If policy is defined, run an upload on the policy
            # TODO: Address situation where policy is queued for
            # uninitialized engine and attempted twice. This will
            # succeed but SMC 6.3 will return ''
            if self.policy:
                if self.wait_for_finish:
                    task = engine.upload(self.policy,
                                         timeout=self.sleep,
                                         wait_for_finish=True,
                                         max_tries=self.max_tries)

                    while not task.done():
                        task.wait(self.sleep)

                    msg = task.last_message()

                else:
                    task = engine.upload(self.policy)

                    if task.task.in_progress:
                        msg = 'Task upload currently in progress. Check the engine ' \
                            'facts to determine if any pending changes remain.'
                    else:
                        msg ='Task did not report positive status when starting. ' \
                            'Returned status was %s' % task.last_message()
                        failed = True

            else:  # A refresh of already installed policy
                if engine.installed_policy:
                    if self.wait_for_finish:
                        task = engine.refresh(timeout=self.sleep,
                                              wait_for_finish=True,
                                              max_tries=self.max_tries)

                        while not task.done():
                            task.wait(self.sleep)

                        msg = task.last_message()
                    else:
                        if engine.installed_policy:
                            task = engine.refresh()

                            if task.task.in_progress:
                                msg = 'Task refresh currently in progress. Check the engine ' \
                                    'facts to determine if any pending changes remain.'
                            else:
                                msg ='Task did not report positive status when starting. ' \
                                    'Returned status was %s' % task.last_message()
                                failed = True
                else:
                    msg = 'Engine does not currently have a policy assigned, you must ' \
                        'specify a policy to upload before refreshing policy.'
                    failed = True

            self.results['msg'] = msg

        except SMCException as err:
            self.fail(msg=str(err), exception=traceback.format_exc())

        self.results['failed'] = failed
        return self.results