diff --git a/linodecli/plugins/README.md b/linodecli/plugins/README.md index 8d0ab4c34..c199c5daf 100644 --- a/linodecli/plugins/README.md +++ b/linodecli/plugins/README.md @@ -40,7 +40,7 @@ all information the plugin is given during invocation. This includes the follow of the acting user. This is preferrable to using `requests` or another library directly (see below). -### CLI Client +#### CLI Client The CLI Client provided as `context.client` can make authenticated API calls on behalf of the user using the provided `call_operation` method. This method is @@ -48,8 +48,17 @@ invoked with a command and an action, and executes the given CLI command as if it were entered into the command line, returning the resulting status code and JSON data. -## TODOs +## Development - - [ ] Test/handle unconfigured invokations - - [ ] Finish statuspage plugin - - [ ] Clean up documentation +To develop a plugin, simply create a python source file in this directory that +has a `call` function as described above. To test, simply build the CLI as +normal (via `make install`) or simply by running `./setup.py install` in the +root directory of the project (this installs the code without generating new +baked data, and will only work if you've installed the CLI via `make install` +at least once, however it's a lot faster). + +### Examples + +This directory contains two example plugins, `echo.py.example` and +`regionstats.py.example`. To run these, simply remove the `.example` at the end +of the file and build the CLI as described above. diff --git a/linodecli/plugins/echo.py b/linodecli/plugins/echo.py.example similarity index 100% rename from linodecli/plugins/echo.py rename to linodecli/plugins/echo.py.example diff --git a/linodecli/plugins/regionstats.py b/linodecli/plugins/regionstats.py.example similarity index 100% rename from linodecli/plugins/regionstats.py rename to linodecli/plugins/regionstats.py.example diff --git a/linodecli/plugins/statuspage.py b/linodecli/plugins/statuspage.py deleted file mode 100644 index 023fd2f20..000000000 --- a/linodecli/plugins/statuspage.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -The StatusPage plugin allows querying status.linode.com from the command line! -This plugin requires BeautifulSoup -""" -from requests import get -from sys import exit - -# if this isn't installed, don't blow up -try: - from bs4 import BeautifulSoup - HAS_SOUP=True -except ImportError: - HAS_SOUP=False - -def call(args, context): - """ - """ - if not HAS_SOUP: - print('The statuspage plugin requires BeautifulSoup. You must install ' - 'it with `pip install beautifulsoup` before this plugin can be used.') - exit(2) - - response = get('https://status.linode.com') - - if response.status_code != 200: - # the status page is down? - print('Could not fetch status.linode.com: {}'.format(response.status_code)) - exit(1) - - page = response.content - soup = BeautifulSoup(page, 'html.parser') - - overall_status = soup.find('span', class_='status').text.strip() - - itemized_status = soup.find_all('div', class_='component-inner-container') - status_items = [] - - for item in itemized_status: - # parse the relevant info out of the items - is_subitem = 'border-color' not in item.parent.attrs['class'] - status = item.attrs['data-component-status'] - name = item.find('span', class_='name').text.strip() - - status_items.append((name, is_subitem, status)) - - print(overall_status) - print() - - for name, is_subitem, status in status_items: - print('{}{}\t{}'.format('+ ' if is_subitem else '', name, status)) -