gpt4 book ai didi

java - 如何使用 JClouds-Chef 指定客户端版本?

转载 作者:行者123 更新时间:2023-11-30 08:58:56 25 4
gpt4 key购买 nike

我一直在使用以下 JClouds-Chef 1.7.3现在需要几个月的代码来从头开始引导新的虚拟机:

public class Bootstrapper {
public static void main(String[] args) {
Bootstrapper b = new Bootstrapper();
b.bootstrap();
}

public void bootstrap() {
String endpoint = "https://mychef.example.com"
String client = "myuser"
String validator = "chef-validator"

String clientCredential = Files.toString(new File("/etc/myuser/myuser.pem"), Charsets.UTF_8)
String validatorCredential = Files.toString(new File("/etc/myuser/chef-validator.pem"), Charsets.UTF_8)

Properties props = new Properties()
props.put(ChefProperties.CHEF_VALIDATOR_NAME, validator);
props.put(ChefProperties.CHEF_VALIDATOR_CREDENTIAL, validatorCredential)
props.put(Constants.PROPERTY_RELAX_HOSTNAME, "true")
props.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true")

ChefContext ctx = ContextBuilder.newBuilder("chef")
.endpoint(endpoint)
.credentials(client, clientCredential)
.overrides(props)
.modules(ImmutableSet.of(new SshjSshClientModule())) //
.buildView(ChefContext.class);

ChefApi api = ctx.unwrapApi(ChefApi.class)
MyEnvProvider environmentProvider = new MyEnvProvider()

Environment devEnv = environmentProvider.provideEnvironment()
api.createEnvironment(devEnv)

List<String> runlist = new RunListBuilder().addRole("myrole").build()
BootstrapConfig bootstrapConfig = BootstrapConfig.builder().environment("myenv").runList(runlist).build()

String vmIp = "myapp01.example.com"
String vmSshUsername = "myuser"
String vmSshPassword = "12345"
ChefService chef = chefContext.getChefService()
chef.updateBootstrapConfigForGroup(chefGroup, bootstrapConfig)

Statement bootstrap = chef.createBootstrapScriptForGroup(chefGroup)

SshClient.Factory sshFactory = chefContext.unwrap().utils()
.injector().getInstance(Key.get(new TypeLiteral<SshClient.Factory>() {}))

SshClient ssh = sshFactory.create(HostAndPort.fromParts(vmIp, 22),
LoginCredentials.builder().user(vmSshUsername).password(vmSshPassword).build())

ssh.connect()

StringBuilder rawScript = new StringBuilder()

Map<String, String> resolvedFunctions = ScriptBuilder.resolveFunctionDependenciesForStatements(
new HashMap<String, String>(), ImmutableSet.of(bootstrap), OsFamily.UNIX)

ScriptBuilder.writeFunctions(resolvedFunctions, OsFamily.UNIX, rawScript)
rawScript.append(bootstrap.render(OsFamily.UNIX))

ssh.put("/tmp/chef-bootstrap.sh", rawScript.toString())
ExecResponse result = ssh.exec("sudo bash /tmp/chef-bootstrap.sh")

ssh.disconnect()
api.close()
ctx.close()
}
}

几周来我第一次运行这段代码,一切都坏了。这段代码现在似乎产生了使用 Chef 12 的节点,而 mychef.example.com 是 Chef 11 服务器,这就是问题的根源。

所以我问:我如何配置此代码以使其继续安装/引导 Chef 11.x 节点?

请注意:这是一个代码问题,不是系统管理员问题,因此属于 StackOverflow。

最佳答案

jclouds docs list how to configure the process .

在这种情况下,您可能需要类似于 ChefProperties.CHEF_VERSION = '11.16.4' 的内容。我觉得我应该指出 chef-client 12 与 Chef Server 11 一起工作得很好。如果你正在运行 Enterprise Chef 11,你只需要更新它的配置变量以允许客户端 12,因为它被错误地限制为只有 11 .x.

关于java - 如何使用 JClouds-Chef 指定客户端版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27450551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com