如何通过azure sdk安装厨师扩展

时间:2015-07-29 12:12:35

标签: java azure cloud chef

我需要通过Java Azure SDK创建包含Chef扩展的角色的部署。我有下一个用于设置扩展参数的代码,但它不起作用。

作为一个例子,我使用Python http://blogs.msdn.com/b/shwetasblogs/archive/2015/02/19/creating-deployment-amp-customizing-linux-vms-with-python-amp-chef-part-2.aspx

中的下一个材料
private void withExtension(Role role) {
        ArrayList<ResourceExtensionReference> references = new ArrayList<ResourceExtensionReference>();
        ResourceExtensionReference reference = new ResourceExtensionReference();
        reference.setReferenceName("LinuxChefClient");
        reference.setVersion("11.*");
        reference.setPublisher("Chef.Bootstrap.WindowsAzure");
        reference.setName("LinuxChefClient");

        ResourceExtensionParameterValue publicConfig = new ResourceExtensionParameterValue();
        publicConfig.setType("Public");
        publicConfig.setKey("PublicParams");
        String value = "{\n" +
                "  \"client_rb\": \"chef_server_url \\\"https://<chefServerUri>\\\"\\nnode_name \\\"<vmName>\\\"\\nvalidation_key \\\"/etc/chef/validation.pem\\\"\\nlog_location  \\\"/etc/chef/client.log\\\"\\nlog_level  :info\\njson_attribs \\\"/etc/chef/role.json\\\"\",\n" +
                "  \"run_list\": [\"role[base]\"]\n" +
                "}";
        publicConfig.setValue(value);


        ResourceExtensionParameterValue privateConfig = new ResourceExtensionParameterValue();
        privateConfig.setType("Private");
        privateConfig.setKey("PrivateParams");
        privateConfig.setValue("{ \"validation_key\": \"" + VALIDATION_PEM + "\" }");

        ArrayList<ResourceExtensionParameterValue> parameterValues = new ArrayList<ResourceExtensionParameterValue>();


    parameterValues.add(publicConfig);
            parameterValues.add(privateConfig);
reference.setResourceExtensionParameterValues(parameterValues);

        references.add(reference);

        role.setResourceExtensionReferences(references);
}

1 个答案:

答案 0 :(得分:0)

您似乎没有加密privateConfigpublicConfig的值。在设置值之前,我需要加密这些值:

    <PublicConfiguration>
base-64-encoded-xsd-for-extension-public-configuration
</PublicConfiguration>
      <PrivateConfiguration>
base-64-encoded-xsd-for-extension-private-configuration
</PrivateConfiguration>

请尝试将此代码添加到您的项目中:

value=Base64.encode(value.getBytes(Charset.forName("UTF-8")));

顺便提一下,如果上述代码不起作用,请分享更多错误信息。