func MachineDetail(ctx *vmango.Context, w http.ResponseWriter, req *http.Request) error { machine := &models.VirtualMachine{ Name: mux.Vars(req)["name"], } if exists, err := ctx.Machines.Get(machine); err != nil { return err } else if !exists { return vmango.NotFound(fmt.Sprintf("Machine with name %s not found", machine.Name)) } ctx.Render.HTML(w, http.StatusOK, "machines/detail", map[string]interface{}{ "Request": req, "Machine": machine, }) return nil }
func MetadataDetail(ctx *Context, w http.ResponseWriter, req *http.Request) error { ctx.Logger.WithFields(logrus.Fields{ "method": "metadata_detail", "path": req.URL.String(), "remote_addr": req.RemoteAddr, }).Info("metadata request") ipaddr, _, err := net.SplitHostPort(req.RemoteAddr) if err != nil { return fmt.Errorf("cannot parse remote ip address: %s", err) } meta, err := ctx.Resolver.GetMeta(ipaddr) if err != nil { return fmt.Errorf("cannot get domain metadata: %s", err) } key := mux.Vars(req)["key"] value, exists := meta[key] if !exists { return vmango.NotFound(fmt.Sprintf("metadata key %s doesn't exist", key)) } fmt.Fprintf(w, "%s\n", value) return nil }