From 478307221691b684fe23442be9a95f56e1208669 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 23 Mar 2015 13:45:26 +0100 Subject: Update examples for Cockpit 0.41 or later --- content/cockpit/cockpit-plugin-tutorial.md | 14 ++++++++------ content/cockpit/dbus-basics.md | 14 ++++++++------ content/cockpit/protocol-interaction.md | 9 ++++----- content/files/pinger.tgz | Bin 873 -> 863 bytes content/files/zoner.tgz | Bin 842 -> 842 bytes 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/content/cockpit/cockpit-plugin-tutorial.md b/content/cockpit/cockpit-plugin-tutorial.md index b189a07..5c10d80 100644 --- a/content/cockpit/cockpit-plugin-tutorial.md +++ b/content/cockpit/cockpit-plugin-tutorial.md @@ -4,13 +4,15 @@ Category: Cockpit, Linux Tags: cockpit, linux Slug: creating-plugins-for-the-cockpit-user-interface +*Note: This post has been updated for changes in Cockpit 0.41 and later.* + [Cockpit is a user interface for servers](http://cockpit-project.org). And you can add stuff to that user interface. Cockpit is internally built of various components. Each component is HTML, with Javascript logic that makes it work, and CSS to make it pretty. It's real easy to create these components. Tools are components that show up in the *Tools* menu in Cockpit: ![Tools menu](images/cockpit-tools-default.png) -For example the *Terminal* that you see there is implemented as a tool. But lets make ourselves another one. For this tutorial you'll need Cockpit 0.30. You can install it in [Fedora 21](https://lists.fedorahosted.org/pipermail/cockpit-devel/2014-November/000196.html) or [build it from git](https://github.com/cockpit-project/cockpit/blob/master/HACKING.md). +For example the *Terminal* that you see there is implemented as a tool. But lets make ourselves another one. For this tutorial you'll need Cockpit 0.41. You can install it in [Fedora 21](https://lists.fedorahosted.org/pipermail/cockpit-devel/2014-November/000196.html) or [build it from git](https://github.com/cockpit-project/cockpit/blob/master/HACKING.md). So break out your terminal, lets make a package called *pinger* that checks whether your server has network connectivity to the Internet by pinging another host. Nothing too fancy. We'll just be spawning a process on the server to do the work. I've prepared it for you as [an example here](http://stef.thewalter.net/files/pinger.tgz), and we can look it over, and modify it. To download the example to your current directory: @@ -68,9 +70,9 @@ Lets take a look at the pinger HTML, and see how it works. Pinger - - - + + +
@@ -123,8 +125,8 @@ Lets take a look at the pinger HTML, and see how it works. First we include `jquery.js` and `cockpit.js`. `cockpit.js` defines the basic API for interacting with the system, as well as Cockpit itself. You can find [detailed documentation here](http://files.cockpit-project.org/guide/latest/api-cockpit.html). :::html - - + + We also include the cockpit.css file to make sure the look of our tool matches that of Cockpit. The HTML is pretty basic, defining a little form with a field to type an address, a button to click to start the pinging, and an area to present output and results. diff --git a/content/cockpit/dbus-basics.md b/content/cockpit/dbus-basics.md index 6b67695..9aa7479 100644 --- a/content/cockpit/dbus-basics.md +++ b/content/cockpit/dbus-basics.md @@ -4,9 +4,11 @@ Category: Cockpit, Linux Tags: cockpit, linux Slug: using-dbus-from-javascript-in-cockpit +*Note: This post has been updated for changes in Cockpit 0.41 and later.* + [Cockpit is a user interface for servers](http://cockpit-project.org). As we covered in the [last tutorial](http://stef.thewalter.net/creating-plugins-for-the-cockpit-user-interface.html) you can add user interface component to Cockpit, and build your own parts of the Server UI. -Much of Cockpit interacts with the server using DBus. We have a powerful yet simple API for doing that, and you should use DBus too when building your own Cockpit user interfaces. For this tutorial you'll need at least Cockpit 0.31. A few tweaks landed in that release to solve a couple rough edges we had in our DBus support. You can install it in [Fedora 21](https://lists.fedorahosted.org/pipermail/cockpit-devel/2014-November/000196.html) or [build it from git](https://github.com/cockpit-project/cockpit/blob/master/HACKING.md). +Much of Cockpit interacts with the server using DBus. We have a powerful yet simple API for doing that, and you should use DBus too when building your own Cockpit user interfaces. For this tutorial you'll need at least Cockpit 0.41. A few tweaks landed in that release to solve a couple rough edges we had in our DBus support. You can install it in [Fedora 21](https://lists.fedorahosted.org/pipermail/cockpit-devel/2014-November/000196.html) or [build it from git](https://github.com/cockpit-project/cockpit/blob/master/HACKING.md). Here we'll make a package called *zoner* which lets you set the time zone of your server. We use the systemd [timedated DBus API](http://www.freedesktop.org/wiki/Software/systemd/timedated/) to do actually switch time zones. @@ -47,9 +49,9 @@ You should see your timezone on your screen update immediately to reflect the ne Time Zone - - - + + +
@@ -101,8 +103,8 @@ You should see your timezone on your screen update immediately to reflect the ne First we include `jquery.js` and `cockpit.js`. `cockpit.js` defines the basic API for interacting with the system, as well as Cockpit itself. You can find [detailed documentation here](http://files.cockpit-project.org/guide/latest/api-cockpit.html). :::html - - + + We also include the cockpit.css file to make sure the look of our tool matches that of Cockpit. The HTML is pretty basic, defining a little form where the current timezone is shown, a field to type an address, a button to click change to a new one, and an area to show errors. diff --git a/content/cockpit/protocol-interaction.md b/content/cockpit/protocol-interaction.md index 4a71350..2f2e457 100644 --- a/content/cockpit/protocol-interaction.md +++ b/content/cockpit/protocol-interaction.md @@ -4,6 +4,8 @@ Category: Cockpit, Linux Tags: cockpit, linux Slug: protocol-for-web-access-to-system-apis +*Note: This post has been updated for changes in Cockpit 0.44 and later.* + A Linux system today has a lot of local system configuration APIs. I'm not talking about library APIs here, but things like DBus services, command/scripts to be executed, or files placed in various locations. All of these constitute the API by which we configure a Linux system. In [Cockpit](http://cockpit-project.org) we access these APIs from a web browser (after authentication of course). How do we access the system APIs? The answer is the `cockpit-bridge` tool. It proxies requests from the Cockpit user interface, running in a web browser, to the system. Typically the `cockpit-bridge` runs as the logged in user, in a user session. It has similar permissions and capabilities as if you had used `ssh` to log into the system. @@ -23,7 +25,7 @@ The protocol that the web browser uses is a [message based protocol](https://git The `cockpit-bridge` tool speaks this protocol on its standard in and standard output. The `cockpit-ws` process hosts the WebSocket and passes the messages to `cockpit-bridge` for processing. -**Following along:** In order to follow along with the stuff below, you'll need at least Cockpit 0.35. The protocol is not yet frozen, and we merged some cleanup recently. You can install it on [Fedora 21 using a COPR](https://lists.fedorahosted.org/pipermail/cockpit-devel/2014-November/000196.html) or [build it from git](https://github.com/cockpit-project/cockpit/blob/master/HACKING.md). +**Following along:** In order to follow along with the stuff below, you'll need at least Cockpit 0.44. The protocol is not yet frozen, and we merged some cleanup recently. You can install it on [Fedora 21 using a COPR](https://lists.fedorahosted.org/pipermail/cockpit-devel/2014-November/000196.html) or [build it from git](https://github.com/cockpit-project/cockpit/blob/master/HACKING.md). Channels -------- @@ -83,7 +85,7 @@ The `"echo"` channel type just sends the messages you send to the `cockpit-bridg Now we're ready to play ... Well almost. -The very first control message sent to and from `cockpit-bridge` must be an `"init"` message containing a version number. Currently that version number is `0` to indicate that protocol is not yet stable: +The very first control message sent to and from `cockpit-bridge` shuld be an `"init"` message containing a version number. Currently that version number is `0` to indicate that protocol is not yet stable:
 
@@ -105,9 +107,6 @@ In this debugging mode sent by `cockpit-bridge` will be bold in your terminal. N
 
 
 
-{ "command": "init", "version": 0 }
-----
-
 { "command": "open", "channel": "mychannel", "payload": "echo" }
 ----
 mychannel
diff --git a/content/files/pinger.tgz b/content/files/pinger.tgz
index 39064ff..98d9741 100644
Binary files a/content/files/pinger.tgz and b/content/files/pinger.tgz differ
diff --git a/content/files/zoner.tgz b/content/files/zoner.tgz
index b461ade..d5dcdeb 100644
Binary files a/content/files/zoner.tgz and b/content/files/zoner.tgz differ
-- 
cgit v1.2.3