public void creatVM() {
        //认证
        OSClientV3 os = this.credentials(userName, password, url);

        String pass = "#cloud-config\nchpasswd:\n   list: |\n       root:" + "123456" +"\n   expire: false\nssh_pwauth: true";
        String userData = new sun.misc.BASE64Encoder().encode(pass.getBytes()).replace("\r\n", "");
        
        System.out.println("设置密码" + userData);

        ServerCreate sc = Builders.server().name("lyufcentOS").flavor("12121212")
                .networks(Arrays.asList("4aaefd04-4a99-4f1d-aff6-e96b8be3cff2"))
                .image("42ba0c93-1866-474c-b73b-78dc9c6c2b3a")
                .userData(userData)
                .build();//主要去掉networks,不然会绑定两个IP上去
        Server boot = os.compute().servers().boot(sc);
    }
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐