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: {},
    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
    },
    trust: [
      "#!credentials",
      "#!certificates",
      "#!keypairs",
      "#!services",
    ],
    boot: [
      "#!mappings",
      "#!boot-menus",
      "#!answerfiles",
      "#!boot-images",
      "#!macs",
    ],
  },
  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: [
      "#!appliance",
      "#!whitelabel",
      "provisioning",
      "monitoring",
      "backups",
      "logs",
      "#!guidance",
      "environments",
      "software-licenses",
      "#!license",
      "#!utilities"
    ],
  },
  :'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”



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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/morpheus/routes.rb', line 166

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.dasherize.pluralize)
    when "servers","hosts","vms","virtual-machines"
      # actually should be "/infrastructure/inventory" unless id is passed, show route uses /servers though
      path = "/infrastructure/servers"
    when "computes", "inventories"
      path = "/infrastructure/inventory"
    when "tenants"
      path = "/admin/accounts"
    when "appliance-settings"
      path = "/admin/settings/#!appliance"
    when "whitelabel-settings"
      path = "/admin/settings/#!whitelabel"
    when "provisioning-settings"
      path = "/admin/settings/#!provisioning"
    when "monitoring-settings","monitor-settings"
      path = "/admin/settings/monitoring"
    when "backup-settings"
      path = "/admin/settings/backups"
    when "log-settings"
      path = "/admin/settings/logs"
    when "guidance-settings"
      path = "/admin/settings/#!guidance"
    when "environments"
      path = "/admin/settings/environments"
    when "software-licenses"
      path = "/admin/settings/software-licenses"
    when "license"
      path = "/admin/settings/#!license"
    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.



156
157
158
159
160
161
# File 'lib/morpheus/routes.rb', line 156

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