예제 #1
0
        public override async Task AddSwitch(string sw)
        {
            HostVirtualSwitchSpec swspec = new HostVirtualSwitchSpec();

            swspec.numPorts = 32;
            // swspec.policy = new HostNetworkPolicy();
            // swspec.policy.security = new HostNetworkSecurityPolicy();
            await _client.vim.AddVirtualSwitchAsync(_client.net, sw, swspec);
        }
예제 #2
0
        private void doAddVirtualSwitch()
        {
            ManagedObjectReference dcmor;
            ManagedObjectReference hostfoldermor;
            ManagedObjectReference hostmor = null;

            datacenter = cb.get_option("datacenter");
            host       = cb.get_option("host");
            vswitchId  = cb.get_option("vswitchid");
            try {
                if (((datacenter != null) && (host != null)) ||
                    ((datacenter != null) && (host == null)))
                {
                    dcmor
                        = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", datacenter);
                    if (dcmor == null)
                    {
                        Console.WriteLine("Datacenter not found");
                        return;
                    }
                    hostfoldermor = vmUtils.getHostFolder(dcmor);
                    hostmor       = vmUtils.getHost(hostfoldermor, host);
                }
                else if ((datacenter == null) && (host != null))
                {
                    hostmor = vmUtils.getHost(null, host);
                }
                if (hostmor != null)
                {
                    Object cmobj
                        = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");
                    HostConfigManager      configMgr = (HostConfigManager)cmobj;
                    ManagedObjectReference nwSystem  = configMgr.networkSystem;
                    HostVirtualSwitchSpec  spec      = new HostVirtualSwitchSpec();
                    spec.numPorts = 8;
                    cb.getConnection()._service.AddVirtualSwitch(nwSystem, vswitchId, spec);
                    Console.WriteLine(cb.getAppName() + " : Successful creating : "
                                      + vswitchId);
                }
                else
                {
                    Console.WriteLine("Host not found");
                }
            }
            catch (SoapException e)
            {
                if (e.Detail.FirstChild.LocalName.Equals("InvalidArgumentFault"))
                {
                    Console.WriteLine(cb.getAppName() + "vswitchName exceeds the maximum "
                                      + "allowed length, or the number of ports "
                                      + "specified falls out of valid range, or the network "
                                      + "policy is invalid, or beacon configuration is invalid. ");
                }
                else if (e.Detail.FirstChild.LocalName.Equals("AlreadyExistsFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed : Switch already exists ");
                }
                else if (e.Detail.FirstChild.LocalName.Equals("HostConfigFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed : Configuration failures. ");
                }
                else if (e.Detail.FirstChild.LocalName.Equals("NotFoundFault"))
                {
                    Console.WriteLine(e.Message.ToString());
                }
                else
                {
                    throw e;
                }
            }

            catch (Exception e) {
                Console.WriteLine(cb.getAppName() + " : Failed adding switch: " + vswitchId);
                throw e;
            }
        }
예제 #3
0
 private void doAddVirtualSwitch()  {
    ManagedObjectReference dcmor ;
    ManagedObjectReference hostfoldermor ;
    ManagedObjectReference hostmor = null; 
    datacenter = cb.get_option("datacenter");
    host = cb.get_option("host");
    vswitchId = cb.get_option("vswitchid");
    try {
       if(((datacenter !=null) && (host !=null)) 
             ||((datacenter !=null) && (host ==null))) {
          dcmor 
             = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", datacenter);
          if(dcmor == null) {
              Console.WriteLine("Datacenter not found");
              return;
          }
          hostfoldermor = vmUtils.getHostFolder(dcmor);
          hostmor = vmUtils.getHost(hostfoldermor, host);
       }
       else if ((datacenter ==null) && (host !=null)) {
          hostmor = vmUtils.getHost(null, host); 
       }
       if(hostmor != null) {
          Object cmobj 
             = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");
          HostConfigManager configMgr = (HostConfigManager)cmobj;
          ManagedObjectReference nwSystem = configMgr.networkSystem;
          HostVirtualSwitchSpec spec = new HostVirtualSwitchSpec();
          spec.numPorts=8;
          cb.getConnection()._service.AddVirtualSwitch(nwSystem, vswitchId, spec);
          Console.WriteLine(cb.getAppName() + " : Successful creating : " 
                           + vswitchId);
       }
       else{
          Console.WriteLine("Host not found");
       }  
    }
    catch (SoapException e)
    {
        if (e.Detail.FirstChild.LocalName.Equals("InvalidArgumentFault"))
        {
            Console.WriteLine(cb.getAppName() + "vswitchName exceeds the maximum "
                             + "allowed length, or the number of ports "
                             + "specified falls out of valid range, or the network "
                             + "policy is invalid, or beacon configuration is invalid. ");
        }
        else if (e.Detail.FirstChild.LocalName.Equals("AlreadyExistsFault"))
        {
            Console.WriteLine(cb.getAppName() + " : Failed : Switch already exists ");
        }
        else if (e.Detail.FirstChild.LocalName.Equals("HostConfigFault"))
        {
            Console.WriteLine(cb.getAppName() + " : Failed : Configuration failures. ");
        }
        else if (e.Detail.FirstChild.LocalName.Equals("NotFoundFault"))
        {
            Console.WriteLine(e.Message.ToString());
        }
        else
        {
            throw e;
        }
    }
   
    catch (Exception e) {
       Console.WriteLine(cb.getAppName() + " : Failed adding switch: "+ vswitchId);
       throw e;
    }
 }