コード例 #1
0
def run_module():
    # define available arguments/parameters a user can pass to the module
    argument_spec = vmanage_argument_spec()
    argument_spec.update(factory_default=dict(type='bool', default=False),
                         )

    # seed the result dict in the object
    # we primarily care about changed and state
    # change is if this module effectively modified the target
    # state will include any data that you want your module to pass back
    # for consumption, for example, in a subsequent task
    result = dict(
        changed=False,
        original_message='',
        message=''
    )

    # the AnsibleModule object will be our abstraction working with Ansible
    # this includes instantiation, a couple of common attr would be the
    # args/params passed to the execution, as well as if the module
    # supports check mode
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True,
                           )
    vmanage = Vmanage(module)
    device_templates = DeviceTemplates(vmanage.auth, vmanage.host)

    vmanage.result['device_templates'] = device_templates.get_device_template_list(factory_default=vmanage.params['factory_default'])

    vmanage.exit_json(**vmanage.result)
コード例 #2
0
ファイル: files.py プロジェクト: NigarumOvum/python-viptela
    def export_templates_to_file(self,
                                 export_file,
                                 name_list=None,
                                 template_type=None):

        device_templates = DeviceTemplates(self.session, self.host, self.port)
        feature_templates = FeatureTemplates(self.session, self.host,
                                             self.port)

        template_export = {}
        #pylint: disable=too-many-nested-blocks
        if template_type != 'feature':
            # Export the device templates and associated feature templates
            device_template_list = device_templates.get_device_template_list(
                name_list=name_list)
            template_export.update(
                {'vmanage_device_templates': device_template_list})
            feature_name_list = []
            if name_list:
                for device_template in device_template_list:
                    if 'generalTemplates' in device_template:
                        for general_template in device_template[
                                'generalTemplates']:
                            if 'templateName' in general_template:
                                feature_name_list.append(
                                    general_template['templateName'])
                            if 'subTemplates' in general_template:
                                for sub_template in general_template[
                                        'subTemplates']:
                                    if 'templateName' in sub_template:
                                        feature_name_list.append(
                                            sub_template['templateName'])
                name_list = list(set(feature_name_list))
        # Since device templates depend on feature templates, we always add them.
        feature_templates = FeatureTemplates(self.session, self.host,
                                             self.port)
        feature_template_list = feature_templates.get_feature_template_list(
            name_list=name_list)
        template_export.update(
            {'vmanage_feature_templates': feature_template_list})

        if export_file.endswith('.json'):
            with open(export_file, 'w') as outfile:
                json.dump(template_export, outfile, indent=4, sort_keys=False)
        elif export_file.endswith('.yaml') or export_file.endswith('.yml'):
            with open(export_file, 'w') as outfile:
                yaml.dump(template_export, outfile, indent=4, sort_keys=False)
        else:
            raise Exception("File format not supported")