Class: EnfCli::Cmd::Xcr

Inherits:
EnfThor
  • Object
show all
Defined in:
lib/enfcli/commands/xcr.rb

Instance Method Summary collapse

Methods inherited from EnfThor

capture_stdout, command_help, handle_argument_error, help

Instance Method Details

#activate_domainObject



346
347
348
349
350
351
352
353
354
355
356
# File 'lib/enfcli/commands/xcr.rb', line 346

def activate_domain
  try_with_rescue_in_session do
    # Call api
    data = EnfApi::API.instance.update_domain_status options[:domain], { :status => "ACTIVE" }
    domains = data[:data]

    # Display the data
    say "Activated Domain!", :green
    display_domains domains
  end
end

#activate_enfnwObject



574
575
576
577
578
579
580
581
582
# File 'lib/enfcli/commands/xcr.rb', line 574

def activate_enfnw
  try_with_rescue_in_session do
    # Call the api
    EnfApi::API.instance.activate_enfnw options.cidr

    # Print success
    say "Activated Enf Network #{options.cidr}!", :green
  end
end

#deactivate_domainObject



361
362
363
364
365
366
367
368
369
370
371
# File 'lib/enfcli/commands/xcr.rb', line 361

def deactivate_domain
  try_with_rescue_in_session do
    # Call api
    data = EnfApi::API.instance.update_domain_status options[:domain], { :status => "READY" }
    domains = data[:data]

    # Display the data
    say "Deactivated Domain!", :yellow
    display_domains domains
  end
end

#get_endpointObject



545
546
547
548
549
550
551
552
553
554
# File 'lib/enfcli/commands/xcr.rb', line 545

def get_endpoint
  try_with_rescue_in_session do
    # call the api
    data = EnfApi::API.instance.get_endpoint options.ipv6
    eps = data[:data]

    # display data
    display_endpoints eps
  end
end

#get_networkObject



177
178
179
180
181
182
183
184
185
186
# File 'lib/enfcli/commands/xcr.rb', line 177

def get_network
  try_with_rescue_in_session do
    # call the api
    data = EnfApi::API.instance.get_nw options.network
    nw = data[:data][0]

    # display data
    display_network nw
  end
end

#list_domain_rate_limitsObject



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/enfcli/commands/xcr.rb', line 281

def list_domain_rate_limits
  try_with_rescue_in_session do
    # Call the api
    data = EnfApi::API.instance.get_domain_rate_limits options[:domain], options[:filter]

    # Get the limits
    limits = data[:data][0]

    # if the Api returns only the rate limits object, have to add type explicitly to display
    limits = {
      options[:filter].to_sym => limits,
    } if options[:filter]

    # Display limits
    display_limits limits
  end
end

#list_domainsObject



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/enfcli/commands/xcr.rb', line 231

def list_domains
  try_with_rescue_in_session do
    session = EnfCli::CTX.instance.session

    # call api
    data = { :data => [] }

    if EnfCli::CTX.instance.xaptum_admin?
      data = EnfApi::API.instance.list_domains
    elsif EnfCli::CTX.instance.has_role?("DOMAIN_ADMIN")
      data = EnfApi::API.instance.get_domain session[:domain_id]
    end

    # Display the data
    domains = data[:data]
    display_domains domains
  end
end

#list_endpoint_eventsObject



517
518
519
520
521
522
523
524
525
526
# File 'lib/enfcli/commands/xcr.rb', line 517

def list_endpoint_events
  try_with_rescue_in_session do
    # call the api
    data = EnfApi::API.instance.list_endpoint_events options.ipv6
    events = data[:data]

    # display data
    display_endpoint_events events
  end
end

#list_endpoint_rate_limitsObject



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/enfcli/commands/xcr.rb', line 325

def list_endpoint_rate_limits
  try_with_rescue_in_session do
    # Call the api
    data = EnfApi::API.instance.get_ep_rate_limits options[:ipv6], options[:filter]

    # Get the limits
    limits = data[:data][0]

    # if the Api returns only the rate limits object, have to add type explicitly to display
    limits = {
      options[:filter].to_sym => limits,
    } if options[:filter]

    # Display limits
    display_limits limits
  end
end

#list_endpointsObject



503
504
505
506
507
508
509
510
511
512
# File 'lib/enfcli/commands/xcr.rb', line 503

def list_endpoints
  try_with_rescue_in_session do
    # call api
    data = EnfApi::API.instance.list_nw_connections options.network
    cxns = data[:data]

    # display table
    display_endpoints cxns
  end
end

#list_enf_networksObject



214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/enfcli/commands/xcr.rb', line 214

def list_enf_networks
  try_with_rescue_in_session do
    # Call the api
    data = EnfApi::API.instance.list_enfnws
    networks = data[:data]

    # Display the data
    headings = ["Id", "Parent", "Network", "Notes", "Status", "Type"]
    rows = networks.map { |hash|
      [hash[:id], hash[:parent], hash[:network], hash[:notes], hash[:status], hash[:type]]
    }
    render_table(headings, rows)
  end
end

#list_network_eventsObject



531
532
533
534
535
536
537
538
539
540
# File 'lib/enfcli/commands/xcr.rb', line 531

def list_network_events
  try_with_rescue_in_session do
    # call the api
    data = EnfApi::API.instance.list_network_events options.network
    events = data[:data]

    # display data
    display_endpoint_events events
  end
end

#list_network_rate_limitsObject



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/enfcli/commands/xcr.rb', line 303

def list_network_rate_limits
  try_with_rescue_in_session do
    # Call the api
    data = EnfApi::API.instance.get_network_rate_limits options[:network], options[:filter]

    # Get the limits
    limits = data[:data][0]

    # if the Api returns only the rate limits object, have to add type explicitly to display
    limits = {
      options[:filter].to_sym => limits,
    } if options[:filter]

    # Display limits
    display_limits limits
  end
end

#list_networksObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/enfcli/commands/xcr.rb', line 110

def list_networks
  try_with_rescue_in_session do
    # get correct domain
    domain = EnfCli::CTX.instance.session[:domain]
    raise EnfCli::ERROR, "User not in a valid domain!" unless domain

    # check if admin
    if EnfCli::CTX.instance.xaptum_admin?
      raise EnfCli::ERROR, "--domain is required" unless options[:domain]

      domain = options[:domain]
    elsif options[:domain]
      say "Warning: Ignoring command option --domain #{options[:domain]}", :yellow
    end

    # Call the api
    data = EnfApi::API.instance.list_domain_nws domain
    networks = data[:data]

    # display table
    display_networks networks
  end
end

#provision_domainObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/enfcli/commands/xcr.rb', line 255

def provision_domain
  try_with_rescue_in_session do
    # Get cli params
    domain_name = options[:name]
    admin_name = options[:'admin-name'].join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
    admin_email = options[:'admin-email']

    # Call api
    hash = {
      :admin_name => admin_name,
      :admin_email => admin_email,
      :name => domain_name,
      :type => "CUSTOMER_SOURCE",
    }
    data = EnfApi::API.instance.create_domain hash

    # Display the data
    domains = data[:data]
    display_domains domains
  end
end

#provision_networkObject



140
141
142
143
144
145
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
# File 'lib/enfcli/commands/xcr.rb', line 140

def provision_network
  try_with_rescue_in_session do
    # get correct domain
    domain = EnfCli::CTX.instance.session[:domain]
    raise EnfCli::ERROR, "User not in a valid domain!" unless domain

    # check if admin
    if EnfCli::CTX.instance.xaptum_admin?
      raise EnfCli::ERROR, "--domain is required" unless options[:domain]

      domain = options[:domain]
    elsif options[:domain]
      say "Warning: Ignoring command option --domain #{options[:domain]}", :yellow
    end

    # Get options
    description = ""
    network_name = options.name.join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
    description = options.description.join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1') if options.description

    # Call the api
    hash = {
      :name => network_name,
      :description => description,
    }
    data = EnfApi::API.instance.create_nw domain, hash
    networks = data[:data]

    # display table
    say "Provisioned a network!", :green
    display_networks networks
  end
end

#reset_endpoint_rate_limitsObject



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/enfcli/commands/xcr.rb', line 482

def reset_endpoint_rate_limits
  try_with_rescue_in_session do
    # Call api
    hash = {
      :inherit => true,
    }
    data = EnfApi::API.instance.update_ep_rate_limits options[:ipv6], options[:limit], hash
    limits = data[:data][0]

    # The Api returns only the rate limits object. Have to add type explicitly to display
    limits_hash = {
      options[:limit].to_sym => limits,
    }
    display_limits limits_hash
  end
end

#reset_network_rate_limitsObject



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/enfcli/commands/xcr.rb', line 433

def reset_network_rate_limits
  try_with_rescue_in_session do
    # Call api
    hash = {
      :inherit => true,
    }
    data = EnfApi::API.instance.update_network_rate_limits options[:network], options[:limit], hash
    limits = data[:data][0]

    # The Api returns only the rate limits object. Have to add type explicitly to display
    limits_hash = {
      options[:limit].to_sym => limits,
    }
    display_limits limits_hash
  end
end

#set_domain_rate_limitsObject



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/enfcli/commands/xcr.rb', line 381

def set_domain_rate_limits
  try_with_rescue_in_session do
    # Call api
    hash = {
      :packets_per_second => options["packets-per-second"],
      :packets_burst_size => options["packets-burst-size"],
      :bytes_per_second => options["bytes-per-second"],
      :bytes_burst_size => options["bytes-burst-size"],
    }
    data = EnfApi::API.instance.update_domain_rate_limits options[:domain], options[:limit], hash
    limits = data[:data][0]

    # The Api returns only the rate limits object. Have to add type explicitly to display
    limits_hash = {
      options[:limit].to_sym => limits,
    }
    display_limits limits_hash
  end
end

#set_endpoint_rate_limitsObject



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/enfcli/commands/xcr.rb', line 458

def set_endpoint_rate_limits
  try_with_rescue_in_session do
    # Call api
    hash = {
      :packets_per_second => options["packets-per-second"],
      :packets_burst_size => options["packets-burst-size"],
      :bytes_per_second => options["bytes-per-second"],
      :bytes_burst_size => options["bytes-burst-size"],
    }
    data = EnfApi::API.instance.update_ep_rate_limits options[:ipv6], options[:limit], hash
    limits = data[:data][0]

    # The Api returns only the rate limits object. Have to add type explicitly to display
    limits_hash = {
      options[:limit].to_sym => limits,
    }
    display_limits limits_hash
  end
end

#set_network_rate_limitsObject



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/enfcli/commands/xcr.rb', line 409

def set_network_rate_limits
  try_with_rescue_in_session do
    # Call api
    hash = {
      :packets_per_second => options["packets-per-second"],
      :packets_burst_size => options["packets-burst-size"],
      :bytes_per_second => options["bytes-per-second"],
      :bytes_burst_size => options["bytes-burst-size"],
    }
    data = EnfApi::API.instance.update_network_rate_limits options[:network], options[:limit], hash
    limits = data[:data][0]

    # The Api returns only the rate limits object. Have to add type explicitly to display
    limits_hash = {
      options[:limit].to_sym => limits,
    }
    display_limits limits_hash
  end
end

#update_endpointObject



560
561
562
563
564
565
566
567
568
569
# File 'lib/enfcli/commands/xcr.rb', line 560

def update_endpoint
  try_with_rescue_in_session do
    # Call the api
    data = EnfApi::API.instance.update_endpoint options.ipv6, options.name.join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
    eps = data[:data]

    # display data
    display_endpoints eps
  end
end

#update_networkObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/enfcli/commands/xcr.rb', line 193

def update_network
  try_with_rescue_in_session do
    # Get options
    name = options.name.join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1') if options.name
    description = options.description.join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1') if options.description

    # Call the api
    hash = {}.tap do |h|
      h[:name] = name if options.name
      h[:description] = description if options.description
    end
    data = EnfApi::API.instance.update_nw options.network, hash
    networks = data[:data]

    # display table
    display_networks networks
  end
end