예제 #1
0
  /**
   * @see javax.wbem.client.WBEMClient
   * @param subject - a security subject built for authentication on the CIM server
   * @param path - initial search path
   * @return a client ready to work with CIM data
   * @throws GetCimWBEMException if we cannot initialize the client
   */
  public WBEMClient client(final Subject subject, final CIMObjectPath path) {
    WBEMClient client = WBEMClientFactory.getClient(WBEMCLIENT_FORMAT);

    try {

      client.initialize(path, subject, new Locale[] {new Locale("en")});

    } catch (WBEMException e) {
      throw new GetCimWBEMException(e);
    }

    return client;
  }
  public CuraPowerClient(String hostname, String username, String password) {

    try {
      cli = WBEMClientFactory.getClient("CIM-XML");
      Subject subject = new Subject();

      cop = new CIMObjectPath("https", hostname, "5989", "/root/cimv2", null, null);
      cli.initialize(cop, subject, null);

    } catch (WBEMException e) {
      System.out.println(e);
    }
  }
  public String getserverstatus(
      String ipAddress,
      String username,
      String password,
      String namespace,
      String port,
      String protocol,
      String ftag) {

    this.status = "OFFLINE";
    this.ftag = ftag;
    String unsecureClientNameSpace = protocol + "://" + ipAddress + ":" + port + "/" + namespace;

    try {
      CIMObjectPath cns = new CIMObjectPath(unsecureClientNameSpace);
      UserPrincipal up = new UserPrincipal(username);
      PasswordCredential pc = new PasswordCredential(password);

      Subject s = new Subject();
      s.getPrincipals().add(up);
      s.getPrivateCredentials().add(pc);
      this.cc = WBEMClientFactory.getClient("CIM-XML");
      Locale[] l = {Locale.ENGLISH, Locale.CHINESE};
      this.cc.initialize(cns, s, l);
      try {
        this.instanceEnum =
            this.cc.enumerateInstances(
                new CIMObjectPath("CIM_System", namespace), true, false, true, null);
      } catch (WBEMException ce) {

        this.instanceEnum = null;
      }
      if (this.instanceEnum == null) {
        this.status = "OFFLINE";
        // this.ucs.updateCimom(Cimom.STATUS_OFFLINE, cimomId);
      } else if (instanceEnum != null) {
        this.status = "ONLINE";
        // this.ucs.updateCimom(Cimom.STATUS_ONLINE, cimomId);
      }

    } catch (WBEMException ce) {
      // ucs.updateCimom(Cimom.STATUS_OFFLINE, cimomId);
    }
    // return this.cc;
    return this.status;
  }