def ADD_VM(url, token, name, project):

    #  create a new vm

    astakos = AstakosClient(url, token, name)

    service_type = CycladesComputeClient.service_type
    endpoint = astakos.get_endpoint_url(service_type)
    compute = CycladesComputeClient(endpoint, token)

    vm_name = name
    flavor = '260'
    image = 'eca2f4ef-b428-4096-a47d-29ddf5ed68d9'

    # server = compute.create_server(name=vm_name, flavor_id=flavor, image_id=image)

    server = compute.create_server(name=vm_name,
                                   key_name='cluster key',
                                   flavor_id=flavor,
                                   image_id=image,
                                   project_id=project)
    print(server['status'])

    with open(vm_name + '.info', "w") as f:
        for s in server:
            f.write(s)

    active = compute.wait_server_until(server['id'], 'ACTIVE')
    if active != 'ACTIVE':
        print('Waiting for server to build...')
def REMOVE_VM(url, token, server):

    astakos = AstakosClient(url, token)
    service_type = CycladesComputeClient.service_type
    endpoint = astakos.get_endpoint_url(service_type)
    compute = CycladesComputeClient(endpoint, token)

    # find server id
    s = compute.list_servers(name=server)
    for i in s:
        if i['name'] == server:
            id = i['id']
            print(id)
            compute.delete_server(id)
Beispiel #3
0
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesComputeClient

AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

#  Create a server (automatic IP)
name = "My public server"
flavor = "420"
image = "image-id-for-debian"
project = "a1234567-a890-1234-56ae-78f90bb1c2db"

server = compute.create_server(name, flavor, image, project=project)
print "Server status is {0}".server["status"]

new_status = compute.wait_server_until(server["id"], "ACTIVE")
if new_status != "ACTIVE":
    print "Waiting for server to build: time out..., server is in {0}".format(
        new_status)
else:
Beispiel #4
0
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesComputeClient

#  Initialize Astakos
AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

#  Initialize CycladesComputeClient
service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

#  Create a public server (with IP)
name = "My public server"
flavor = "420"
image = "image-id-for-debian"
IP = "123.45.67.89"
network_id_for_this_ip = 204
networks = dict(uuid=network_id_for_this_ip, fixed_ip=IP)
project = "a1234567-a890-1234-56ae-78f90bb1c2db"

public_server = compute.create_server(name,
                                      flavor,
                                      image,
                                      networks=networks,
                                      project=project)
Beispiel #5
0
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesComputeClient

#  Initialize Astakos
AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

#  Initialize CycladesComputeClient
service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

#  Get server current status
server_id = "my-server-id"
server = compute.get_server_details(server_id)
status = server["status"]

#  Shutdown server
if status == "ACTIVE":
    compute.server_reboot(server_id)
elif status == "STOPPED":
    compute.server_start(server_id)

new_status = compute.wait_sever_while(server_id, "REBOOT")
print "Server {id} is now {status}".format(id=server_id, status=new_status)
Beispiel #6
0
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import (
    CycladesBlockStorageClient, CycladesComputeClient)

#  Initialize Astakos
AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

#  Initialize CycladesComputeClient
service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

#  Servers
server_id_1, server_id_2 = "id-for-sever-1", "id-for-sever-2"

#  Initialize CycladesBlockStorageClient
service_type = CycladesBlockStorageClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
blockstorage = CycladesBlockStorageClient(endpoint, TOKEN)

#  Create new volume on server_1
size_ = 20  # in GB
name = "USB stick"
usb = blockstorage.create_volume(size_, name, server_id=server_id_1)
blockstorage.wait_volume_until(usb["id"], "in_use")
Beispiel #7
0
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import (CycladesComputeClient,
                                     CycladesNetworkClient)

AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

service_type = CycladesNetworkClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
network = CycladesNetworkClient(endpoint, TOKEN)

#  Create VPN and reserve an IP
type_ = CycladesNetworkClient.types[0]
vpn = network.create_network(type_, name="Cluster Network")
unused_ips = filter(lambda ip: not ip["port_id"], network.list_floatingips())
ip = unused_ips[0] if unused_ips else network.create_floatingip()
ip_net = ip["floating_network_id"]

#  Server data
flavor = 420
image = "image-id-for-a-debian-image"
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesComputeClient

AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

#  Data
server_id = "my-server-id"
new_flavor = "new-flavor-id-able-in-resources"
new_project = "a9f87654-3af2-1e09-8765-43a2df1098765"

#  Shutdown server
compute.shutdown_server(server_id)
compute.wait_server_until(server_id, "STOPPED")

#  Reassign and resize
compute.reassign_server(server_id, new_project)
compute.resize_server(server_id, new_flavor)

#  Start server
Beispiel #9
0
def lambda_instance_stop(auth_url, auth_token, master_id, slave_ids):
    """
    Stops the VMs of a lambda instance using kamaki. Stopping the master node will cause the lambda
    services to stop. That is why the master node must be stopped before stopping any of the slave
    nodes.
    :param auth_url: The authentication url for ~okeanos API.
    :param auth_token: The authentication token of the owner of the lambda instance.
    :param master_id: The ~okeanos id of the VM that acts as the master node.
    :param slave_ids: The ~okeanos ids of the VMs that act as the slave nodes.
    """

    # Create cyclades client.
    cyclades_compute_url = AstakosClient(auth_url, auth_token).get_endpoint_url(
        CycladesComputeClient.service_type)
    cyclades_compute_client = CycladesComputeClient(cyclades_compute_url, auth_token)

    # Stop master node.
    if cyclades_compute_client.get_server_details(master_id)["status"] != "STOPPED":
        cyclades_compute_client.shutdown_server(master_id)

    # Wait until master node has been stopped.
    cyclades_compute_client.wait_server(master_id, current_status="ACTIVE")

    # Stop all slave nodes.
    for slave_id in slave_ids:
        if cyclades_compute_client.get_server_details(slave_id)["status"] != "STOPPED":
            cyclades_compute_client.shutdown_server(slave_id)

    # Wait until all slave nodes have been stopped.
    for slave_id in slave_ids:
        cyclades_compute_client.wait_server(slave_id, current_status="ACTIVE")
Beispiel #10
0
def lambda_instance_destroy(auth_url, auth_token, master_id, slave_ids, public_ip_id,
                            private_network_id):
    """
    Destroys the specified lambda instance. The VMs of the lambda instance, along with the public
    ip and the private network used are destroyed and the status of the lambda instance gets
    changed to DESTROYED. There is no going back from this state, the entries are kept to the
    database for reference.
    :param auth_url: The authentication url for ~okeanos API.
    :param auth_token: The authentication token of the owner of the lambda instance.
    :param master_id: The ~okeanos id of the VM that acts as the master node.
    :param slave_ids: The ~okeanos ids of the VMs that act as the slave nodes.
    :param public_ip_id: The ~okeanos id of the public ip assigned to master node.
    :param private_network_id: The ~okeanos id of the private network used by the lambda instance.
    """

    # Create cyclades compute client.
    cyclades_compute_url = AstakosClient(auth_url, auth_token).get_endpoint_url(
        CycladesComputeClient.service_type)
    cyclades_compute_client = CycladesComputeClient(cyclades_compute_url, auth_token)

    # Create cyclades network client.
    cyclades_network_url = AstakosClient(auth_url, auth_token).get_endpoint_url(
        CycladesNetworkClient.service_type)
    cyclades_network_client = CycladesNetworkClient(cyclades_network_url, auth_token)

    # Get the current status of the VMs.
    master_status = cyclades_compute_client.get_server_details(master_id)["status"]
    slaves_status = []
    for slave_id in slave_ids:
        slaves_status.append(cyclades_compute_client.get_server_details(slave_id)["status"])

    # Destroy all the VMs without caring for properly stopping the lambda services.
    # Destroy master node.
    if cyclades_compute_client.get_server_details(master_id)["status"] != "DELETED":
        cyclades_compute_client.delete_server(master_id)

    # Destroy all slave nodes.
    for slave_id in slave_ids:
        if cyclades_compute_client.get_server_details(slave_id)["status"] != "DELETED":
            cyclades_compute_client.delete_server(slave_id)

    # Wait for all the VMs to be destroyed before destroyed the public ip and the
    # private network.
    cyclades_compute_client.wait_server(master_id, current_status=master_status)
    for i, slave_id in enumerate(slave_ids):
        cyclades_compute_client.wait_server(slave_id, current_status=slaves_status[i])

    # Destroy the public ip.
    cyclades_network_client.delete_floatingip(public_ip_id)

    # Destroy the private network.
    cyclades_network_client.delete_network(private_network_id)
Beispiel #11
0
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesComputeClient

AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

#  Find flavor with 2 cores, 20GB disk and 2048MB of ram
pick_flavor = lambda flavor: all(
    flavor["vcpus"] == 2,
    flavor["disk"] == 20,
    flavor["ram"] == 2048
)
all_flavors = compute.list_flavors(detail=True)
flavors = filter(pick_flavor, all_flavors)

#  Find images with debian in their name
pick_image = lambda image: "debian" in image["name"].lower()
all_images = compute.list_images(detail=True)
images = filter(pick_image, all_images)
Beispiel #12
0
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import (
    CycladesComputeClient, CycladesNetworkClient)

AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

service_type = CycladesNetworkClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
network = CycladesNetworkClient(endpoint, TOKEN)

#  Create VPN and reserve an IP
type_ = CycladesNetworkClient.types[0]
vpn = network.create_network(type_, name="Cluster Network")
unused_ips = filter(lambda ip: not ip["port_id"], network.list_floatingips())
ip = unused_ips[0] if unused_ips else network.create_floatingip()
ip_net = ip["floating_network_id"]

#  Server data
flavor = 420
image = "image-id-for-a-debian-image"
Beispiel #13
0
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesComputeClient

#  Initialize Astakos
AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

#  Initialize CycladesComputeClient
service_type = CycladesComputeClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
compute = CycladesComputeClient(endpoint, TOKEN)

#  Create a public server (with IP)
name = "My public server"
flavor = "420"
image = "image-id-for-debian"
IP = "123.45.67.89"
network_id_for_this_ip = 204
networks = dict(uuid=network_id_for_this_ip, fixed_ip=IP)
project = "a1234567-a890-1234-56ae-78f90bb1c2db"

public_server = compute.create_server(
    name, flavor, image, networks=networks, project=project)

#  Create a private server (without networking)
name = "My private server"