Module: Morpheus::Routes

Defined in:
lib/morpheus/routes.rb

Overview

Routes is a module to provide a way to look up routes in the Morpheus UI. Examples:

Routes.lookup("users") == "/admin/users"
Routes.lookup("instances") == "/provisioning/instances"

puts "All routes", Morpheus::Routes.routes

Constant Summary collapse

SITE_MAP =

A static site map for the Morpheus UI. todo: move to YAML or load from api

{
  operations: {
    dashboard: {},
    reports: {},
    analytics: {},
    guidance: {},
    wiki: {},
    costing: {
      budgets: {},
      invoices: {},
      usage: {},
    },
    approvals: {},
    activity: {},
    alarms: {},
  },
  provisioning: {
    instances: {},
    apps: {},
    catalog: {},
    jobs: {},
    executions: {},
    code: {
      respositories: {},
      deployments: {},
      # integrations: {}, # Integrations
    },
  },
  library: {
    automation: [
      "#!tasks",
      "#!workflows",
      "#!thresholds",
      "#!power-schedules",
      "#!execute-schedules",
    ],
    blueprints: [
      "#instance-types",
      "#!instance-type-layouts",
      "#!container-types",
      "#!app-templates", # App Blueprints (blueprints)
      "#!catalog-items",
      "#!compute-type-layouts", # Cluster Layouts
    ],
    :'virtual-images' => {},
    options: [
      "#!option-type-lists", # Option Lists
    ],
    templates: [
      "#!specs",
      "#!files",
      "#!scripts",
      "#!security-specs",
    ],
    services: {}, # Integrations

  },
  infrastructure: {
    groups: {},
    clouds: {},
    clusters: {},
    servers: {}, # Hosts (still used for loading by id)
    inventory: [ # Compute
      "#!hosts",
      "#!virtual-machines",
      "#!containers",
      "#!resources",
      "#!bare-metal",
    ],
    networks: {},
    :'load-balancers' => {},
    storage: {
      buckets: {},  
      shares: {},  # File Shares
      volumes: {},  
      :'data-stores' => {}, # ugh, should be datastores
      servers: {}, # Storage Servers
    },
    # :'keys-and-certs' => {},
    :'key-pairs' => {},
    certificates: {},
  },
  backups: {

  },
  monitoring: {
    status: {},
    logs: {},
    apps: {},
    checks: {},
    groups: {},
    incidents: {},
    contacts: {},
    :'alert-rules' => {}, 
  },
  tools: {
    cypher: {},
    archives: {
      buckets: {},
    },
    :'image-builder' => {},
    :vdi => {}
  },
  admin: {
    accounts: {}, # Tenants
    :'service-plans' => [
      "#prices",
      "#pricesets"
    ],
    roles: {},
    users: {},
    :'user-groups' => {},
    integrations: {},
    policies: {},
    health: ["logs"],
    settings: {},
  },
  :'user-settings' => {}, # User Settings (Profile)
}
@@routes =

A list of routes generated from the site map and cached

nil

Class Method Summary collapse

Class Method Details

.lookup(input) ⇒ Object

lookup a route in the morpheus UI

Parameters:

  • path (String)

    The input to lookup a route for eg. “dashboard”

Returns:

  • full path like “/operations/dashboard”



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/morpheus/routes.rb', line 146

def self.lookup(input)
  path = input.to_s
  if path.start_with?("/")
    # absolute path is being looked up
    return path
  else
    # todo: make this smarter, regex, case insensitive, etc
    # find the one with smallest match index

    # map well known aliases
    case(path.underscore.singularize)
    when "server","host","vm","virtual-machine"
      # actually should be "/infrastructure/inventory" unless id is passed, show route uses /servers though
      path = "/infrastructure/servers"
    when "compute"
      path = "/infrastructure/inventory"
    when "tenant"
      path = "/admin/accounts"
    end
    # dasherize path and attempt to match the plural first
    plural_path = path.pluralize
    paths = [path.dasherize]
    if plural_path != path
      paths.unshift(plural_path.dasherize)
    end

    best_route = nil
    best_index = nil
    best_prefix_words = nil
    paths.each do |p|
      if best_route.nil?
        self.routes.each do |it|
          match_index = it.index(p)
          if match_index
            prefix_route = match_index == 0 ? "" : it[0..(match_index-1)]
            prefix_words = prefix_route.split("/")
            #if best_index.nil? || match_index < best_index
            if best_prefix_words.nil? || prefix_words.size < best_prefix_words.size
              best_route = it
              best_index = match_index
              best_prefix_words = prefix_words
            end
          end
        end
      end
    end
    if best_route
      return best_route
    else
      # no match found
      return nil
    end
  end
  
end

.routesObject

Returns an array of well known Morpheus UI routes.

Returns:

  • an array of well known Morpheus UI routes.



136
137
138
139
140
141
# File 'lib/morpheus/routes.rb', line 136

def self.routes
  if !@@routes
    @@routes = build_routes(SITE_MAP)
  end
  return @@routes
end