Created
October 22, 2014 20:18
-
-
Save makyo/3a5e4428dc2351115a26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// This is a demo application that uses the jujusvg library to build a bundle SVG | |
// from a given bundle.yaml file. | |
import ( | |
"io/ioutil" | |
"log" | |
"os" | |
"strings" | |
// Import the jujusvg library and the juju charm library | |
"github.com/juju/jujusvg" | |
"gopkg.in/juju/charm.v4" | |
) | |
// iconURL takes a reference to a charm and returns the URL for that charm's icon. | |
// In this case, we're using the manage.jujucharms.com API to provide the icon's URL. | |
func iconURL(ref *charm.Reference) string { | |
return "https://manage.jujucharms.com/api/3/charm/" + ref.Path() + "/file/icon.svg" | |
} | |
func main() { | |
// First, we need to read our bundle data into a []byte | |
bundle_data, err := ioutil.ReadFile("bundle.yaml") | |
if err != nil { | |
log.Fatalf("Error reading bundle: %s\n", err) | |
} | |
// Next, generate a charm.Bundle from the bytearray by passing it to ReadNewBundleData. | |
// This gives us an in-memory object representation of the bundle that we can pass to jujusvg | |
bundle, err := charm.ReadBundleData(strings.NewReader(string(bundle_data))) | |
if err != nil { | |
log.Fatalf("Error parsing bundle: %s\n", err) | |
} | |
// Next, build a canvas of the bundle. This is a simplified version of a charm.Bundle | |
// that contains just the position information and charm icon URLs necessary to build | |
// the SVG representation of the bundle | |
canvas, err := jujusvg.NewFromBundle(bundle, iconURL) | |
if err != nil { | |
log.Fatalf("Error generating canvas: %s\n", err) | |
} | |
// Finally, marshal that canvas as SVG to os.Stdout; this will print the SVG data | |
// required to generate an image of the bundle. | |
canvas.Marshal(os.Stdout) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
mongodb: | |
charm: "cs:precise/mongodb-21" | |
num_units: 1 | |
annotations: | |
"gui-x": "940.5" | |
"gui-y": "388.7698359714502" | |
constraints: "mem=2G cpu-cores=1" | |
elasticsearch: | |
charm: "cs:~charming-devs/precise/elasticsearch-2" | |
num_units: 1 | |
annotations: | |
"gui-x": "490.5" | |
"gui-y": "369.7698359714502" | |
constraints: "mem=2G cpu-cores=1" | |
charmworld: | |
charm: "cs:~juju-jitsu/precise/charmworld-58" | |
num_units: 1 | |
expose: true | |
annotations: | |
"gui-x": "813.5" | |
"gui-y": "112.23016402854975" | |
options: | |
charm_import_limit: -1 | |
source: "lp:~bac/charmworld/ingest-local-charms" | |
revno: 511 | |
relations: | |
- - "charmworld:essearch" | |
- "elasticsearch:essearch" | |
- - "charmworld:database" | |
- "mongodb:database" | |
series: precise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment