Example #1
0
    def get_ip_address(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _private_hostname = '{0}'.format(
                obj_attr_list["instance_obj"].private_dns_name)
            _private_ip_address = '{0}'.format(
                obj_attr_list["instance_obj"].private_ip_address)
            _public_hostname = '{0}'.format(
                obj_attr_list["instance_obj"].public_dns_name)
            _public_hostname, _public_ip_address = hostname2ip(
                _public_hostname)
            if obj_attr_list["run_netname"] == "private":
                obj_attr_list["cloud_hostname"] = _private_hostname
                obj_attr_list["cloud_ip"] = _private_ip_address
            else:
                obj_attr_list["cloud_hostname"] = _public_hostname
                obj_attr_list["cloud_ip"] = _public_ip_address

            if obj_attr_list["prov_netname"] == "private":
                obj_attr_list["prov_cloud_ip"] = _private_ip_address
            else:
                obj_attr_list["prov_cloud_ip"] = _public_ip_address

            return True
        except:
            return False
Example #2
0
    def connect(self, access, credentials, vmc_name, extra_parms = {}, diag = False, generate_rc = False) :
        '''
        TBD
        '''        
        try :
            _status = 100
            _endpoint_ip = "NA"            
            _fmsg = "An error has occurred, but no error message was captured"
                        
            self.ssl_key = extra_parms["ssl_key"]
            self.ssl_cert = extra_parms["ssl_cert"]

            for _endpoint in access.split(',') :
                _endpoint_name, _endpoint_ip = hostname2ip(_endpoint.split('//')[1].split(':')[0], True)

                if _endpoint_ip not in self.lxdconn :
                    self.lxdconn[_endpoint_ip] = Client(endpoint = _endpoint, cert = (self.ssl_cert, self.ssl_key), verify = False)
                    self.lxdconn[_endpoint_ip].authenticate(credentials)
                    if not self.lxdconn[_endpoint_ip].trusted :
                        _fmsg = "Unable to authenticate"
                        _status = 101

            _status -= 100

        except LXDError.ClientConnectionFailed, obj:
            _status = 18127
            _fmsg = str(obj.message)
Example #3
0
 def vm_placement(self, obj_attr_list) :
     '''
     TBD
     '''        
     obj_attr_list["host_name"], obj_attr_list["host_cloud_ip"] = hostname2ip(choice(self.lxdconn.keys()), True)
     
     return True
Example #4
0
 def get_ip_from_hostname(self, obj_attr_list):
     try:
         obj_attr_list["cloud_hostname"], obj_attr_list[
             "cloud_ip"] = hostname2ip(obj_attr_list["cloud_hostname"])
     except:
         obj_attr_list["cloud_ip"] = "undefined_" + str(
             obj_attr_list["counter"])
Example #5
0
    def get_ip_address(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _private_hostname = '{0}'.format(obj_attr_list["instance_obj"].private_dns_name)
            _private_ip_address = '{0}'.format(obj_attr_list["instance_obj"].private_ip_address)
            _public_hostname = '{0}'.format(obj_attr_list["instance_obj"].public_dns_name)
            _public_hostname, _public_ip_address = hostname2ip(_public_hostname)
            if obj_attr_list["run_netname"] == "private" :
                obj_attr_list["cloud_hostname"] = _private_hostname
                obj_attr_list["run_cloud_ip"] = _private_ip_address
            else :
                obj_attr_list["cloud_hostname"] = _public_hostname
                obj_attr_list["run_cloud_ip"] = _public_ip_address

            if obj_attr_list["prov_netname"] == "private" :
                obj_attr_list["prov_cloud_ip"] = _private_ip_address
            else :
                obj_attr_list["prov_cloud_ip"]  = _public_ip_address

            # NOTE: "cloud_ip" is always equal to "run_cloud_ip"
            obj_attr_list["cloud_ip"] = obj_attr_list["run_cloud_ip"]
            
            return True
        except :
            return False
Example #6
0
    def vmcregister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = \
            _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            self.connect(obj_attr_list["access"], \
                         obj_attr_list["credentials"], \
                         obj_attr_list["name"], obj_attr_list)

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list[
                    "cleanup_on_attach"] == "True":
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            obj_attr_list["cloud_hostname"], obj_attr_list[
                "cloud_ip"] = hostname2ip(obj_attr_list["name"], False)

            _fmsg = "VMC " + obj_attr_list["uuid"] + " could not be registered "
            _fmsg += " on " + self.get_description(
            ) + " \"" + obj_attr_list["cloud_name"] + "\"."

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid(
                obj_attr_list["name"])

            obj_attr_list["arrival"] = int(time())

            if obj_attr_list["discover_hosts"].lower() == "true":
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else:
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

            _time_mark_prc = int(time())
            obj_attr_list["mgt_003_provisioning_request_completed"] = \
            _time_mark_prc - _time_mark_prs

            _status = 0

        except CldOpsException as obj:
            _status = obj.status
            _fmsg = str(obj.msg)

        except Exception as e:
            _status = 23
            _fmsg = str(e)

        finally:
            _status, _msg = self.common_messages("VMC", obj_attr_list,
                                                 "registered", _status, _fmsg)
            return _status, _msg
Example #7
0
    def vm_placement(self, obj_attr_list):
        '''
        TBD
        '''
        obj_attr_list["host_name"], obj_attr_list[
            "host_cloud_ip"] = hostname2ip(choice(self.lxdconn.keys()), True)

        return True
Example #8
0
    def vmcregister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list[
                "mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                    obj_attr_list["mgt_001_provisioning_request_originated"])

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list[
                    "cleanup_on_attach"] == "True":
                _msg = "Removing all VMs previously created on VMC \""
                _msg += obj_attr_list[
                    "name"] + "\" (only VMs names starting with"
                _msg += " \"" + "cb-" + obj_attr_list[
                    "username"] + '-' + obj_attr_list["cloud_name"]
                _msg += "\")....."
                cbdebug(_msg, True)
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            if not _status:
                if type(self.plmconn) is type(False):
                    self.connect(obj_attr_list["access"], \
                                 obj_attr_list["credentials"], \
                                 obj_attr_list["name"])

                _status, _msg, _info = self.plmconn.group_register(
                    obj_attr_list["name"])
                _network_address = _info["computenodes"].split(',')[0]
                obj_attr_list["cloud_hostname"], obj_attr_list[
                    "cloud_ip"] = hostname2ip(_network_address)

                obj_attr_list["arrival"] = int(time())

                if obj_attr_list["discover_hosts"].lower() == "true":
                    _msg = "Discovering hosts on VMC \"" + obj_attr_list[
                        "name"] + "\"....."
                    cbdebug(_msg, True)
                    _status, _fmsg = self.discover_hosts(
                        obj_attr_list, _time_mark_prs)
                else:
                    obj_attr_list["hosts"] = ''
                    obj_attr_list["host_list"] = {}
                    obj_attr_list["host_count"] = "NA"

                _time_mark_prc = int(time())
                obj_attr_list[
                    "mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
Example #9
0
    def vmcregister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list[
                "mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                    obj_attr_list["mgt_001_provisioning_request_originated"])

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list[
                    "cleanup_on_attach"] == "True":
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            if not _status:
                _x, _y, _hostname = self.connect(obj_attr_list["access"], \
                                                 obj_attr_list["credentials"], \
                                                 obj_attr_list["name"])

                obj_attr_list["cloud_hostname"] = _hostname.replace(
                    "https://", '')

                _x, obj_attr_list["cloud_ip"] = hostname2ip(
                    obj_attr_list["cloud_hostname"])

                obj_attr_list["arrival"] = int(time())

            if str(obj_attr_list["discover_hosts"]).lower() == "true":
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else:
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

            _time_mark_prc = int(time())

            obj_attr_list[
                "mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

            _status = 0

        except CldOpsException as obj:
            _status = obj.status
            _fmsg = str(obj.msg)

        except Exception as e:
            _status = 23
            _fmsg = str(e)

        finally:
            _status, _msg = self.common_messages("VMC", obj_attr_list,
                                                 "registered", _status, _fmsg)
            return _status, _msg
Example #10
0
    def vmcregister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list[
                "mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                    obj_attr_list["mgt_001_provisioning_request_originated"])

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list[
                    "cleanup_on_attach"] == "True":
                _msg = "Removing all VMs previously created on VMC \""
                _msg += obj_attr_list[
                    "name"] + "\" (only VMs names starting with"
                _msg += " \"" + "cb-" + obj_attr_list[
                    "username"] + '-' + obj_attr_list["cloud_name"]
                _msg += "\")....."
                cbdebug(_msg, True)
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            if not _status:
                if type(self.plmconn) is type(False):
                    self.connect(obj_attr_list["access"], \
                                 obj_attr_list["credentials"], \
                                 obj_attr_list["name"])

                _status, _msg, _info = self.plmconn.group_register(
                    obj_attr_list["name"])
                _network_address = _info["computenodes"].split(',')[0]
                obj_attr_list["cloud_hostname"], obj_attr_list[
                    "cloud_ip"] = hostname2ip(_network_address)
                obj_attr_list["arrival"] = int(time())

                if obj_attr_list["discover_hosts"].lower() == "true":
                    _msg = "Discovering hosts on VMC \"" + obj_attr_list[
                        "name"] + "\"....."
                    cbdebug(_msg, True)
                    _status, _fmsg = self.discover_hosts(
                        obj_attr_list, _time_mark_prs)
                else:
                    obj_attr_list["hosts"] = ''
                    obj_attr_list["host_list"] = {}
                    obj_attr_list["host_count"] = "NA"

                _time_mark_prc = int(time())
                obj_attr_list[
                    "mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
Example #11
0
    def is_vm_running(self, obj_attr_list):
        '''
        TBD
        '''
        try :

            _instance = self.get_instances(obj_attr_list, "pod", obj_attr_list["cloud_vm_name"])

            _instance_status = False
            if _instance :
                if "status" in _instance.obj :
                    if "containerStatuses" in _instance.obj["status"] :
                        if "state" in _instance.obj["status"]["containerStatuses"][0] : 
                            _instance_status = _instance.obj["status"]["containerStatuses"][0]["state"].keys()[0]
            
            if str(_instance_status) == "running" :
                self.instance_info = _instance.obj
                obj_attr_list["cloud_vm_exact_match_name"] = _instance.name
                obj_attr_list["cloud_vm_name"] = _instance.name
                obj_attr_list["cloud_hostname"] = _instance.name
                
                if "hostIP" in self.instance_info["status"] :
                    _host_ip = self.instance_info["status"]["hostIP"]
                    obj_attr_list["host_name"], obj_attr_list["host_cloud_ip"] = hostname2ip(_host_ip, True)     

                if obj_attr_list["abstraction"] == "replicaset" or obj_attr_list["abstraction"] == "deployment" :
                    if "cloud_rs_exact_match_name" not in obj_attr_list :
                        _x_instance = self.get_instances(obj_attr_list, "replicaset", obj_attr_list["cloud_rs_name"])
                        if _x_instance :
                            obj_attr_list["cloud_rs_exact_match_name"] = _x_instance.name
                            obj_attr_list["cloud_rs_name"] = _x_instance.name

                            if "metadata" in _x_instance.obj :
                                if "uid" in _x_instance.obj["metadata"] :                        
                                    obj_attr_list["cloud_rs_uuid"] = _x_instance.obj["metadata"]["uid"]
                                                 
                if obj_attr_list["abstraction"] == "deployment" :
                    if "cloud_d_exact_match_name" not in obj_attr_list :
                        _x_instance = self.get_instances(obj_attr_list, "deployment", obj_attr_list["cloud_d_name"])
                        if _x_instance :                        
                            obj_attr_list["cloud_d_exact_match_name"] = _x_instance.name
                            obj_attr_list["cloud_d_name"] = _x_instance.name

                            if "metadata" in _x_instance.obj :
                                if "uid" in _x_instance.obj["metadata"] :           
                                    obj_attr_list["cloud_d_uuid"] = _x_instance.obj["metadata"]["uid"]
                            
                return True
            else :
                return False
        
        except Exception, e :
            _status = 23
            _fmsg = str(e)
            raise CldOpsException(_fmsg, _status)
Example #12
0
    def discover_hosts(self, obj_attr_list, start) :
        '''
        TBD
        '''
        _host_uuid = obj_attr_list["cloud_vm_uuid"]

        obj_attr_list["host_list"] = {}
        obj_attr_list["hosts"] = ''

        for _endpoint in self.lxdconn :
            _host_info = self.lxdconn[_endpoint].host_info
                        
            _host_uuid = self.generate_random_uuid(_endpoint)

            obj_attr_list["hosts"] += _host_uuid + ','            
            obj_attr_list["host_list"][_host_uuid] = {}
            obj_attr_list["host_list"][_host_uuid]["pool"] = obj_attr_list["pool"].upper()
            obj_attr_list["host_list"][_host_uuid]["username"] = obj_attr_list["username"]
            obj_attr_list["host_list"][_host_uuid]["notification"] = "False"

            obj_attr_list["host_list"][_host_uuid]["cloud_hostname"], \
            obj_attr_list["host_list"][_host_uuid]["cloud_ip"] = hostname2ip(_endpoint, True)

            obj_attr_list["host_list"][_host_uuid]["name"] = "host_"  + obj_attr_list["host_list"][_host_uuid]["cloud_hostname"]
            obj_attr_list["host_list"][_host_uuid]["vmc_name"] = obj_attr_list["name"]
            obj_attr_list["host_list"][_host_uuid]["vmc"] = obj_attr_list["uuid"]
            obj_attr_list["host_list"][_host_uuid]["cloud_vm_uuid"] = _host_uuid
            obj_attr_list["host_list"][_host_uuid]["uuid"] = _host_uuid
            obj_attr_list["host_list"][_host_uuid]["model"] = obj_attr_list["model"]
            obj_attr_list["host_list"][_host_uuid]["function"] = "hypervisor"
            obj_attr_list["host_list"][_host_uuid]["cores"] = "NA"
            obj_attr_list["host_list"][_host_uuid]["memory"] = "NA"
            obj_attr_list["host_list"][_host_uuid]["cloud_ip"] = _endpoint             
            obj_attr_list["host_list"][_host_uuid]["arrival"] = int(time())
            obj_attr_list["host_list"][_host_uuid]["simulated"] = False
            obj_attr_list["host_list"][_host_uuid]["identity"] = obj_attr_list["identity"]

            obj_attr_list["host_list"][_host_uuid]["hypervisor_type"] = "lxd"
                                                
            if "login" in obj_attr_list :
                obj_attr_list["host_list"][_host_uuid]["login"] = obj_attr_list["login"]
            else :
                obj_attr_list["host_list"][_host_uuid]["login"] = "******"
                
            obj_attr_list["host_list"][_host_uuid]["counter"] = obj_attr_list["counter"]
            obj_attr_list["host_list"][_host_uuid]["mgt_001_provisioning_request_originated"] = obj_attr_list["mgt_001_provisioning_request_originated"]
            obj_attr_list["host_list"][_host_uuid]["mgt_002_provisioning_request_sent"] = obj_attr_list["mgt_002_provisioning_request_sent"]
            _time_mark_prc = int(time())
            obj_attr_list["host_list"][_host_uuid]["mgt_003_provisioning_request_completed"] = _time_mark_prc - start
                
        obj_attr_list["hosts"] = obj_attr_list["hosts"][:-1]

        self.additional_host_discovery(obj_attr_list)

        return True
Example #13
0
    def discover_hosts(self, obj_attr_list, start) :
        '''
        TBD
        '''
        _host_uuid = obj_attr_list["cloud_vm_uuid"]

        obj_attr_list["host_list"] = {}
        obj_attr_list["hosts"] = ''

        for _host in pykube.Node.objects(self.kubeconn) :

            _host_info = _host.metadata
    
            _host_uuid = self.generate_random_uuid(_host_info["uid"])
    
            obj_attr_list["hosts"] += _host_uuid + ','            
            obj_attr_list["host_list"][_host_uuid] = {}
            obj_attr_list["host_list"][_host_uuid]["pool"] = obj_attr_list["pool"].upper()
            obj_attr_list["host_list"][_host_uuid]["username"] = obj_attr_list["username"]
            obj_attr_list["host_list"][_host_uuid]["notification"] = "False"
            
            obj_attr_list["host_list"][_host_uuid]["cloud_hostname"], \
            obj_attr_list["host_list"][_host_uuid]["cloud_ip"] = hostname2ip(_host_info["name"], True)
                
            obj_attr_list["host_list"][_host_uuid]["name"] = "host_"  + obj_attr_list["host_list"][_host_uuid]["cloud_hostname"]
            obj_attr_list["host_list"][_host_uuid]["vmc_name"] = obj_attr_list["name"]
            obj_attr_list["host_list"][_host_uuid]["vmc"] = obj_attr_list["uuid"]
            obj_attr_list["host_list"][_host_uuid]["cloud_vm_uuid"] = _host_uuid
            obj_attr_list["host_list"][_host_uuid]["uuid"] = _host_uuid
            obj_attr_list["host_list"][_host_uuid]["model"] = obj_attr_list["model"]
            obj_attr_list["host_list"][_host_uuid]["function"] = "hypervisor"
            obj_attr_list["host_list"][_host_uuid]["cores"] = "NA"
            obj_attr_list["host_list"][_host_uuid]["memory"] = "NA"
            obj_attr_list["host_list"][_host_uuid]["arrival"] = int(time())
            obj_attr_list["host_list"][_host_uuid]["simulated"] = False
            obj_attr_list["host_list"][_host_uuid]["identity"] = obj_attr_list["identity"]
    
            obj_attr_list["host_list"][_host_uuid]["hypervisor_type"] = "docker"
                                                
            if "login" in obj_attr_list :
                obj_attr_list["host_list"][_host_uuid]["login"] = obj_attr_list["login"]
            else :
                obj_attr_list["host_list"][_host_uuid]["login"] = "******"
                
            obj_attr_list["host_list"][_host_uuid]["counter"] = obj_attr_list["counter"]
            obj_attr_list["host_list"][_host_uuid]["mgt_001_provisioning_request_originated"] = obj_attr_list["mgt_001_provisioning_request_originated"]
            obj_attr_list["host_list"][_host_uuid]["mgt_002_provisioning_request_sent"] = obj_attr_list["mgt_002_provisioning_request_sent"]
            _time_mark_prc = int(time())
            obj_attr_list["host_list"][_host_uuid]["mgt_003_provisioning_request_completed"] = _time_mark_prc - start
                
        obj_attr_list["hosts"] = obj_attr_list["hosts"][:-1]

        self.additional_host_discovery (obj_attr_list)

        return True
Example #14
0
    def vmcregister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list[
                "mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                    obj_attr_list["mgt_001_provisioning_request_originated"])

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list[
                    "cleanup_on_attach"] == "True":
                _msg = "Removing all VMs previously created on VMC \""
                _msg += obj_attr_list[
                    "name"] + "\" (only VMs names starting with"
                _msg += " \"" + "cb-" + obj_attr_list[
                    "username"] + '-' + obj_attr_list["cloud_name"]
                _msg += "\")....."
                cbdebug(_msg, True)
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            _access_url, _iaas_endpoint = obj_attr_list["access"].split('-')
            _name, _discard = _access_url.split(':')

            obj_attr_list["cloud_hostname"], obj_attr_list[
                "cloud_ip"] = hostname2ip(_name)

            obj_attr_list["arrival"] = int(time())

            if obj_attr_list["discover_hosts"].lower() == "true":
                _msg = "Discovering hosts on VMC \"" + obj_attr_list[
                    "name"] + "\"....."
                cbdebug(_msg, True)
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else:
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

            _time_mark_prc = int(time())
            obj_attr_list[
                "mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

            _status = 0

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
Example #15
0
    def vmcregister(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = \
            _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])            

            self.connect(obj_attr_list["access"], \
                         obj_attr_list["credentials"], \
                         obj_attr_list["name"])

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True" :
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else :
                _status = 0

            obj_attr_list["cloud_hostname"] = obj_attr_list["name"]

            obj_attr_list["cloud_hostname"], obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["name"], False)

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid(obj_attr_list["name"])

            obj_attr_list["arrival"] = int(time())
            
            if str(obj_attr_list["discover_hosts"]).lower() == "true" :
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else :
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

            obj_attr_list["network_detected"] = "flannel"
            _container_list = pykube.objects.Pod.objects(self.kubeconn).filter(namespace = "kube-system")
            for _container in _container_list :
                if _container.name.count("calico") :
                    obj_attr_list["network_detected"] = "calico"
            
            _time_mark_prc = int(time())
            obj_attr_list["mgt_003_provisioning_request_completed"] = \
            _time_mark_prc - _time_mark_prs
            
            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
Example #16
0
    def vmcregister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list[
                "mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                    obj_attr_list["mgt_001_provisioning_request_originated"])

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list[
                    "cleanup_on_attach"] == "True":
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            if not _status:
                _x, _y, _hostname = self.connect(obj_attr_list["access"], \
                                                 obj_attr_list["credentials"], \
                                                 obj_attr_list["name"])

                obj_attr_list["cloud_hostname"] = _hostname.replace(
                    "https://", '')

                _x, obj_attr_list["cloud_ip"] = hostname2ip(
                    obj_attr_list["cloud_hostname"])

                obj_attr_list["arrival"] = int(time())

            if obj_attr_list["discover_hosts"].lower() == "true":
                _msg = "Host discovery for VMC \"" + obj_attr_list["name"]
                _msg += "\" request, but SoftLayer does not allow it. Ignoring for now....."
                cbdebug(_msg, True)
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"
            else:
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

                _time_mark_prc = int(time())
                obj_attr_list[
                    "mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
Example #17
0
    def discover_hosts(self, obj_attr_list, start) :
        '''
        TBD
        '''
        _host_uuid = obj_attr_list["cloud_vm_uuid"]

        obj_attr_list["host_list"] = {}
        obj_attr_list["hosts"] = ''

        obj_attr_list["initial_hosts"] = obj_attr_list["initial_hosts"].split(',')
        obj_attr_list["host_count"] = len(obj_attr_list["initial_hosts"])
    
        for _host_n in range(0, obj_attr_list["host_count"]) :
            _host_uuid = self.generate_random_uuid()
            obj_attr_list["hosts"] += _host_uuid + ','            
            obj_attr_list["host_list"][_host_uuid] = {}
            obj_attr_list["host_list"][_host_uuid]["pool"] = obj_attr_list["pool"].upper()
            obj_attr_list["host_list"][_host_uuid]["username"] = obj_attr_list["username"]

            obj_attr_list["host_list"][_host_uuid]["notification"] = "False"
            obj_attr_list["host_list"][_host_uuid]["cloud_hostname"], \
            obj_attr_list["host_list"][_host_uuid]["cloud_ip"] = hostname2ip(obj_attr_list["initial_hosts"][_host_n], True)                

            obj_attr_list["host_list"][_host_uuid]["name"] = "host_"  + obj_attr_list["host_list"][_host_uuid]["cloud_hostname"]
            obj_attr_list["host_list"][_host_uuid]["vmc_name"] = obj_attr_list["name"]
            obj_attr_list["host_list"][_host_uuid]["vmc"] = obj_attr_list["uuid"]
            obj_attr_list["host_list"][_host_uuid]["cloud_vm_uuid"] = _host_uuid
            obj_attr_list["host_list"][_host_uuid]["uuid"] = _host_uuid
            obj_attr_list["host_list"][_host_uuid]["model"] = obj_attr_list["model"]
            obj_attr_list["host_list"][_host_uuid]["function"] = "hypervisor"
            obj_attr_list["host_list"][_host_uuid]["cores"] = 16
            obj_attr_list["host_list"][_host_uuid]["memory"] = 131072
            obj_attr_list["host_list"][_host_uuid]["arrival"] = int(time())
            obj_attr_list["host_list"][_host_uuid]["simulated"] = False
            obj_attr_list["host_list"][_host_uuid]["identity"] = obj_attr_list["identity"]
            if "login" in obj_attr_list :
                obj_attr_list["host_list"][_host_uuid]["login"] = obj_attr_list["login"]
            else :
                obj_attr_list["host_list"][_host_uuid]["login"] = "******"
            obj_attr_list["host_list"][_host_uuid]["counter"] = obj_attr_list["counter"]
            obj_attr_list["host_list"][_host_uuid]["mgt_001_provisioning_request_originated"] = obj_attr_list["mgt_001_provisioning_request_originated"]
            obj_attr_list["host_list"][_host_uuid]["mgt_002_provisioning_request_sent"] = obj_attr_list["mgt_002_provisioning_request_sent"]
            _time_mark_prc = int(time())
            obj_attr_list["host_list"][_host_uuid]["mgt_003_provisioning_request_completed"] = _time_mark_prc - start

        obj_attr_list["hosts"] = obj_attr_list["hosts"][:-1]

        self.additional_host_discovery (obj_attr_list)

        return True
Example #18
0
    def vmcregister(self, obj_attr_list):
        """
        TBD
        """
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                obj_attr_list["mgt_001_provisioning_request_originated"]
            )

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True":
                _msg = 'Removing all VMs previously created on VMC "'
                _msg += obj_attr_list["name"] + '" (only VMs names starting with'
                _msg += ' "' + "cb-" + obj_attr_list["username"] + "-" + obj_attr_list["cloud_name"]
                _msg += '").....'
                cbdebug(_msg, True)
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            if not _status:
                _x, _y = self.connect(obj_attr_list["access"], obj_attr_list["api_key"], obj_attr_list["secret_key"])

                _zoneid = self.get_zone(obj_attr_list["name"])

                obj_attr_list["cloud_hostname"] = obj_attr_list["name"]
                _x, obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["access"].split(":")[1].replace("//", ""))
                obj_attr_list["arrival"] = int(time())

                if obj_attr_list["discover_hosts"].lower() == "true":
                    _msg = 'Discovering hosts on VMC "' + obj_attr_list["name"] + '".....'
                    cbdebug(_msg, True)
                    _status, _fmsg = self.discover_hosts(obj_attr_list, _time_mark_prs)
                else:
                    obj_attr_list["hosts"] = ""
                    obj_attr_list["host_list"] = {}
                    obj_attr_list["host_count"] = "NA"

                _time_mark_prc = int(time())

                obj_attr_list["mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

        except CldOpsException, obj:
            _fmsg = str(obj.msg)
            cberr(_msg)
            _status = 2
Example #19
0
    def vmcregister(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])
            
            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True" :
                _msg = "Removing all VMs previously created on VMC \""
                _msg += obj_attr_list["name"] + "\" (only VMs names starting with"
                _msg += " \"" + "cb-" + obj_attr_list["username"] + '-' + obj_attr_list["cloud_name"]
                _msg += "\")....."
                cbdebug(_msg, True)
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else :
                _status = 0

            if not _status :
                _x, _y = self.connect(obj_attr_list["access"], obj_attr_list["api_key"], obj_attr_list["secret_key"])
            
                _zoneid = self.get_zone(obj_attr_list["name"])

                obj_attr_list["cloud_hostname"] = obj_attr_list["name"];
                _x, obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["access"].split(':')[1].replace('//',''))
                obj_attr_list["arrival"] = int(time())

                if obj_attr_list["discover_hosts"].lower() == "true" :
                    _msg = "Discovering hosts on VMC \"" + obj_attr_list["name"] + "\"....."
                    cbdebug(_msg, True)
                    _status, _fmsg = self.discover_hosts(obj_attr_list, _time_mark_prs)
                else :
                    obj_attr_list["hosts"] = ''
                    obj_attr_list["host_list"] = {}
                    obj_attr_list["host_count"] = "NA"

                _time_mark_prc = int(time())

                obj_attr_list["mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

        except CldOpsException, obj :
            _fmsg = str(obj.msg)
            cberr(_msg)
            _status = 2
Example #20
0
    def vmcregister(self, obj_attr_list):
        """
        TBD
        """
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                obj_attr_list["mgt_001_provisioning_request_originated"]
            )

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True":
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            if not _status:
                _x, _y, _hostname = self.connect(
                    obj_attr_list["access"], obj_attr_list["credentials"], obj_attr_list["name"]
                )

                obj_attr_list["cloud_hostname"] = _hostname.replace("https://", "")

                _x, obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["cloud_hostname"])

                obj_attr_list["arrival"] = int(time())

            if obj_attr_list["discover_hosts"].lower() == "true":
                _msg = 'Host discovery for VMC "' + obj_attr_list["name"]
                _msg += '" request, but SoftLayer does not allow it. Ignoring for now.....'
                cbdebug(_msg, True)
                obj_attr_list["hosts"] = ""
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"
            else:
                obj_attr_list["hosts"] = ""
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

                _time_mark_prc = int(time())
                obj_attr_list["mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
Example #21
0
    def vmcregister(self, obj_attr_list):
        """
        TBD
        """
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                obj_attr_list["mgt_001_provisioning_request_originated"]
            )

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True":
                _msg = 'Removing all VMs previously created on VMC "'
                _msg += obj_attr_list["name"] + '" (only VMs names starting with'
                _msg += ' "' + "cb-" + obj_attr_list["username"] + "-" + obj_attr_list["cloud_name"]
                _msg += '").....'
                cbdebug(_msg, True)
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            _access_url, _iaas_endpoint = obj_attr_list["access"].split("-")
            _name, _discard = _access_url.split(":")

            obj_attr_list["cloud_hostname"], obj_attr_list["cloud_ip"] = hostname2ip(_name)

            obj_attr_list["arrival"] = int(time())

            if obj_attr_list["discover_hosts"].lower() == "true":
                _msg = 'Discovering hosts on VMC "' + obj_attr_list["name"] + '".....'
                cbdebug(_msg, True)
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else:
                obj_attr_list["hosts"] = ""
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

            _time_mark_prc = int(time())
            obj_attr_list["mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

            _status = 0

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
Example #22
0
    def vmcregister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = \
            _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list[
                    "cleanup_on_attach"] == "True":
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else:
                _status = 0

            obj_attr_list["cloud_hostname"] = obj_attr_list["name"]

            obj_attr_list["cloud_hostname"], obj_attr_list[
                "cloud_ip"] = hostname2ip(obj_attr_list["cloud_hostname"],
                                          False)

            obj_attr_list["cloud_ip"].replace(
                "undefined", "undefined_" + str(obj_attr_list["counter"]))

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()

            obj_attr_list["arrival"] = int(time())

            if obj_attr_list["discover_hosts"].lower() == "true":
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else:
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

            _time_mark_prc = int(time())
            obj_attr_list["mgt_003_provisioning_request_completed"] = \
            _time_mark_prc - _time_mark_prs

            _status = 0

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
Example #23
0
    def vmcregister(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = \
            _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])            

            self.connect(obj_attr_list["access"], \
                         obj_attr_list["credentials"], \
                         obj_attr_list["name"], obj_attr_list)

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True" :
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else :
                _status = 0

            obj_attr_list["cloud_hostname"], obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["name"], False)

            _fmsg = "VMC " + obj_attr_list["uuid"] + " could not be registered "
            _fmsg += " on " + self.get_description() + " \"" + obj_attr_list["cloud_name"] + "\"."

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid(obj_attr_list["name"])

            obj_attr_list["arrival"] = int(time())
            
            if obj_attr_list["discover_hosts"].lower() == "true" :
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else :
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"
            
            _time_mark_prc = int(time())
            obj_attr_list["mgt_003_provisioning_request_completed"] = \
            _time_mark_prc - _time_mark_prs
            
            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
Example #24
0
    def vmcregister(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])
            
            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True" :
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else :
                _status = 0

            if not _status :
                _x, _y, _hostname = self.connect(obj_attr_list["access"], \
                                                 obj_attr_list["credentials"], \
                                                 obj_attr_list["name"])
    
                obj_attr_list["cloud_hostname"] = _hostname.replace("https://",'')

                _x, obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["cloud_hostname"])

                obj_attr_list["arrival"] = int(time())
    
            if str(obj_attr_list["discover_hosts"]).lower() == "true" :
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else :
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"

            _time_mark_prc = int(time())
                    
            obj_attr_list["mgt_003_provisioning_request_completed"] = _time_mark_prc - _time_mark_prs

            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
Example #25
0
    def vmcregister(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = \
            _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])            

            if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True" :
                _status, _fmsg = self.vmccleanup(obj_attr_list)
            else :
                _status = 0

            obj_attr_list["cloud_hostname"] = obj_attr_list["name"]

            obj_attr_list["cloud_hostname"], obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["cloud_hostname"], False)
            
            obj_attr_list["cloud_ip"].replace("undefined", "undefined_" + str(obj_attr_list["counter"])) 

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()

            obj_attr_list["arrival"] = int(time())
            
            if obj_attr_list["discover_hosts"].lower() == "true" :
                self.discover_hosts(obj_attr_list, _time_mark_prs)
            else :
                obj_attr_list["hosts"] = ''
                obj_attr_list["host_list"] = {}
                obj_attr_list["host_count"] = "NA"
            
            _time_mark_prc = int(time())
            obj_attr_list["mgt_003_provisioning_request_completed"] = \
            _time_mark_prc - _time_mark_prs
            
            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
Example #26
0
    def get_ip_address(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _private_hostname = '{0}'.format(
                obj_attr_list["instance_obj"].private_dns_name)
            _private_ip_address = '{0}'.format(
                obj_attr_list["instance_obj"].private_ip_address)
            _public_hostname = '{0}'.format(
                obj_attr_list["instance_obj"].public_dns_name)
            _public_hostname, _public_ip_address = hostname2ip(
                _public_hostname)
            if obj_attr_list["run_netname"] == "private":
                obj_attr_list["cloud_hostname"] = _private_hostname
                obj_attr_list["run_cloud_ip"] = _private_ip_address
            else:
                obj_attr_list["cloud_hostname"] = _public_hostname
                obj_attr_list["run_cloud_ip"] = _public_ip_address

            # NOTE: "cloud_ip" is always equal to "run_cloud_ip"
            obj_attr_list["cloud_ip"] = obj_attr_list["run_cloud_ip"]

            if str(obj_attr_list["use_vpn_ip"]).lower() == "true" and str(
                    obj_attr_list["vpn_only"]).lower() == "true":
                assert (self.get_attr_from_pending(obj_attr_list))

                if "cloud_init_vpn" not in obj_attr_list:
                    cbdebug("Instance VPN address not yet available.")
                    return False
                cbdebug("Found VPN IP: " + obj_attr_list["cloud_init_vpn"])
                obj_attr_list["prov_cloud_ip"] = obj_attr_list[
                    "cloud_init_vpn"]
            else:
                if obj_attr_list["prov_netname"] == "private":
                    obj_attr_list["prov_cloud_ip"] = _private_ip_address
                else:
                    obj_attr_list["prov_cloud_ip"] = _public_ip_address

            return True
        except:
            return False
Example #27
0
    def connect(self,
                access,
                credentials,
                vmc_name,
                extra_parms={},
                diag=False,
                generate_rc=False):
        '''
        TBD
        '''
        try:
            _status = 100
            _endpoint_ip = "NA"
            _fmsg = "An error has occurred, but no error message was captured"

            self.ssl_key = extra_parms["ssl_key"]
            self.ssl_cert = extra_parms["ssl_cert"]

            for _endpoint in access.split(','):
                _endpoint_name, _endpoint_ip = hostname2ip(
                    _endpoint.split('//')[1].split(':')[0], True)

                if _endpoint_ip not in self.lxdconn:
                    self.lxdconn[_endpoint_ip] = Client(endpoint=_endpoint,
                                                        cert=(self.ssl_cert,
                                                              self.ssl_key),
                                                        verify=False)
                    self.lxdconn[_endpoint_ip].authenticate(credentials)
                    if not self.lxdconn[_endpoint_ip].trusted:
                        _fmsg = "Unable to authenticate"
                        _status = 101

            _status -= 100

        except LXDError.ClientConnectionFailed, obj:
            _status = 18127
            _fmsg = str(obj.message)
Example #28
0
    def get_ip_address(self, obj_attr_list):
        """
        TBD
        """
        try:
            _private_hostname = "{0}".format(obj_attr_list["instance_obj"].private_dns_name)
            _private_ip_address = "{0}".format(obj_attr_list["instance_obj"].private_ip_address)
            _public_hostname = "{0}".format(obj_attr_list["instance_obj"].public_dns_name)
            _public_hostname, _public_ip_address = hostname2ip(_public_hostname)
            if obj_attr_list["run_netname"] == "private":
                obj_attr_list["cloud_hostname"] = _private_hostname
                obj_attr_list["cloud_ip"] = _private_ip_address
            else:
                obj_attr_list["cloud_hostname"] = _public_hostname
                obj_attr_list["cloud_ip"] = _public_ip_address

            if obj_attr_list["prov_netname"] == "private":
                obj_attr_list["prov_cloud_ip"] = _private_ip_address
            else:
                obj_attr_list["prov_cloud_ip"] = _public_ip_address

            return True
        except:
            return False
Example #29
0
    def get_ip_address(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _private_hostname = '{0}'.format(obj_attr_list["instance_obj"].private_dns_name)
            _private_ip_address = '{0}'.format(obj_attr_list["instance_obj"].private_ip_address)
            _public_hostname = '{0}'.format(obj_attr_list["instance_obj"].public_dns_name)
            _public_hostname, _public_ip_address = hostname2ip(_public_hostname)
            if obj_attr_list["run_netname"] == "private" :
                obj_attr_list["cloud_hostname"] = _private_hostname
                obj_attr_list["run_cloud_ip"] = _private_ip_address
            else :
                obj_attr_list["cloud_hostname"] = _public_hostname
                obj_attr_list["run_cloud_ip"] = _public_ip_address

            # NOTE: "cloud_ip" is always equal to "run_cloud_ip"
            obj_attr_list["cloud_ip"] = obj_attr_list["run_cloud_ip"]

            if str(obj_attr_list["use_vpn_ip"]).lower() == "true" and str(obj_attr_list["vpn_only"]).lower() == "true" :
                assert(self.get_attr_from_pending(obj_attr_list))

                if "cloud_init_vpn" not in obj_attr_list :
                    cbdebug("Instance VPN address not yet available.")
                    return False
                cbdebug("Found VPN IP: " + obj_attr_list["cloud_init_vpn"])
                obj_attr_list["prov_cloud_ip"] = obj_attr_list["cloud_init_vpn"]
            else :
                if obj_attr_list["prov_netname"] == "private" :
                    obj_attr_list["prov_cloud_ip"] = _private_ip_address
                else :
                    obj_attr_list["prov_cloud_ip"]  = _public_ip_address

            return True
        except :
            return False
Example #30
0
def rsync_filestore_setup(global_objects, operation = "check") :
    '''
    TBD
    '''
    _hostname = global_objects["filestore"]["hostname"]
    _protocol = global_objects["filestore"]["protocol"]
    _username = global_objects["filestore"]["username"]
    _port = global_objects["filestore"]["port"]
    _usage = global_objects["filestore"]["usage"].lower()
    _base_dir = global_objects["space"]["base_dir"]
    _stores_wk_dir = global_objects["space"]["stores_working_dir"]
    _log_dir = global_objects["space"]["log_dir"]

    try :
        _name, _ip = hostname2ip(_hostname)        
        
        if operation == "check" :

            if _usage == "shared" :

                _hostport = int(global_objects["filestore"]["port"])
                
                if not pre_check_port(_hostname, _hostport, _protocol) :
                    _proc_man =  ProcessManagement(username = "******")
                    _rsync_pid = _proc_man.get_pid_from_cmdline("rsync --daemon")
    
                    _cmd = "rsync --daemon"

                    if not _rsync_pid :
                        _msg = "Unable to detect a shared rsync server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"                    
                        print _msg
                        exit(8)

            else :
                _usage = "private"

                _proc_man =  ProcessManagement(username = _username)
                
                _config_file_fn = _stores_wk_dir + '/' + _username + "_rsync.conf"
                _cmd = "rsync --daemon --config " + _config_file_fn

                if not access(_config_file_fn, F_OK) :
                    # File was deleted, but the rsync process is still dangling
                    _proc_man.run_os_command("sudo pkill -9 -f " + _config_file_fn)

                _rsyslog_pid = _proc_man.get_pid_from_cmdline(_cmd)

                if not _rsyslog_pid :

                    _proc_man.run_os_command("sudo rm -rf " + _stores_wk_dir + '/' + _username + "_rsyncd.pid")
                    
                    global_objects["filestore"]["port"] = _proc_man.get_free_port(global_objects["filestore"]["port"], protocol = "tcp")

                    _hostport = int(global_objects["filestore"]["port"])
                    
                    _config_file_contents = global_objects["filestore"]["config_string"].replace('_', ' ')
                    _config_file_contents = _config_file_contents.replace("DOLLAR", '$')
                    _config_file_contents = _config_file_contents.replace("REPLEQUAL", '=')                    
                    _config_file_contents = _config_file_contents.replace("REPLPORT", str(_hostport))
                    _config_file_contents = _config_file_contents.replace("REPLLOGDIR", _log_dir)
                    _config_file_contents = _config_file_contents.replace("REPLUSERU", _username + '_')
                    _config_file_contents = _config_file_contents.replace("REPLUSER", _username)                    
                    _config_file_contents = _config_file_contents.replace("REPLBASEDIR", _base_dir)
                    _config_file_contents = _config_file_contents.replace("REPLSTORESWORKINGDIR", global_objects["space"]["stores_working_dir"])                                         
                    _config_file_contents = _config_file_contents.replace(';','\n')
                    _config_file_contents = _config_file_contents.replace("--", ';')

                    _config_file_fn = _stores_wk_dir + '/' + _username + "_rsync.conf"
                    _config_file_fd = open(_config_file_fn, 'w')
                    _config_file_fd.write(_config_file_contents)
                    _config_file_fd.close()
                    
                    _rsyslog_pid = _proc_man.start_daemon("sudo " + _cmd)

                    if not _rsyslog_pid :
                        _msg = "Unable to detect a private rsyslog server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"
                        print _msg
                        exit(8)

                else :
                    _config_file_fd = open(_config_file_fn, 'r')
                    _config_file_contents = _config_file_fd.readlines()
                    _config_file_fd.close()

                    for _line in _config_file_contents :
                        if _line.count("port=") :
                            global_objects["filestore"]["port"] = _line.split('=')[1]
                            _hostport = int(global_objects["filestore"]["port"])
                            break

        _nh_conn = Nethashget(_hostname)
        
        _nh_conn.nmap(_hostport, _protocol)
        _msg = "A File Store of the kind \"rsync\" (" + _usage + ") "
        _msg += "on node " + _hostname + ", " + _protocol
        _msg += " port " + str(_hostport) + " seems to be running."
        cbdebug(_msg)
        _status = 0
        return _status, _msg

    except socket.herror:
        _status = 1200
        _msg = "The IP address \"" + _hostname + "\" - used by the rsync "
        _msg += " daemon - is not mapped to a Hostname. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)

    except socket.gaierror:
        _status = 1200
        _msg = "The Hostname \"" + _hostname + "\" - used by the rsync"
        _msg += " daemon - is not mapped to an IP. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)
    
    except ProcessManagement.ProcessManagementException, obj :
        _status = str(obj.status)
        _msg = str(obj.msg)
        raise StoreSetupException(_msg, 9)
def rsync_filestore_setup(global_objects, operation="check"):
    '''
    TBD
    '''
    _hostname = global_objects["filestore"]["hostname"]
    _protocol = global_objects["filestore"]["protocol"]
    _username = global_objects["filestore"]["username"]
    _port = global_objects["filestore"]["port"]
    _usage = global_objects["filestore"]["usage"].lower()
    _base_dir = global_objects["space"]["base_dir"]
    _stores_wk_dir = global_objects["space"]["stores_working_dir"]
    _log_dir = global_objects["space"]["log_dir"]

    try:
        _name, _ip = hostname2ip(_hostname)

        if operation == "check":

            if _usage == "shared":

                _hostport = int(global_objects["filestore"]["port"])

                if not pre_check_port(_hostname, _hostport, _protocol):
                    _proc_man = ProcessManagement(username="******")
                    _rsync_pid = _proc_man.get_pid_from_cmdline(
                        "rsync --daemon")

                    _cmd = "rsync --daemon"

                    if not _rsync_pid:
                        _msg = "Unable to detect a shared rsync server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"
                        print _msg
                        exit(8)

            else:
                _usage = "private"

                _proc_man = ProcessManagement(username=_username)

                _config_file_fn = _stores_wk_dir + '/' + _username + "_rsync.conf"
                _cmd = "rsync --daemon --config " + _config_file_fn

                if not access(_config_file_fn, F_OK):
                    # File was deleted, but the rsync process is still dangling
                    _proc_man.run_os_command("sudo pkill -9 -f " +
                                             _config_file_fn)

                _rsyslog_pid = _proc_man.get_pid_from_cmdline(_cmd)

                if not _rsyslog_pid:

                    _proc_man.run_os_command("sudo rm -rf " + _stores_wk_dir +
                                             '/' + _username + "_rsyncd.pid")

                    global_objects["filestore"][
                        "port"] = _proc_man.get_free_port(
                            global_objects["filestore"]["port"],
                            protocol="tcp")

                    _hostport = int(global_objects["filestore"]["port"])

                    _config_file_contents = global_objects["filestore"][
                        "config_string"].replace('_', ' ')
                    _config_file_contents = _config_file_contents.replace(
                        "DOLLAR", '$')
                    _config_file_contents = _config_file_contents.replace(
                        "REPLEQUAL", '=')
                    _config_file_contents = _config_file_contents.replace(
                        "REPLPORT", str(_hostport))
                    _config_file_contents = _config_file_contents.replace(
                        "REPLLOGDIR", _log_dir)
                    _config_file_contents = _config_file_contents.replace(
                        "REPLUSERU", _username + '_')
                    _config_file_contents = _config_file_contents.replace(
                        "REPLUSER", _username)
                    _config_file_contents = _config_file_contents.replace(
                        "REPLBASEDIR", _base_dir)
                    _config_file_contents = _config_file_contents.replace(
                        "REPLSTORESWORKINGDIR",
                        global_objects["space"]["stores_working_dir"])
                    _config_file_contents = _config_file_contents.replace(
                        ';', '\n')
                    _config_file_contents = _config_file_contents.replace(
                        "--", ';')

                    _config_file_fn = _stores_wk_dir + '/' + _username + "_rsync.conf"
                    _config_file_fd = open(_config_file_fn, 'w')
                    _config_file_fd.write(_config_file_contents)
                    _config_file_fd.close()

                    _rsyslog_pid = _proc_man.start_daemon("sudo " + _cmd)

                    if not _rsyslog_pid:
                        _msg = "Unable to detect a private rsyslog server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"
                        print _msg
                        exit(8)

                else:
                    _config_file_fd = open(_config_file_fn, 'r')
                    _config_file_contents = _config_file_fd.readlines()
                    _config_file_fd.close()

                    for _line in _config_file_contents:
                        if _line.count("port="):
                            global_objects["filestore"]["port"] = _line.split(
                                '=')[1]
                            _hostport = int(
                                global_objects["filestore"]["port"])
                            break

        _nh_conn = Nethashget(_hostname)

        _nh_conn.nmap(_hostport, _protocol)
        _msg = "A File Store of the kind \"rsync\" (" + _usage + ") "
        _msg += "on node " + _hostname + ", " + _protocol
        _msg += " port " + str(_hostport) + " seems to be running."
        cbdebug(_msg)
        _status = 0
        return _status, _msg

    except socket.herror:
        _status = 1200
        _msg = "The IP address \"" + _hostname + "\" - used by the rsync "
        _msg += " daemon - is not mapped to a Hostname. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)

    except socket.gaierror:
        _status = 1200
        _msg = "The Hostname \"" + _hostname + "\" - used by the rsync"
        _msg += " daemon - is not mapped to an IP. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)

    except ProcessManagement.ProcessManagementException, obj:
        _status = str(obj.status)
        _msg = str(obj.msg)
        raise StoreSetupException(_msg, 9)
def syslog_logstore_setup(global_objects, operation="check"):
    '''
    TBD
    '''
    _hostname = global_objects["logstore"]["hostname"]
    _protocol = global_objects["logstore"]["protocol"]
    _username = global_objects["logstore"]["username"]
    _usage = global_objects["logstore"]["usage"].lower()
    _stores_wk_dir = global_objects["space"]["stores_working_dir"]
    _log_dir = global_objects["space"]["log_dir"]

    try:
        _name, _ip = hostname2ip(_hostname)

        if operation == "check":

            if _usage == "shared":

                _hostport = int(global_objects["logstore"]["port"])

                if not pre_check_port(_hostname, _hostport, _protocol):
                    _proc_man = ProcessManagement(username="******")
                    _rsyslog_pid = _proc_man.get_pid_from_cmdline("rsyslogd")

                    _cmd = "/sbin/rsyslogd -i /var/run/syslogd.pid "

                    if not _rsyslog_pid:
                        _msg = "Unable to detect a shared rsyslog server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"
                        print _msg
                        exit(8)

            else:
                _usage = "private"

                _proc_man = ProcessManagement(username=_username)

                _config_file_fn = _stores_wk_dir + '/' + _username + "_rsyslog.conf"
                _cmd = "rsyslogd -f " + _config_file_fn + " " + "-i " + _stores_wk_dir + "/rsyslog.pid"

                if not access(_config_file_fn, F_OK):
                    # File was deleted, but the rsyslog process is still dangling
                    _proc_man.run_os_command("sudo pkill -9 -f " +
                                             _config_file_fn)

                if not access(_log_dir, W_OK):
                    # The directory does not even exist, kill any rsyslog processes still dangling
                    _proc_man.run_os_command("sudo pkill -9 -f " +
                                             _config_file_fn)
                    _proc_man.run_os_command("sudo mkdir -p " + _log_dir +
                                             " && sudo chmod 777 " + _log_dir)

                _rsyslog_pid = _proc_man.get_pid_from_cmdline(_cmd)

                if not _rsyslog_pid:

                    global_objects["logstore"]["port"] = _proc_man.get_free_port(global_objects["logstore"]["port"],\
                                                                                 protocol = "udp")
                    _hostport = int(global_objects["logstore"]["port"])

                    _config_file_contents = global_objects["logstore"][
                        "config_string"].replace('_', ' ')
                    _config_file_contents = _config_file_contents.replace(
                        "DOLLAR", '$')
                    _config_file_contents = _config_file_contents.replace(
                        "RSYSLOG", "RSYSLOG_")
                    _config_file_contents = _config_file_contents.replace(
                        "REPLPORT", str(_hostport))
                    _config_file_contents = _config_file_contents.replace(
                        "REPLLOGDIR", _log_dir)
                    _config_file_contents = _config_file_contents.replace(
                        "REPLUSER", _username + '_')
                    _config_file_contents = _config_file_contents.replace(
                        ';', '\n')
                    _config_file_contents = _config_file_contents.replace(
                        "--", ';')

                    _config_file_fn = _stores_wk_dir + '/' + _username + "_rsyslog.conf"
                    _config_file_fd = open(_config_file_fn, 'w')
                    _config_file_fd.write(_config_file_contents)
                    _config_file_fd.close()

                    _rsyslog_pid = _proc_man.start_daemon(_cmd)

                    if not _rsyslog_pid:
                        _msg = "Unable to detect a private rsyslog server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"
                        print _msg
                        exit(8)

                else:
                    _config_file_fd = open(_config_file_fn, 'r')
                    _config_file_contents = _config_file_fd.readlines()
                    _config_file_fd.close()

                    for _line in _config_file_contents:
                        if _line.count("UDPServerRun"):
                            global_objects["logstore"]["port"] = _line.split(
                            )[1]
                            _hostport = int(global_objects["logstore"]["port"])
                            break

        _nh_conn = Nethashget(_hostname)

        _nh_conn.nmap(_hostport, _protocol)
        _msg = "A Log Store of the kind \"rsyslog\" (" + _usage + ") "
        _msg += "on node " + _hostname + ", " + _protocol
        _msg += " port " + str(_hostport) + " seems to be running."
        cbdebug(_msg)
        _status = 0
        return _status, _msg

    except socket.herror:
        _status = 1200
        _msg = "The IP address \"" + _hostname + "\" - used by the rsyslog "
        _msg += " daemon - is not mapped to a Hostname. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)

    except socket.gaierror:
        _status = 1200
        _msg = "The Hostname \"" + _hostname + "\" - used by the rsyslog"
        _msg += " daemon - is not mapped to an IP. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)

    except ProcessManagement.ProcessManagementException, obj:
        _status = str(obj.status)
        _msg = str(obj.msg)
        raise StoreSetupException(_msg, 9)
Example #33
0
 def get_ip_from_hostname(self, obj_attr_list):
     try:
         obj_attr_list["cloud_hostname"], obj_attr_list["cloud_ip"] = hostname2ip(obj_attr_list["cloud_hostname"])
     except:
         obj_attr_list["cloud_ip"] = "undefined_" + str(obj_attr_list["counter"])
Example #34
0
def syslog_logstore_setup(global_objects, operation = "check") :
    '''
    TBD
    '''
    _hostname = global_objects["logstore"]["hostname"]
    _protocol = global_objects["logstore"]["protocol"]
    _username = global_objects["logstore"]["username"]
    _usage = global_objects["logstore"]["usage"].lower()
    _stores_wk_dir = global_objects["space"]["stores_working_dir"]
    _log_dir = global_objects["space"]["log_dir"]

    try :
        _name, _ip = hostname2ip(_hostname)        
        
        if operation == "check" :

            if _usage == "shared" :

                _hostport = int(global_objects["logstore"]["port"])
                
                if not pre_check_port(_hostname, _hostport, _protocol) :
                    _proc_man =  ProcessManagement(username = "******")
                    _rsyslog_pid = _proc_man.get_pid_from_cmdline("rsyslogd")
    
                    _cmd = "/sbin/rsyslogd -i /var/run/syslogd.pid "

                    if not _rsyslog_pid :
                        _msg = "Unable to detect a shared rsyslog server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"                    
                        print _msg
                        exit(8)

            else :
                _usage = "private"

                _proc_man =  ProcessManagement(username = _username)

                _config_file_fn = _stores_wk_dir + '/' + _username + "_rsyslog.conf"
                _cmd = "rsyslogd -f " + _config_file_fn + " " + "-i " + _stores_wk_dir + "/rsyslog.pid"

                if not access(_config_file_fn, F_OK) :
                    # File was deleted, but the rsyslog process is still dangling
                    _proc_man.run_os_command("sudo pkill -9 -f " + _config_file_fn)

                if not access(_log_dir, W_OK) :
                    # The directory does not even exist, kill any rsyslog processes still dangling
                    _proc_man.run_os_command("sudo pkill -9 -f " + _config_file_fn)                    
                    _proc_man.run_os_command("sudo mkdir -p " + _log_dir + " && sudo chmod 777 " + _log_dir)

                _rsyslog_pid = _proc_man.get_pid_from_cmdline(_cmd)     

                if not _rsyslog_pid :

                    global_objects["logstore"]["port"] = _proc_man.get_free_port(global_objects["logstore"]["port"],\
                                                                                 protocol = "udp")
                    _hostport = int(global_objects["logstore"]["port"])

                    _config_file_contents = global_objects["logstore"]["config_string"].replace('_', ' ')
                    _config_file_contents = _config_file_contents.replace("DOLLAR", '$')
                    _config_file_contents = _config_file_contents.replace("RSYSLOG", "RSYSLOG_")
                    _config_file_contents = _config_file_contents.replace("REPLPORT", str(_hostport))
                    _config_file_contents = _config_file_contents.replace("REPLLOGDIR", _log_dir)
                    _config_file_contents = _config_file_contents.replace("REPLUSER", _username + '_')                    
                    _config_file_contents = _config_file_contents.replace(';','\n')
                    _config_file_contents = _config_file_contents.replace("--", ';')

                    _config_file_fn = _stores_wk_dir + '/' + _username + "_rsyslog.conf"
                    _config_file_fd = open(_config_file_fn, 'w')
                    _config_file_fd.write(_config_file_contents)
                    _config_file_fd.close()

                    _rsyslog_pid = _proc_man.start_daemon(_cmd)
             
                    if not _rsyslog_pid :
                        _msg = "Unable to detect a private rsyslog server daemon running. "
                        _msg += "Please try to start one (e.g., " + _cmd + ")"
                        print _msg
                        exit(8)

                else :
                    _config_file_fd = open(_config_file_fn, 'r')
                    _config_file_contents = _config_file_fd.readlines()
                    _config_file_fd.close()

                    for _line in _config_file_contents :
                        if _line.count("UDPServerRun") :
                            global_objects["logstore"]["port"] = _line.split()[1]
                            _hostport = int(global_objects["logstore"]["port"])
                            break

        _nh_conn = Nethashget(_hostname)

        _nh_conn.nmap(_hostport, _protocol)
        _msg = "A Log Store of the kind \"rsyslog\" (" + _usage + ") "
        _msg += "on node " + _hostname + ", " + _protocol
        _msg += " port " + str(_hostport) + " seems to be running."
        cbdebug(_msg)
        _status = 0
        return _status, _msg

    except socket.herror:
        _status = 1200
        _msg = "The IP address \"" + _hostname + "\" - used by the rsyslog "
        _msg += " daemon - is not mapped to a Hostname. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)


    except socket.gaierror:
        _status = 1200
        _msg = "The Hostname \"" + _hostname + "\" - used by the rsyslog"
        _msg += " daemon - is not mapped to an IP. "
        _msg += "Please make sure this name is resolvable either in /etc/hosts or DNS."
        raise StoreSetupException(_msg, 9)
    
    except ProcessManagement.ProcessManagementException, obj :
        _status = str(obj.status)
        _msg = str(obj.msg)
        raise StoreSetupException(_msg, 9)