MCPcopy Create free account
hub / github.com/M2Team/NanaBox / ComputeNetworkCreateEndpoint

Method ComputeNetworkCreateEndpoint

NanaBox/ConfigurationManager.cpp:524–695  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

522}
523
524void NanaBox::ComputeNetworkCreateEndpoint(
525 std::string const& Owner,
526 NanaBox::NetworkAdapterConfiguration& Configuration)
527{
528 NanaBox::HcnNetwork NetworkHandle;
529 winrt::guid SwitchId = NanaBox::NanaBoxSwitchId;
530 {
531 bool UseSuggestedSwitchId = false;
532 bool UseSuggestedSwitchName = false;
533 bool UseSuggestedSwitchSubnet = false;
534 if (!Configuration.SuggestedSwitchId.empty())
535 {
536 try
537 {
538 winrt::guid CandidateSwitchId = winrt::guid(
539 Configuration.SuggestedSwitchId);
540 if (NanaBox::NanaBoxSwitchId != CandidateSwitchId)
541 {
542 SwitchId = CandidateSwitchId;
543 UseSuggestedSwitchId = true;
544 }
545 }
546 catch (...)
547 {
548 }
549 }
550 nlohmann::json Settings;
551 {
552 std::string SwitchName = "NanaBox";
553 if (UseSuggestedSwitchId)
554 {
555 if (Configuration.SuggestedSwitchName.empty() ||
556 "NanaBox" == Configuration.SuggestedSwitchName)
557 {
558 SwitchName.push_back('_');
559 SwitchName.append(winrt::to_string(::FromGuid(SwitchId)));
560 }
561 else
562 {
563 SwitchName = Configuration.SuggestedSwitchName;
564 }
565 UseSuggestedSwitchName = true;
566 }
567 Settings["Name"] = SwitchName;
568 }
569 Settings["Type"] = "ICS";
570 Settings["IsolateSwitch"] = true;
571 Settings["Flags"] =
572 NanaBox::HcnNetworkFlags::EnableDns |
573 NanaBox::HcnNetworkFlags::EnableDhcp |
574 NanaBox::HcnNetworkFlags::EnableNonPersistent;
575 if (!Configuration.SuggestedSwitchSubnet.empty())
576 {
577 std::uint8_t Octets[4] = {};
578 std::uint8_t PrefixLength = 0;
579 if (5 == ::sscanf_s(
580 Configuration.SuggestedSwitchSubnet.c_str(),
581 "%hhu.%hhu.%hhu.%hhu/%hhu",

Callers

nothing calls this directly

Calls 1

FromGuidFunction · 0.85

Tested by

no test coverage detected