• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Server类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.openstack4j.model.compute.Server的典型用法代码示例。如果您正苦于以下问题:Java Server类的具体用法?Java Server怎么用?Java Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Server类属于org.openstack4j.model.compute包,在下文中一共展示了Server类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: create

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
public Server create(String name, String keypairName, String imageId, String flavorId, 
		List<String> networks, boolean powerOn) {
	Assert.notNull(client());
	
	ServerCreate serverCreate = client().compute().servers().serverBuilder()
		.name(name)
		.keypairName(keypairName)
		.image(imageId)
		.flavor(flavorId)
		.networks(networks)
		.build();
	
	Server server = null;
	if (powerOn)
		server = client().compute().servers().boot(serverCreate) ;
	
	return server;
}
 
开发者ID:evoila,项目名称:cfsummiteu2017,代码行数:19,代码来源:NovaFluent.java


示例2: waitUntilServerDeleted

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
private static void waitUntilServerDeleted(OSClient os, String serverId) throws Exception{
    while(true){
        Server server=os.compute().servers().get(serverId);
        Server.Status status=Status.DELETED;
        if(server!=null)
            status=server.getStatus();
        System.out.println("current status: "+status.toString());
        if(status.equals(Status.DELETED)){
            break; 
        }else{
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
            }
        }
    }
}
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:18,代码来源:NovaAPI.java


示例3: getVolumesAttachedToServer

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
public static Set<String> getVolumesAttachedToServer(String serverId, OSClient os) throws Exception {
    ServerService serverService = os.compute().servers();
    serverId=CommonAPI.takeFromMemory(NovaKey.NOVA_SERVERID, serverId);
    Server server = serverService.get(serverId);
    List<String> volumeList = server.getOsExtendedVolumesAttached();
    Set<String> volSet = new TreeSet<String>();
    for (String volumeId : volumeList) {
        VolumeAttachment attachment = getAttachmentOnVolume(volumeId, os);
        if (!attachment.getDevice().contains("vda")) {
            printVolumeDetails(os.blockStorage().volumes().get(volumeId));
            volSet.add(volumeId);
        }
    }
    System.out.println("Total Attached Volumes: "+volSet.size());
    return volSet;
}
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:17,代码来源:CinderAPI.java


示例4: refreshAll

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Override
public void refreshAll(PluginRequest pluginRequest) throws Exception{
    if (!refreshed) {
        String agentID;
        PluginSettings pluginSettings = pluginRequest.getPluginSettings();
        Agents agents = pluginRequest.listAgents();
        Map<String, String> op_instance_prefix = new HashMap<String, String>();
        op_instance_prefix.put("name",pluginSettings.getOpenstackVmPrefix());
        List<Server> allInstances = (List<Server>) os_client(pluginSettings).compute().servers().list(op_instance_prefix);
        for (Server server : allInstances) {
            if (agents.containsAgentWithId(server.getId())) {
                register(new OpenStackInstance(server.getId(),
                        server.getCreated(),
                        server.getMetadata().get(Constants.GOSERVER_PROPERTIES_PREFIX + Constants.ENVIRONMENT_KEY),
                        os_client(pluginSettings)));
            }else{
                os_client(pluginSettings).compute().servers().delete(server.getId());
            }
        }
        refreshed = true;
    }
}
 
开发者ID:gocd-contrib,项目名称:openstack-elastic-agent,代码行数:23,代码来源:OpenStackInstances.java


示例5: unregisteredAfterTimeout

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
private OpenStackInstances unregisteredAfterTimeout(PluginSettings settings, Agents knownAgents) throws Exception {

        String agentID;
        Map<String, String> op_instance_prefix = new HashMap<String, String>();
        op_instance_prefix.put("name",settings.getOpenstackVmPrefix());

        Period period = settings.getAutoRegisterPeriod();
        OpenStackInstances unregisteredInstances = new OpenStackInstances();
        OpenstackClientWrapper client = new OpenstackClientWrapper(settings);
        List<Server> allInstances = (List<Server>) client.getClient().compute().servers().list(op_instance_prefix);

        for (Server server : allInstances) {
            if (knownAgents.containsAgentWithId(server.getId())) {
                continue;
            }
            if (DateUtils.addMinutes(server.getCreated(), period.getMinutes()).before(new Date())) {
                unregisteredInstances.register(new OpenStackInstance(server.getId(),
                        server.getCreated(),
                        server.getMetadata().get(Constants.GOSERVER_PROPERTIES_PREFIX + Constants.ENVIRONMENT_KEY),
                        client.getClient()));
            }
        }
        return unregisteredInstances;
    }
 
开发者ID:gocd-contrib,项目名称:openstack-elastic-agent,代码行数:25,代码来源:OpenStackInstances.java


示例6: startMachines

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Override
public List<Machine> startMachines(int count) throws StartMachinesException, CloudPoolDriverException {
    checkState(isConfigured(), "attempt to use unconfigured driver");

    List<Machine> startedMachines = new ArrayList<>();
    try {
        for (int i = 0; i < count; i++) {
            // tag new server with cloud pool membership
            Map<String, String> tags = ImmutableMap.of(Constants.CLOUD_POOL_TAG, getPoolName());
            Server newServer = this.client.launchServer(uniqueServerName(), provisioningTemplate(), tags);
            Machine machine = serverToMachine().apply(newServer);
            startedMachines.add(machine);

            if (provisioningTemplate().isAssignFloatingIp()) {
                String serverId = newServer.getId();
                String floatingIp = this.client.assignFloatingIp(serverId);
                machine.getPublicIps().add(floatingIp);
            }
        }
    } catch (Exception e) {
        throw new StartMachinesException(count, startedMachines, e);
    }
    return startedMachines;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:25,代码来源:OpenStackPoolDriver.java


示例7: doRequest

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Override
public Void doRequest(OSClient api) throws NotFoundException, ResponseException {
    // look for victim server in all regions
    ServerService serverApi = api.compute().servers();
    Server victimServer = serverApi.get(this.victimId);
    if (victimServer == null) {
        throw new NotFoundException(format("delete failed: server with id '%s' could not be found in region %s",
                this.victimId, getApiAccessConfig().getRegion()));
    }

    releaseFloatingIps(api, victimServer);
    ActionResponse response = serverApi.delete(this.victimId);
    if (!response.isSuccess()) {
        throw new ResponseException(
                String.format("delete failed: server %s: %s", this.victimId, response.getFault()),
                response.getCode());
    }

    awaitTermination(victimServer.getId());
    return null;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:22,代码来源:DeleteServerRequest.java


示例8: doRequest

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Override
public Server doRequest(OSClient api) throws NotFoundException, ResponseException {
    ServerService serverService = api.compute().servers();

    ServerCreateBuilder serverCreateBuilder = serverService.serverBuilder().name(this.serverName)
            .flavor(getFlavorId()).image(getImageId()).keypairName(this.keyPair).addMetadata(this.metadata);

    for (String securityGroup : this.securityGroups) {
        serverCreateBuilder.addSecurityGroup(securityGroup);
    }
    if (this.networks != null && !this.networks.isEmpty()) {
        serverCreateBuilder.networks(getNetworkIds());
    }
    if (this.encodedUserData != null) {
        serverCreateBuilder.userData(this.encodedUserData);
    }

    ServerCreate serverCreate = serverCreateBuilder.build();
    Server server = serverService.boot(serverCreate);
    // first call to boot only seem to return a stripped Server object
    // (missing fields such as status). re-fetch it before returning.
    return serverService.get(server.getId());
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:24,代码来源:CreateServerRequest.java


示例9: testWithStateIn

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Test
public void testWithStateIn() {
    Server server = server(Status.STOPPED);

    // empty set
    assertFalse(ServerPredicates.withStateIn().test(server));
    // non-empty set, missing a matching state
    assertFalse(ServerPredicates.withStateIn(Status.ACTIVE).test(server));
    assertFalse(ServerPredicates.withStateIn(Status.ACTIVE, Status.BUILD).test(server));
    // set contains matching state only
    assertTrue(ServerPredicates.withStateIn(Status.STOPPED).test(server));
    // set contains matching state and other states
    assertTrue(ServerPredicates.withStateIn(Status.ACTIVE, Status.STOPPED).test(server));

    // test with another server state
    server = server(Status.ACTIVE);
    assertFalse(ServerPredicates.withStateIn(Status.STOPPED, Status.BUILD).test(server));
    assertTrue(ServerPredicates.withStateIn(Status.ACTIVE, Status.STOPPED).test(server));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:20,代码来源:TestServerPredicates.java


示例10: convertServerWithPublicAndPrivateIpAddresses

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Test
public void convertServerWithPublicAndPrivateIpAddresses() {
    DateTime now = UtcTime.now();

    NovaAddresses addresses = new NovaAddresses();
    addresses.add("Default network", novaAddress("10.11.12.2", "fixed"));
    addresses.add("Default network", novaAddress("130.239.48.193", "floating"));
    Server server = server(Status.ACTIVE, now, addresses, "1C-1G");

    Machine machine = new ServerToMachine("RackSpace", "LON").apply(server);
    assertThat(machine.getId(), is(server.getId()));
    assertThat(machine.getMachineState(), is(MachineState.RUNNING));
    assertThat(machine.getCloudProvider(), is("RackSpace"));
    assertThat(machine.getRegion(), is("LON"));
    assertThat(machine.getMachineSize(), is("1C-1G"));
    assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus()));
    assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN));
    assertThat(machine.getRequestTime().toDate(), is(server.getCreated()));
    assertThat(machine.getPublicIps(), is(asList("130.239.48.193")));
    assertThat(machine.getPrivateIps(), is(asList("10.11.12.2")));
    assertThat(machine.getMetadata(), is(JsonUtils.toJson(server)));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:23,代码来源:TestServerToMachine.java


示例11: convertServerWithoutPublicIpAddress

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Test
public void convertServerWithoutPublicIpAddress() {
    DateTime now = UtcTime.now();

    NovaAddresses addresses = new NovaAddresses();
    addresses.add("private", novaAddress("10.11.12.2", "fixed"));
    Server server = server(Status.ACTIVE, now, addresses, "1C-1G");

    Machine machine = new ServerToMachine("CityCloud", "Kna1").apply(server);
    assertThat(machine.getId(), is(server.getId()));
    assertThat(machine.getMachineState(), is(MachineState.RUNNING));
    assertThat(machine.getRegion(), is("Kna1"));
    assertThat(machine.getCloudProvider(), is("CityCloud"));
    assertThat(machine.getMachineSize(), is("1C-1G"));
    assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus()));
    assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN));
    assertThat(machine.getRequestTime().toDate(), is(server.getCreated()));
    List<String> empty = asList();
    assertThat(machine.getPublicIps(), is(empty));
    assertThat(machine.getPrivateIps(), is(asList("10.11.12.2")));
    assertThat(machine.getMetadata(), is(JsonUtils.toJson(server)));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:23,代码来源:TestServerToMachine.java


示例12: getServer

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Override
public Server getServer(String serverId) {
	try {

		Server server = os.compute().servers().get(serverId);

		logger.info("Server retrieved successfully for ID: " + serverId);

		return server;
	}
	catch( Exception ex ) {
		ex.printStackTrace();
		// TODO: Check with the team on how to handle exceptions.
		logger.error("Failed to retrieve server for ID: " + serverId);
		return null;
	}
}
 
开发者ID:apache,项目名称:airavata,代码行数:18,代码来源:OpenstackIntfImpl.java


示例13: build

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image,
        List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
    CloudResource resource = buildableResource.get(0);
    try {
        String publicNetId = context.getStringParameter(OpenStackConstants.PUBLIC_NET_ID);
        if (publicNetId != null) {
            OSClient osClient = createOSClient(auth);
            List<CloudResource> computeResources = context.getComputeResources(privateId);
            CloudResource instance = getInstance(computeResources);
            FloatingIP unusedIp = osClient.compute().floatingIps().allocateIP(publicNetId);
            ActionResponse response = osClient.compute().floatingIps().addFloatingIP(instance.getParameter(OpenStackConstants.SERVER, Server.class),
                    unusedIp.getFloatingIpAddress());
            if (!response.isSuccess()) {
                throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(),
                        auth.getCloudContext().getId(), response.getFault());
            }
            return Collections.singletonList(createPersistedResource(resource, group.getName(), unusedIp.getId()));
        }
        return Collections.emptyList();
    } catch (OS4JException ex) {
        throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), ex);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:25,代码来源:OpenStackFloatingIPBuilder.java


示例14: discoverVmForPort

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
/**
 * @param em     Hibernate session object
 * @param region Region this entity belongs to
 * @param sg     Security Group in context
 * @param osPort Open stack port
 * @param vmPort VM port
 * @throws IOException
 */
public static void discoverVmForPort(EntityManager em, String region, SecurityGroup sg, Port osPort, VMPort vmPort)
        throws IOException, EncryptionException {

    try (Openstack4JNova nova = new Openstack4JNova(new Endpoint(sg.getVirtualizationConnector(), sg.getProjectName()))) {
        Server osVm = nova.getServer(region, osPort.getDeviceId());
        if (null == osVm) {
            OSCEntityManager.delete(em, vmPort, StaticRegistry.transactionalBroadcastUtil());
            //TODO sridhar handle stale VM delete ?
            return;

        }
        VM vm = VMEntityManager.findByOpenstackId(em, osPort.getDeviceId());
        if (vm == null) {
            vm = new VM(region, osPort.getDeviceId(), osVm.getName());
            OSCEntityManager.create(em, vm, StaticRegistry.transactionalBroadcastUtil());
        }
        vmPort.setVm(vm);
        // Update vm host if needed
        String hypervisorHostname = osVm.getHypervisorHostname();
        if (hypervisorHostname != null && !hypervisorHostname.equals(vm.getHost())) {
            vm.setHost(hypervisorHostname);
            OSCEntityManager.update(em, vm, StaticRegistry.transactionalBroadcastUtil());
        }
    }
    OSCEntityManager.update(em, vmPort, StaticRegistry.transactionalBroadcastUtil());
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:35,代码来源:OpenstackUtil.java


示例15: executeTransaction

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
@Override
public void executeTransaction(EntityManager em) throws Exception {
    this.dai = DistributedApplianceInstanceEntityMgr.findById(em, this.dai.getId());
    DeploymentSpec ds = this.dai.getDeploymentSpec();

    Endpoint endPoint = new Endpoint(ds);
    try (Openstack4JNova nova = new Openstack4JNova(endPoint)) {
        Server serverDAI = nova.getServer(ds.getRegion(), this.dai.getExternalId());
        // Check is SVA is Shut off
        if (serverDAI.getStatus().equals(Server.Status.SHUTOFF)) {
            boolean isStarted = nova.startServer(ds.getRegion(), this.dai.getExternalId());
            this.log.info("SVA found in SHUTOFF state we will try to start it ... Is SVA started successfully: " + isStarted);
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:16,代码来源:OsSvaStateCheckTask.java


示例16: findVmByPortId

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
private VmInfo findVmByPortId(Openstack4JNova nova, Openstack4JNeutron neutron, DistributedApplianceInstance dai,
                              String portId) throws IOException, VmidcBrokerValidationException {
    String region = dai.getDeploymentSpec().getRegion();
    String vmId = neutron.getVmIdByPortId(region, portId);
    if (vmId == null) {
        throw new VmidcBrokerValidationException(
                String.format("Unable to find Server attached to the port: %s", portId));
    }
    Server vm = nova.getServer(region, vmId);
    if (vm == null) {
        throw new VmidcBrokerValidationException(
                String.format("Unable to find Server with Id: %s in region: %s ", vmId, region));
    }
    return newVmInfo(vm);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:16,代码来源:QueryVmInfoService.java


示例17: findVmByMacAddress

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
private VmInfo findVmByMacAddress(Openstack4JNova nova, Openstack4JNeutron neutron, DistributedApplianceInstance dai,
                                  String macAddress) throws IOException, VmidcBrokerValidationException {
    String region = dai.getDeploymentSpec().getRegion();
    String vmId = neutron.getVmIdByMacAddress(region, macAddress);
    if (vmId == null) {
        throw new VmidcBrokerValidationException(
                String.format("Unable to find Server with mac address: %s ", macAddress));
    }
    Server server = nova.getServer(region, vmId);
    if (server == null) {
        throw new VmidcBrokerValidationException(
                String.format("Unable to find Server with Id: %s in region: %s ", vmId, region));
    }
    return newVmInfo(server);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:16,代码来源:QueryVmInfoService.java


示例18: newVmInfo

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
private VmInfo newVmInfo(Server vm) {
    VmInfo vmi = new VmInfo();
    vmi.vmName = vm.getName();
    vmi.vmId = vm.getId();
    vmi.vmUuid = vm.getId();
    // TODO: Future Maybe add comma seperated list of ip addresses
    vmi.vmIpAddress = "";
    vmi.hostName = vm.getHostId();
    vmi.hostId = vm.getHostId();
    return vmi;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:12,代码来源:QueryVmInfoService.java


示例19: listServers

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
public List<? extends Server> listServers(String region) {
    getOs().useRegion(region);
    List<? extends Server> serverList = getOs().compute().servers().list();
    if (CollectionUtils.isEmpty(serverList)) {
        log.info("No servers found in region: " + region);
    }
    return serverList;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:9,代码来源:Openstack4JNova.java


示例20: getServerByName

import org.openstack4j.model.compute.Server; //导入依赖的package包/类
public Server getServerByName(String region, String name) {
    getOs().useRegion(region);
    Map<String, String> filter = Maps.newHashMap();
    filter.put(OPENSTACK_NAME_PROPERTY, "^" + name + "$");

    List<? extends Server> servers = getOs().compute().servers().list(filter);
    return (servers.size() == 1) ? servers.get(0) : null;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:9,代码来源:Openstack4JNova.java



注:本文中的org.openstack4j.model.compute.Server类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Nullable类代码示例发布时间:2022-05-21
下一篇:
Java IMethodInterceptor类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap