Git Product home page Git Product logo

pylo's Introduction

Pylo

Introduction

A framework and set of utilities to interact with Illumio's PCE (Policy Compute Engine)

Example

Remove TCP/3389 from all rules using fully object oriented framework

import illumio_pylo as pylo

pce_hostname = 'pce212-beauty-contest.illumio.microsegment.io'

pylo.log_set_debug()
org = pylo.Organization(1)

print("* Loading PCE objects from API: ", end='', flush=True)
org.load_from_saved_credentials(pce_hostname, prompt_for_api_key=True)
print("OK!")

print("* PCE statistics: ", end='', flush=True)
print(org.stats_to_str())

print()

for ruleset in org.RulesetStore.itemsByHRef.values():
    for rule in ruleset.rules_byHref.values():
        for service in rule.services.get_direct_services():
            if service.is_tcp() and service.to_port is None and service.port == 3389:
                print("Rule {} is concerned".format(rule.href))
                rule.services.remove_direct_service(service)
                rule.services.api_sync()

Creating an IPList using raw API calls and json payloads

import illumio_pylo as pylo

pce_hostname = 'pce212-beauty-contest.illumio.microsegment.io'

connector = pylo.APIConnector.create_from_credentials_in_file(pce_hostname, request_if_missing=True)

if connector is None:
    print("****ERROR**** No cached credentials found for PCE {}".format())
    exit(1)

print("PCE Software version is {}".format(connector.get_software_version_string()))

print("* Now downloading Workload JSON...", end='', flush=True)
all_workloads_json = connector.objects_workload_get(max_results=999999, async_mode=False)
print("OK")

print()

print("* Now listing workloads names from JSON data:", end='', flush=True)
for workload_json in all_workloads_json:
    print(" - {} / href:{}".format(workload_json['name'], workload_json['href']))

print()

print("* attempting to create an IP¨List", end='', flush=True)
data = {'name': 'an IPList 2', "ip_ranges": [
    {"from_ip": "192.168.0.0/24"},
    {"from_ip": "172.16.0.0/24"},
]}
result = connector.objects_iplist_create(data)

if 'href' not in result:
    print("****ERROR**** Object was not created, PCE response was: ".format(result))
    exit(1)

print("OK! created with HREF={}".format(result['href']))

print()

pylo's People

Contributors

cpainchaud avatar dsommerville-illumio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pylo's Issues

license field object reference invalid

pylo/setup.py

Line 21 in b5174a6

license=license,

changed to 'license' temporarily to bypass setup issue:

Obtaining file://C:\Users\ron.gonzalez\PycharmProjects\pylo
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'

  error: subprocess-exited-with-error
  
  python setup.py egg_info did not run successfully.
  exit code: 1
  
  [35 lines of output]
  running egg_info
  creating C:\Users\ron.gonzalez\AppData\Local\Temp\pip-pip-egg-info-chwdya0o\pylo.egg-info
  writing C:\Users\ron.gonzalez\AppData\Local\Temp\pip-pip-egg-info-chwdya0o\pylo.egg-info\PKG-INFO
  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "C:\Users\ron.gonzalez\PycharmProjects\pylo\setup.py", line 13, in <module>
      setup(
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\__init__.py", line 87, in setup
      return distutils.core.setup(**attrs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
      return run_commands(dist)
             ^^^^^^^^^^^^^^^^^^
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
      dist.run_commands()
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\_distutils\dist.py", line 968, in run_commands
      self.run_command(cmd)
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\dist.py", line 1217, in run_command
      super().run_command(command)
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\_distutils\dist.py", line 987, in run_command
      cmd_obj.run()
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\command\egg_info.py", line 301, in run
      writer(self, ep.name, os.path.join(self.egg_info, ep.name))
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\command\egg_info.py", line 675, in write_pkg_info
      metadata.write_pkg_info(cmd.egg_info)
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\_distutils\dist.py", line 1136, in write_pkg_info
      self.write_pkg_file(pkg_info)
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\dist.py", line 197, in write_pkg_file
      write_field('License', rfc822_escape(license))
                             ^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\ron.gonzalez\PycharmProjects\pce_data_populator\311venv\Lib\site-packages\setuptools\_distutils\util.py", line 511, in rfc822_escape
      lines = header.split('\n')
              ^^^^^^^^^^^^
  AttributeError: '_Printer' object has no attribute 'split'
  [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

Encountered error while generating package metadata.

See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Support request for new policy items

Currently virtual_server and virtual_service are not recognized when loading rulesets from json. Class RuleHostContainer.load_from_json()

Stubbing them out like so avoids the 'Unsupported reference type' exception

        elif 'virtual_server' in host_data:
            print('Virtual server entry in policy')
            href = host_data['virtual_server'].get('href')
            if href is None:
                raise Exception('Cannot find object HREF ')
        elif 'virtual_service' in host_data:
            print('Virtual service entry in policy')
            href = host_data['virtual_service'].get('href')
            if href is None:
                raise Exception('Cannot find object HREF ')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.