def cli(target_ip, target_port, target_username, target_password, include_svc_setup, infra_subnet, infra_bgp_as,
        portal_hostname, deployment_region, deployment_locations_americas, deployment_locations_europe,
        deployment_locations_apac, ip_pool_cidr, user1_password, user2_password, conf_filename):
    """
    Import a full configuration. Defaults values in parenthesis.
    """

    # creating the jinja context from the skillet vars
    print('Reading in skillet variables')
    context = dict()
    context['include_svc_setup'] = include_svc_setup
    context['infra_subnet'] = infra_subnet
    context['infra_bgp_as'] = infra_bgp_as
    context['portal_hostname'] = portal_hostname
    context['deployment_region'] = deployment_region
    context['deployment_locations_americas'] = deployment_locations_americas.split(',')
    context['deployment_locations_europe'] = deployment_locations_europe.split(',')
    context['deployment_locations_apac'] = deployment_locations_apac.split(',')
    context['ip_pool_cidr'] = ip_pool_cidr
    context['user1_password'] = user1_password
    context['user2_password'] = user2_password
    context['conf_filename'] = conf_filename


    try:
        # render the template config file and create file_contents to use with import_file
        print('Creating the configuration file')
        sl = SkilletLoader()
        skillet = sl.load_skillet_from_path('../mobile_full_config')
        output = skillet.execute(context)
        file_contents = output.get('template', '')

        # create device object and use panoply import_file to send a config file to the device
        print('Import the config file to Panorama')
        device = Panos(api_username=target_username,
                       api_password=target_password,
                       hostname=target_ip,
                       api_port=target_port
                       )

        if not device.import_file(conf_filename, file_contents, 'configuration'):
            exit(1)

        exit(0)

    except LoginException as lxe:
        print(lxe)
        exit(1)
    except SkilletLoaderException as pe:
        print(pe)
        exit(1)

    # failsafe
    exit(1)

    print('File import complete')
示例#2
0
def load_and_execute_skillet(skillet_path: str) -> dict:
    skillet_loader = SkilletLoader()
    skillet = skillet_loader.load_skillet_from_path(skillet_path)

    print('=' * 80)
    print(f'Executing {skillet.label}\n'.center(80))

    output: dict = skillet.execute(context)

    return output
示例#3
0
def load_and_dump_skillet(skillet_path: str) -> str:
    skillet_loader = SkilletLoader()
    skillet = skillet_loader.load_skillet_from_path(skillet_path)

    print('=' * 80)
    print(f'Checking {skillet.label}\n'.center(80))

    output: str = skillet.dump_yaml()

    return output
示例#4
0
def cli(skillet_path, target_ip, target_port, target_username, target_password, env_file):
    """
    Load the Skillet from the command line.  Defaults values in parenthesis.
    """

    try:
        sl = SkilletLoader()
        skillet = sl.load_skillet_from_path(skillet_path)

        if env_file is not None:
            try:
                with open(env_file, 'r') as ef:
                    context = yaml.safe_load(ef.read())
            except yaml.YAMLError:
                context = os.environ.copy()
        else:
            context = skillet.update_context(os.environ.copy())

        if skillet.type == 'panos':
            device = Panos(api_username=target_username,
                           api_password=target_password,
                           hostname=target_ip,
                           api_port=target_port
                           )

            skillet.panoply = device
            output = skillet.execute(context)
            # FIXME - context should always include a key indicating success / failure of the given skillet
            # we may need situations where a failure doesn't necessarily raise an exception and we should handle
            # this here. Possibly for things likes like - skillet already applied, no action taken, or some
            # check failed...
            if output.get('result', 'failure') == 'success':
                msg = device.commit()
                # msg = 'no commit for testing, commit commented out for now'
                print(f'Successfully executed Skillet {skillet.name} for host: {target_ip}')
                print(f'commit message was: {msg}')
                print(f'output was: {context}')
                exit(0)
            else:
                exit(1)

    except LoginException as lxe:
        print(lxe)
        exit(1)
    except SkilletLoaderException as lde:
        print(lde)
        exit(1)

    # failsafe
    exit(1)
示例#5
0
def test_load_skillet_from_path():
    skillet_path = '../example_skillets/skillet_includes/include_other_skillets.skillet.yaml'
    skillet_loader = SkilletLoader()
    skillet = skillet_loader.load_skillet_from_path(skillet_path)

    # verify we can find and load the correct skillet
    assert skillet.name == 'include_other_skillets'

    # verify the correct number of snippets.
    assert len(skillet.snippets) == 9

    included_snippet: Snippet = skillet.get_snippet_by_name(
        'network_profiles.check_network_profiles')

    # verify we can get an included snippet from the skillet object
    assert included_snippet is not None
示例#6
0
def cli(skillet_path, target_ip, target_port, target_username,
        target_password):
    """
    Load the Skillet from the command line.  Defaults values in parenthesis.
    """

    try:
        sl = SkilletLoader()
        skillet = sl.load_skillet_from_path(skillet_path)
        context = skillet.update_context(os.environ.copy())

        if skillet.type == 'panos':
            device = Panoply(api_username=target_username,
                             api_password=target_password,
                             hostname=target_ip,
                             api_port=target_port)

            # set the device object on the skillet object
            skillet.panoply = device
            skillet.execute(context)
            print('Performing Commit')
            device.commit()
            print(
                f'Successfully pushed Skillet {skillet.name} to host: {target_ip}'
            )
            exit(0)

    except LoginException as lxe:
        print(lxe)
        exit(1)
    except SkilletLoaderException as lde:
        print(lde)
        exit(1)

    # failsafe
    exit(1)
示例#7
0
        if not found_order_label:
            setattr(skillet, 'order', order_index)

        order_index += 1

for collection in collections:
    collections[collection].sort(key=lambda x: x.order)

context = dict()
context['collections'] = collections
context['repo'] = repo
context['repo_branch'] = repo_branch
context['app_name'] = repo_name
context['description'] = description

skillet_path = os.path.join(this_path, 'skillets/build_config')
config_builder_skillet = sl.load_skillet_from_path(skillet_path)
t = config_builder_skillet.execute(context)

if 'template' not in t:
    print('Could not parse skillet data!')
    sys.exit(1)

with open(config_path, 'w') as config_file:
    config_file.write(t['template'])

print('Appetizer Configuration File built...')

print(t['template'])
示例#8
0
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# Authors: Nathan Embery

from skilletlib import SkilletLoader

# use skilletLoader from skilletlib to load and execute the skillet
sl = SkilletLoader()

# our skillet is located in the same directory
skillet = sl.load_skillet_from_path('.')

# each skillet can specify what items are customizable.
# Create a context dictionary to hold our customized variables for this execution.
context = dict()
context['username'] = '******'
context['password'] = '******'
context['ip_address'] = '10.10.10.10'

# This Ansible playbook may take a very long time. Use the 'execute_async' method to poll for the output as it happens
# As with the execute method, we pass in our context object
# The primary different is 'execute_async' returns a generator that we can iterate over to get the output as it happens
# from the docker container
for l in skillet.execute_async(context):
    print(l)