Search in sources :

Example 11 with SSHKeyPairVO

use of com.cloud.user.SSHKeyPairVO in project cloudstack by apache.

the class KubernetesClusterStartWorker method getKubernetesAdditionalControlNodeConfig.

private String getKubernetesAdditionalControlNodeConfig(final String joinIp, final boolean ejectIso) throws IOException {
    String k8sControlNodeConfig = readResourceFile("/conf/k8s-control-node-add.yml");
    final String joinIpKey = "{{ k8s_control_node.join_ip }}";
    final String clusterTokenKey = "{{ k8s_control_node.cluster.token }}";
    final String sshPubKey = "{{ k8s.ssh.pub.key }}";
    final String clusterHACertificateKey = "{{ k8s_control_node.cluster.ha.certificate.key }}";
    final String ejectIsoKey = "{{ k8s.eject.iso }}";
    String pubKey = "- \"" + configurationDao.getValue("ssh.publickey") + "\"";
    String sshKeyPair = kubernetesCluster.getKeyPair();
    if (StringUtils.isNotEmpty(sshKeyPair)) {
        SSHKeyPairVO sshkp = sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), sshKeyPair);
        if (sshkp != null) {
            pubKey += "\n      - \"" + sshkp.getPublicKey() + "\"";
        }
    }
    k8sControlNodeConfig = k8sControlNodeConfig.replace(sshPubKey, pubKey);
    k8sControlNodeConfig = k8sControlNodeConfig.replace(joinIpKey, joinIp);
    k8sControlNodeConfig = k8sControlNodeConfig.replace(clusterTokenKey, KubernetesClusterUtil.generateClusterToken(kubernetesCluster));
    k8sControlNodeConfig = k8sControlNodeConfig.replace(clusterHACertificateKey, KubernetesClusterUtil.generateClusterHACertificateKey(kubernetesCluster));
    k8sControlNodeConfig = k8sControlNodeConfig.replace(ejectIsoKey, String.valueOf(ejectIso));
    k8sControlNodeConfig = updateKubeConfigWithRegistryDetails(k8sControlNodeConfig);
    return k8sControlNodeConfig;
}
Also used : SSHKeyPairVO(com.cloud.user.SSHKeyPairVO)

Example 12 with SSHKeyPairVO

use of com.cloud.user.SSHKeyPairVO in project cloudstack by apache.

the class KubernetesClusterStartWorker method getKubernetesControlNodeConfig.

private String getKubernetesControlNodeConfig(final String controlNodeIp, final String serverIp, final String hostName, final boolean haSupported, final boolean ejectIso) throws IOException {
    String k8sControlNodeConfig = readResourceFile("/conf/k8s-control-node.yml");
    final String apiServerCert = "{{ k8s_control_node.apiserver.crt }}";
    final String apiServerKey = "{{ k8s_control_node.apiserver.key }}";
    final String caCert = "{{ k8s_control_node.ca.crt }}";
    final String sshPubKey = "{{ k8s.ssh.pub.key }}";
    final String clusterToken = "{{ k8s_control_node.cluster.token }}";
    final String clusterInitArgsKey = "{{ k8s_control_node.cluster.initargs }}";
    final String ejectIsoKey = "{{ k8s.eject.iso }}";
    final List<String> addresses = new ArrayList<>();
    addresses.add(controlNodeIp);
    if (!serverIp.equals(controlNodeIp)) {
        addresses.add(serverIp);
    }
    final Certificate certificate = caManager.issueCertificate(null, Arrays.asList(hostName, "kubernetes", "kubernetes.default", "kubernetes.default.svc", "kubernetes.default.svc.cluster", "kubernetes.default.svc.cluster.local"), addresses, 3650, null);
    final String tlsClientCert = CertUtils.x509CertificateToPem(certificate.getClientCertificate());
    final String tlsPrivateKey = CertUtils.privateKeyToPem(certificate.getPrivateKey());
    final String tlsCaCert = CertUtils.x509CertificatesToPem(certificate.getCaCertificates());
    k8sControlNodeConfig = k8sControlNodeConfig.replace(apiServerCert, tlsClientCert.replace("\n", "\n      "));
    k8sControlNodeConfig = k8sControlNodeConfig.replace(apiServerKey, tlsPrivateKey.replace("\n", "\n      "));
    k8sControlNodeConfig = k8sControlNodeConfig.replace(caCert, tlsCaCert.replace("\n", "\n      "));
    String pubKey = "- \"" + configurationDao.getValue("ssh.publickey") + "\"";
    String sshKeyPair = kubernetesCluster.getKeyPair();
    if (StringUtils.isNotEmpty(sshKeyPair)) {
        SSHKeyPairVO sshkp = sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), sshKeyPair);
        if (sshkp != null) {
            pubKey += "\n      - \"" + sshkp.getPublicKey() + "\"";
        }
    }
    k8sControlNodeConfig = k8sControlNodeConfig.replace(sshPubKey, pubKey);
    k8sControlNodeConfig = k8sControlNodeConfig.replace(clusterToken, KubernetesClusterUtil.generateClusterToken(kubernetesCluster));
    String initArgs = "";
    if (haSupported) {
        initArgs = String.format("--control-plane-endpoint %s:%d --upload-certs --certificate-key %s ", serverIp, CLUSTER_API_PORT, KubernetesClusterUtil.generateClusterHACertificateKey(kubernetesCluster));
    }
    initArgs += String.format("--apiserver-cert-extra-sans=%s", serverIp);
    initArgs += String.format(" --kubernetes-version=%s", getKubernetesClusterVersion().getSemanticVersion());
    k8sControlNodeConfig = k8sControlNodeConfig.replace(clusterInitArgsKey, initArgs);
    k8sControlNodeConfig = k8sControlNodeConfig.replace(ejectIsoKey, String.valueOf(ejectIso));
    k8sControlNodeConfig = updateKubeConfigWithRegistryDetails(k8sControlNodeConfig);
    return k8sControlNodeConfig;
}
Also used : ArrayList(java.util.ArrayList) SSHKeyPairVO(com.cloud.user.SSHKeyPairVO) Certificate(org.apache.cloudstack.framework.ca.Certificate)

Example 13 with SSHKeyPairVO

use of com.cloud.user.SSHKeyPairVO in project cloudstack by apache.

the class SSHKeyPairDaoImpl method deleteByName.

@Override
public boolean deleteByName(long accountId, long domainId, String name) {
    SSHKeyPairVO pair = findByName(accountId, domainId, name);
    if (pair == null)
        return false;
    expunge(pair.getId());
    return true;
}
Also used : SSHKeyPairVO(com.cloud.user.SSHKeyPairVO)

Example 14 with SSHKeyPairVO

use of com.cloud.user.SSHKeyPairVO in project cosmic by MissionCriticalCloud.

the class SSHKeyPairDaoImpl method deleteByName.

@Override
public boolean deleteByName(final long accountId, final long domainId, final String name) {
    final SSHKeyPairVO pair = findByName(accountId, domainId, name);
    if (pair == null) {
        return false;
    }
    expunge(pair.getId());
    return true;
}
Also used : SSHKeyPairVO(com.cloud.user.SSHKeyPairVO)

Example 15 with SSHKeyPairVO

use of com.cloud.user.SSHKeyPairVO in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method listSSHKeyPairs.

@Override
public Pair<List<? extends SSHKeyPair>, Integer> listSSHKeyPairs(final ListSSHKeyPairsCmd cmd) {
    final String name = cmd.getName();
    final String fingerPrint = cmd.getFingerprint();
    final Account caller = getCaller();
    final List<Long> permittedAccounts = new ArrayList<>();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
    _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
    final Long domainId = domainIdRecursiveListProject.first();
    final Boolean isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final SearchBuilder<SSHKeyPairVO> sb = _sshKeyPairDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    final Filter searchFilter = new Filter(SSHKeyPairVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchCriteria<SSHKeyPairVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.EQ, name);
    }
    if (fingerPrint != null) {
        sc.addAnd("fingerprint", SearchCriteria.Op.EQ, fingerPrint);
    }
    final Pair<List<SSHKeyPairVO>, Integer> result = _sshKeyPairDao.searchAndCount(sc, searchFilter);
    return new Pair<>(result.first(), result.second());
}
Also used : Account(com.cloud.legacymodel.user.Account) Ternary(com.cloud.legacymodel.utils.Ternary) ArrayList(java.util.ArrayList) SSHKeyPairVO(com.cloud.user.SSHKeyPairVO) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) SSHKeyPair(com.cloud.legacymodel.user.SSHKeyPair) Pair(com.cloud.legacymodel.utils.Pair)

Aggregations

SSHKeyPairVO (com.cloud.user.SSHKeyPairVO)16 Account (com.cloud.user.Account)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 Account (com.cloud.legacymodel.user.Account)4 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 ArrayList (java.util.ArrayList)3 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)2 DomainVO (com.cloud.domain.DomainVO)2 ActionEvent (com.cloud.event.ActionEvent)2 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 Filter (com.cloud.utils.db.Filter)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 SSHKeysHelper (com.cloud.utils.ssh.SSHKeysHelper)2 List (java.util.List)2 DataCenter (com.cloud.dc.DataCenter)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 KubernetesSupportedVersion (com.cloud.kubernetes.version.KubernetesSupportedVersion)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 SSHKeyPair (com.cloud.legacymodel.user.SSHKeyPair)1