コード例 #1
0
 def run(self):
     xx = rimuapi.Api()
     # minions first
     master = xx.orders(
         '', {
             'server_type':
             'VPS',
             'meta_search':
             'com.rimuhosting.kclusterid:' + self.cluster +
             ' com.rimuhosting.kismaster:Y'
         })
     if not master or len(master) == 0:
         raise Exception("Could not find a master VM for that cluster.")
     minions = xx.orders(
         'N', {
             'server_type':
             'VPS',
             'meta_search':
             'com.rimuhosting.kclusterid:' + self.cluster +
             ' com.rimuhosting.kisminion:Y'
         })
     output = []
     for order in minions:
         #print("deleting " + str(order["order_oid"]))
         resp = xx.delete(order_oid=order["order_oid"])
         output.append(resp)
     # then master
     for order in master:
         #print("deleting " + str(order["order_oid"]))
         resp = xx.delete(order_oid=order["order_oid"])
         output.append(resp)
     print(pformat(output))
コード例 #2
0
ファイル: lscluster.py プロジェクト: sbutsky/rimuhosting-k8s
 def clusterList(self):
     xx = rimuapi.Api()
     # has a cluster id, is active, is master
     existing = xx.orders('N', {'server_type': 'VPS','meta_search': 'com.rimuhosting.kclusterid: com.rimuhosting.kismaster:Y'})
     output = {}
     output["cluster_masters"] = []
     for order in existing:
         output["cluster_masters"].append(self._getSimplifiedOrder(order))
     print(pformat(output))
コード例 #3
0
    def run(self):
        xx = rimuapi.Api()
        server_json = {}
        if args.server_json:
            server_json = json.load(open(args.server_json))
        self.debug("server json = " + str(server_json))
        if not hasattr(server_json, "instantiation_options"):
            server_json["instantiation_options"] = dict()
        if not hasattr(server_json, "vps_parameters"):
            server_json["vps_parameters"] = dict()

        if self.cloud_config:
            server_json["instantiation_options"]["cloud_config_data"] = open(
                args.cloud_config).read()
        if self.dc_location:
            server_json["dc_location"] = self.dc_location
        if self.domain_name:
            server_json["instantiation_options"][
                "domain_name"] = self.domain_name
            self.debug("domain_name = " + self.domain_name)
        if self.memory_mb:
            server_json["vps_parameters"]["memory_mb"] = self.memory_mb
        if self.disk_space_gb:
            server_json["vps_parameters"][
                "disk_space_mb"] = self.disk_space_gb * 1024
        if self.distro:
            server_json["instantiation_options"]["distro"] = self.distro
        #print("server_json=",server_json)

        # see if the cluster id is in the server json, else use the command line arg value
        # replace the magic $kubernetes_domain_name with the server domain name
        if args.reinstall_order_oid:
            existing = xx.orders('N', {
                'server_type': 'VPS',
                'order_oids': args.reinstall_order_oid
            })
            if len(existing) == 0:
                raise Exception(
                    "Could not find that server for a reinstall.  Just create a new VM?"
                )
            if len(existing) > 1:
                raise Exception("Found multiple servers with this id.")

            self.debug("Running a reinstall on " +
                       str(existing[0]["order_oid"]) + " " + str(existing[0]))

            vm = xx.reinstall(int(existing[0]["order_oid"]), server_json)
            self.debug("reinstalled master server")
            print(pformat(vm))
            return

        self.debug("creating VM...")
        print("server-json = ", pformat(server_json))
        vm = xx.create(server_json)
        self.debug("created VM: ")
        print(pformat(vm))
コード例 #4
0
ファイル: lsvms.py プロジェクト: abdallah/RimuHostingAPI
 def serverList(self):
     xx = rimuapi.Api()
     # has a cluster id, is active, is master
     existing = xx.orders('N', {'server_type': 'VPS'})
     output = {}
     output["servers"]=[]
     for order in existing:
         output["servers"].append(self._getSimplifiedOrder(order))
     
     print(pformat(output))
コード例 #5
0
ファイル: lscluster.py プロジェクト: sbutsky/rimuhosting-k8s
 def clusterDetail(self):
     xx = rimuapi.Api()
     # has a specific cluster id, is active, is master
     existing = xx.orders('', {'server_type': 'VPS','meta_search': 'com.rimuhosting.kclusterid:'+self.cluster+' com.rimuhosting.kismaster:Y'})
     output = {}
     for order in existing:
         output["cluster_master"] = self._getSimplifiedOrder(order)
               
     existing = xx.orders('N', {'server_type': 'VPS','meta_search': 'com.rimuhosting.kclusterid:'+self.cluster+' com.rimuhosting.kisminion:Y'})
     output["minions"]=[]
     for order in existing:
         output["minions"].append(self._getSimplifiedOrder(order))
     
     print(pformat(output))
コード例 #6
0
    def getExports(self):
        xx = rimuapi.Api()
        # has a specific cluster id, is active, is master
        master = xx.orders(
            'N', {
                'server_type':
                'VPS',
                'meta_search':
                'com.rimuhosting.kclusterid:' + self.cluster +
                ' com.rimuhosting.kismaster:Y'
            })
        if not master or len(master) == 0:
            raise Exception("No such cluster located.")
        output = []
        for order in master:
            output.append("export KUBERNETES_MASTER_IPV4=" +
                          order["allocated_ips"]["primary_ip"])
            output.append("export KUBERNETES_MASTER_ORDER_OID=" +
                          str(order["order_oid"]))
            output.append("export SERVER_ARG='--server=http://" +
                          order["allocated_ips"]["primary_ip"] + ":8080'")
            output.append("alias rkubectl='kubectl $SERVER_ARG'")
            output.append(
                "alias rkubectlgetall='rkubectl get pods,services,replicationcontrollers,nodes,events,componentstatuses,limitranges,persistentvolumes,persistentvolumeclaims,resourcequotas,namespaces,endpoints,serviceaccounts,secrets  --all-namespaces -o=wide'"
            )
        minion_ips = ""
        minion_order_oids = ""
        minions = xx.orders(
            'N', {
                'server_type':
                'VPS',
                'meta_search':
                'com.rimuhosting.kclusterid:' + self.cluster +
                ' com.rimuhosting.kisminion:Y'
            })
        for order in minions:
            minion_ips = minion_ips + " " + order["allocated_ips"]["primary_ip"]
            minion_order_oids = minion_order_oids + " " + str(
                order["order_oid"])
        output.append("unset KUBERNETES_MINION_IPV4S")
        output.append("declare -a KUBERNETES_MINION_IPV4S")
        output.append("export KUBERNETES_MINION_IPV4S=(" + minion_ips + " )")
        output.append("export KUBERNETES_MINION_ORDER_OIDS=(" +
                      minion_order_oids + " )")

        return output
コード例 #7
0
import argparse
import os
import json, sys
import urllib.request
from pprint import pprint
from pprint import pformat
import rimuapi


class Args(object):
    def __init__(self):
        parser = argparse.ArgumentParser()
        parser.parse_args(namespace=self)


if __name__ == '__main__':
    args = Args()
    xx = rimuapi.Api()
    resp = xx.data_centers()
    print(pformat(resp))
コード例 #8
0
ファイル: mkminion.py プロジェクト: sbutsky/rimuhosting-k8s
    def run(self):
        xx = rimuapi.Api()
        server_json = json.load(open(self.server_json))
        debug("server json = " + str(server_json))
        if not hasattr(server_json, "instantiation_options"):
            server_json["instantiation_options"] = dict()
        # if not hasattr(server_json["instantiation_options"], "distro"):
        # required to be a coreos distro
        server_json["instantiation_options"]["distro"] = "coreos.64"
        if not hasattr(server_json["instantiation_options"], "domain_name"):
            server_json["instantiation_options"][
                "domain_name"] = "coreosminion.localhost"
        if not hasattr(server_json["instantiation_options"],
                       "cloud_config_data"):
            server_json["instantiation_options"]["cloud_config_data"] = open(
                self.cloud_config).read()
        if not hasattr(server_json, "meta_data"):
            server_json["meta_data"] = list()
        if not hasattr(server_json, "file_injection_data"):
            server_json["file_injection_data"] = list()
        if self.dc_location:
            server_json["dc_location"] = self.dc_location
        # print("server_json=",server_json)

        # see if the cluster id is in the server json, else use the command line arg value
        klusterids = objectpath.Tree(server_json).execute(
            "$.meta_data[@.key_name is 'com.rimuhosting.kclusterid'].value")
        if not klusterids is None and len(list(klusterids)) > 0:
            raise Exception(
                "Provide the cluster id as a command line argument.")
        server_json["meta_data"].append({
            'key_name': 'com.rimuhosting.kclusterid',
            'value': self.cluster
        })
        server_json["meta_data"].append({
            'key_name': 'com.rimuhosting.kisminion',
            'value': 'Y'
        })

        existing = xx.orders(
            'N', {
                'server_type':
                'VPS',
                'meta_search':
                'com.rimuhosting.kclusterid:' + self.cluster +
                ' com.rimuhosting.kismaster:Y'
            })
        if len(existing) == 0:
            raise Exception(
                "Could not find that cluster master.  Create the master first?"
            )
        if len(existing) > 1:
            raise Exception(
                "Found multiple cluster masters with this id.  Unexpected.")
        ip = objectpath.Tree(existing).execute("$.allocated_ips.primary_ip")
        if ip is None:
            raise Exception("Could not determine the master node IP.")
        ip = list(ip)[0]

        # replace the magic $kubernetes_master_ipv4 string with the master ip
        server_json["instantiation_options"][
            "cloud_config_data"] = server_json["instantiation_options"][
                "cloud_config_data"].replace("$kubernetes_master_ipv4", ip, 99)
        server_json["instantiation_options"][
            "cloud_config_data"] = server_json["instantiation_options"][
                "cloud_config_data"].replace("<master-private-ip>", ip, 99)
        if self.reinstall_order_oid:
            reinstallminion = xx.orders(
                'N', {
                    'server_type':
                    'VPS',
                    'order_oids':
                    self.reinstall_order_oid,
                    'meta_search':
                    'com.rimuhosting.kclusterid:' + self.cluster +
                    ' com.rimuhosting.kisminion:Y'
                })
            if len(reinstallminion) == 0:
                raise Exception("Requested minion not found")
            if server_json["instantiation_options"][
                    "domain_name"] == "coreosminion.localhost":
                server_json["instantiation_options"][
                    "domain_name"] = reinstallminion[0]["domain_name"]
            if self.domain_name:
                server_json["instantiation_options"][
                    "domain_name"] = self.domain_name
            # replace the magic $kubernetes_domain_name with the server domain name
            server_json["instantiation_options"][
                "cloud_config_data"] = server_json["instantiation_options"][
                    "cloud_config_data"].replace(
                        "$kubernetes_domain_name",
                        server_json["instantiation_options"]["domain_name"],
                        99)
            vm = xx.reinstall(int(reinstallminion[0]["order_oid"]),
                              server_json)
        else:
            #print("cloud config = " + server_json["instantiation_options"]["cloud_config_data"])
            if self.domain_name:
                server_json["instantiation_options"][
                    "domain_name"] = self.domain_name
            elif server_json["instantiation_options"][
                    "domain_name"] == "coreosminion.localhost":
                minions = xx.orders(
                    None, {
                        'server_type':
                        'VPS',
                        'meta_search':
                        'com.rimuhosting.kclusterid:' + self.cluster +
                        ' com.rimuhosting.kisminion:Y'
                    })
                server_json["instantiation_options"][
                    "domain_name"] = "coreosminion-" + str(len(minions) +
                                                           1) + ".localhost"
            # replace the magic $kubernetes_domain_name with the server domain name
            server_json["instantiation_options"][
                "cloud_config_data"] = server_json["instantiation_options"][
                    "cloud_config_data"].replace(
                        "$kubernetes_domain_name",
                        server_json["instantiation_options"]["domain_name"],
                        99)
            vm = xx.create(server_json)
        debug("created minion server")
        print(pformat(vm))
コード例 #9
0
ファイル: mkmaster.py プロジェクト: sbutsky/rimuhosting-k8s
    def run(self):
        xx = rimuapi.Api()
        server_json = json.load(open(args.server_json))
        self.debug("server json = " + str(server_json))
        if not hasattr(server_json, "instantiation_options"):
            server_json["instantiation_options"] = dict()
        #if not hasattr(server_json["instantiation_options"], "distro"):
        # required to be a coreos distro
        server_json["instantiation_options"]["distro"] = "coreos.64"
        if not hasattr(server_json["instantiation_options"], "domain_name"):
            server_json["instantiation_options"][
                "domain_name"] = "coreosmaster.localhost"
        if not hasattr(server_json["instantiation_options"],
                       "cloud_config_data"):
            server_json["instantiation_options"]["cloud_config_data"] = open(
                args.cloud_config).read()
        if not hasattr(server_json, "meta_data"):
            server_json["meta_data"] = list()
        if self.dc_location:
            server_json["dc_location"] = self.dc_location
        #print("server_json=",server_json)

        # see if the cluster id is in the server json, else use the command line arg value
        klusterids = objectpath.Tree(server_json).execute(
            "$.meta_data[@.key_name is 'com.rimuhosting.kclusterid'].value")
        if not klusterids is None and len(list(klusterids)) > 0:
            raise Exception(
                "Provide the cluster id as a command line argument.")
        server_json["meta_data"].append({
            'key_name': 'com.rimuhosting.kclusterid',
            'value': args.cluster
        })
        server_json["meta_data"].append({
            'key_name': 'com.rimuhosting.kismaster',
            'value': 'Y'
        })
        # replace the magic $kubernetes_domain_name with the server domain name
        server_json["instantiation_options"][
            "cloud_config_data"] = server_json["instantiation_options"][
                "cloud_config_data"].replace(
                    "$kubernetes_domain_name",
                    server_json["instantiation_options"]["domain_name"], 99)

        existing = xx.orders(
            'N', {
                'server_type':
                'VPS',
                'meta_search':
                'com.rimuhosting.kclusterid:' + args.cluster +
                ' com.rimuhosting.kismaster:Y'
            })
        if args.isreinstall:
            if len(existing) == 0:
                raise Exception(
                    "Could not find that cluster master for a reinstall.  Just create the master?"
                )
            if len(existing) > 1:
                raise Exception("Found multiple cluster masters with this id.")

            self.debug("Running a reinstall on " +
                       str(existing[0]["order_oid"]) + " " + str(existing[0]) +
                       " ETA 5 minutes")

            master = xx.reinstall(int(existing[0]["order_oid"]), server_json)
            self.debug("reinstalled master server")
            print(pformat(master))
            return

        if existing:
            raise Exception(
                "That cluster already exists.  Delete it, or create a new one, or reinstall it (with the --reinstall option).  Use rhkclusterlist.py to list the existing clusters."
            )
        self.debug("creating master server (ETA 5 minutes)...")
        master = xx.create(server_json)
        self.debug("created master server: ")
        print(pformat(master))