Search in sources :

Example 26 with PlatformLayerKey

use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.

the class ListItems method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = pathToKey(client, path);
    return client.listItemsUntyped(key);
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 27 with PlatformLayerKey

use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.

the class DirectCloudUtils method getSharedNetworkKey.

private static PlatformLayerKey getSharedNetworkKey() {
    DirectCloud cloud = OpsContext.get().getInstance(DirectCloud.class);
    DirectHost host = OpsContext.get().getInstance(DirectHost.class);
    PlatformLayerKey sharedNetwork = host.network;
    if (sharedNetwork == null) {
        sharedNetwork = cloud.network;
    }
    return sharedNetwork;
}
Also used : DirectCloud(org.platformlayer.service.cloud.direct.model.DirectCloud) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 28 with PlatformLayerKey

use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.

the class DirectCloudUtils method getPublicAddressPool4.

public OpsProvider<ResourcePool<InetSocketAddress>> getPublicAddressPool4(final int publicPort, final List<Integer> publicPortGroup) {
    OpsProvider<ResourcePool<InetSocketAddress>> pool = new OpsProvider<ResourcePool<InetSocketAddress>>() {

        @Override
        public ResourcePool<InetSocketAddress> get() throws OpsException {
            DirectHost host = OpsContext.get().getInstance(DirectHost.class);
            OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
            PlatformLayerKey sharedNetworkKey = getSharedNetworkKey();
            // We don't skip here, at the moment.
            // We may just need a comma separated list in future...
            int skipCount = 0;
            if (sharedNetworkKey == null) {
                File poolPath = getPoolPath("sockets-ipv4-public");
                File resourceDir = new File(poolPath, "all");
                File assignedBase = new File(poolPath, "assigned");
                File perPortDir = new File(assignedBase, "port" + publicPort);
                PoolBuilder<AddressModel> poolBuilder = null;
                String ipv4Public = host.ipv4Public;
                if (ipv4Public != null) {
                    poolBuilder = new NetworkPoolBuilder(ipv4Public, skipCount);
                }
                StaticFilesystemBackedPool<AddressModel> addressPool = new StaticFilesystemBackedPool<AddressModel>(AddressModel.class, poolBuilder, target, resourceDir, perPortDir);
                return new AssignPortToAddressPool(addressPool, publicPort);
            } else {
                throw new UnsupportedOperationException();
            // DirectNetwork network = platformLayer.getItem(sharedNetworkKey, DirectNetwork.class);
            //
            // for (AddressModel net : network.getNetworks()) {
            // if (Strings.isNullOrEmpty(net.cidr)) {
            // continue;
            // }
            //
            // IpRange cidr = IpRange.parse(net.cidr);
            // if (!cidr.isIpv4()) {
            // continue;
            // }
            //
            // NetworkPoolBuilder poolBuilder = new NetworkPoolBuilder(net.cidr, skipCount, net);
            // PlatformlayerBackedPool<AddressModel> addressPool = new PlatformlayerBackedPool<AddressModel>(
            // platformLayer, sharedNetworkKey, AddressModel.class, poolBuilder);
            // return new AssignPortToAddressPool(addressPool, publicPort);
            // }
            //
            // log.warn("Unable to find an IPV4 network configured on " + sharedNetworkKey);
            // return null;
            }
        }
    };
    return pool;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) StaticFilesystemBackedPool(org.platformlayer.ops.pool.StaticFilesystemBackedPool) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ResourcePool(org.platformlayer.ops.pool.ResourcePool) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) OpsTarget(org.platformlayer.ops.OpsTarget) OpsProvider(org.platformlayer.ops.OpsProvider) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) File(java.io.File)

Example 29 with PlatformLayerKey

use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.

the class DirectCloudUtils method getAddressPool6.

public OpsProvider<ResourcePool<AddressModel>> getAddressPool6() {
    OpsProvider<PoolBuilder<AddressModel>> poolBuilder = new OpsProvider<PoolBuilder<AddressModel>>() {

        @Override
        public PoolBuilder<AddressModel> get() throws OpsException {
            DirectHost host = OpsContext.get().getInstance(DirectHost.class);
            PlatformLayerKey sharedNetworkKey = getSharedNetworkKey();
            // Skip the first entries in the CIDR as it's probably not valid
            // 0: Network identifier
            // 1: Gateway
            // 2: Host
            int skipCount = 3;
            if (sharedNetworkKey != null) {
                DirectNetwork network = platformLayer.getItem(sharedNetworkKey, DirectNetwork.class);
                for (AddressModel net : network.getNetworks()) {
                    if (Strings.isNullOrEmpty(net.cidr)) {
                        continue;
                    }
                    IpRange cidr = IpRange.parse(net.cidr);
                    if (!cidr.isIpv6()) {
                        continue;
                    }
                    return new NetworkPoolBuilder(net.cidr, skipCount, net);
                }
                log.warn("Unable to find an IPV6 network configured on " + sharedNetworkKey);
                return null;
            } else {
                String privateCidr = host.ipv6;
                if (privateCidr != null) {
                    return new NetworkPoolBuilder(privateCidr, skipCount, null);
                }
                return null;
            }
        }
    };
    return getNetworkPoolProvider(AddressModel.class, "addresses-ipv6", poolBuilder);
}
Also used : IpRange(org.platformlayer.ops.networks.IpRange) DirectNetwork(org.platformlayer.service.cloud.direct.model.DirectNetwork) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) OpsProvider(org.platformlayer.ops.OpsProvider) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) PoolBuilder(org.platformlayer.ops.pool.PoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 30 with PlatformLayerKey

use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.

the class DirectHostController method addChildren.

@Override
protected void addChildren() throws OpsException {
    // if (Strings.isEmpty(model.dnsName)) {
    // throw new IllegalArgumentException("dnsName must be specified");
    // }
    // DirectCloud cloud = platformLayer.getItem(model.cloud, DirectCloud.class);
    // We'd like to auto-gen the disk image, but there's no way to auto-specify the OS at the moment
    // String dnsName = "direct-host-" + model.getId();
    // InstanceBuilder instance = InstanceBuilder.build(dnsName, DiskImageRecipeBuilder.buildDiskImageRecipe(this));
    // instance.cloud = cloud.machineSource;
    // instance.addTagToManaged = true;
    // addChild(instance);
    DirectTarget host;
    {
        host = addChild(DirectTarget.class);
        host.address = NetworkPoint.forPublicHostname(model.host);
        host.sshKey = service.getSshKey();
    }
    // TODO: It isn't quite right to call this InstanceBootstrap any more!
    host.addChild(InstanceBootstrap.class);
    host.addChild(DnsResolver.class);
    // Time synchronization is pretty important
    host.addChild(PackageDependency.build("ntp"));
    // TODO: Do we want to differentiate between an LXC host and a KVM host?
    host.addChild(PackageDependency.build("lxc"));
    host.addChild(ManagedDirectory.build(LXC_INSTANCE_DIR, "0755"));
    host.addChild(ManagedDirectory.build(KVM_INSTANCE_DIR, "0755"));
    // Useful for moving images around
    host.addChild(PackageDependency.build("bzip2"));
    PeerToPeerCopy peerToPeerCopy = Injection.getInstance(PeerToPeerCopy.class);
    peerToPeerCopy.addChildren(this);
    {
        PlatformLayerKey owner = model.getKey();
        serviceManager.addServiceInstall(owner, host);
    }
    host.addChild(KvmHost.class);
    host.addChild(MountCgroups.class);
    host.addChild(PackageDependency.build("bridge-utils"));
    host.addChild(NetworkBridge.class);
    OpsItemBase.setAllChildrenLazyDelete(host, true);
}
Also used : PeerToPeerCopy(org.platformlayer.ops.images.direct.PeerToPeerCopy) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Aggregations

PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)86 PlatformLayerClient (org.platformlayer.PlatformLayerClient)21 OpsException (org.platformlayer.ops.OpsException)16 ItemBase (org.platformlayer.core.model.ItemBase)14 ManagedItemId (org.platformlayer.ids.ManagedItemId)13 UntypedItem (org.platformlayer.common.UntypedItem)10 ProjectId (org.platformlayer.ids.ProjectId)10 Tag (org.platformlayer.core.model.Tag)8 RepositoryException (org.platformlayer.RepositoryException)7 ServiceType (org.platformlayer.ids.ServiceType)7 JobData (org.platformlayer.jobs.model.JobData)7 InstanceBase (org.platformlayer.core.model.InstanceBase)6 ItemType (org.platformlayer.ids.ItemType)6 OpsTarget (org.platformlayer.ops.OpsTarget)6 JaxbHelper (org.platformlayer.xml.JaxbHelper)6 Handler (org.platformlayer.ops.Handler)5 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)4 UntypedItemXml (org.platformlayer.UntypedItemXml)4 FederationKey (org.platformlayer.ids.FederationKey)4 Machine (org.platformlayer.ops.Machine)4