示例#1
0
    def create_launch_config(self, user_obj, lc):
        (dt_name, site_name) = _breakup_name(lc.LaunchConfigurationName)

        # see if that name already exists
        dt_def = None
        exists = self._check_dt_name_exists(dt_name, user_obj.access_id)
        if exists:
            dt_def = self._get_dt_details(dt_name, user_obj.access_id)
        if not dt_def:
            dt_def = {}
            dt_def['mappings'] = {}

        if site_name in dt_def['mappings']:
            raise PhantomAWSException('InvalidParameterValue',
                                      details="Name already in use")

        dt_def['mappings'][site_name] = {}
        # values needed by the system
        dt_def['mappings'][site_name]['iaas_allocation'] = lc.InstanceType
        dt_def['mappings'][site_name]['iaas_image'] = lc.ImageId
        dt_def['mappings'][site_name][
            'key_name'] = phantom_get_default_key_name()

        # user defined values
        dt_def['mappings'][site_name]['CreatedTime'] = make_time(
            lc.CreatedTime.date_time)
        #dt_def['mappings'][site_name]['BlockDeviceMappings'] = lc.BlockDeviceMappings
        dt_def['mappings'][site_name][
            'InstanceMonitoring'] = lc.InstanceMonitoring.Enabled
        dt_def['mappings'][site_name]['KernelId'] = lc.KernelId
        dt_def['mappings'][site_name]['RamdiskId'] = lc.RamdiskId
        dt_def['mappings'][site_name]['RequestedKeyName'] = lc.KeyName
        dt_def['mappings'][site_name][
            'LaunchConfigurationARN'] = lc.LaunchConfigurationARN

        if lc.UserData:
            try:
                lc.UserData = base64.b64decode(lc.UserData)
            except:
                raise PhantomAWSException(
                    'InvalidParameterValue',
                    details="UserData should be base64-encoded")

            dt_def['contextualization'] = {}
            dt_def['contextualization']['method'] = 'userdata'
            dt_def['contextualization']['userdata'] = lc.UserData

        if exists:
            self._dtrs_client.update_dt(user_obj.access_id, dt_name, dt_def)
        else:
            self._dtrs_client.add_dt(user_obj.access_id, dt_name, dt_def)
示例#2
0
    def create_autoscale_group(self, user_obj, asg):
        log(
            logging.DEBUG, "entering create_autoscale_group with %s" %
            (asg.LaunchConfigurationName))

        (definition_name, domain_opts) = tags_to_definition(asg.Tags.type_list)
        domain_opts['minimum_vms'] = asg.DesiredCapacity

        dt_name = asg.LaunchConfigurationName
        site_name = ""
        if dt_name.find('@') > 0:
            (dt_name, site_name) = _breakup_name(asg.LaunchConfigurationName)

        if definition_name == 'sensor_engine':
            domain_opts['deployable_type'] = dt_name
            domain_opts['dtname'] = dt_name
            domain_opts['iaas_site'] = site_name
            domain_opts['iaas_allocation'] = "m1.small"
            domain_opts['minimum_vms'] = asg.MinSize
            domain_opts['maximum_vms'] = asg.MaxSize
            domain_opts['opentsdb_host'] = self._opentsdb_host
            domain_opts['opentsdb_port'] = self._opentsdb_port
        else:
            domain_opts['dtname'] = dt_name
            domain_opts['minimum_vms'] = asg.MinSize
            domain_opts['maximum_vms'] = asg.MaxSize
            domain_opts['opentsdb_host'] = self._opentsdb_host
            domain_opts['opentsdb_port'] = self._opentsdb_port
        #domain_opts['force_site'] = site_name
        domain_opts['CreatedTime'] = make_time(asg.CreatedTime.date_time)
        domain_opts['AutoScalingGroupARN'] = asg.AutoScalingGroupARN
        domain_opts['VPCZoneIdentifier'] = asg.VPCZoneIdentifier
        domain_opts['HealthCheckType'] = asg.HealthCheckType
        domain_opts['PlacementGroup'] = asg.PlacementGroup

        conf = {'engine_conf': domain_opts}

        log(logging.INFO, "Creating autoscale group with %s" % (conf))
        try:
            self._epum_client.add_domain(asg.AutoScalingGroupName,
                                         definition_name,
                                         conf,
                                         caller=user_obj.access_id)
        except DashiError, de:
            if de.exc_type == u'WriteConflictError':
                raise PhantomAWSException(
                    'InvalidParameterValue',
                    details="auto scale name already exists")
            log(logging.ERROR, "An error creating ASG: %s" % (str(de)))
            raise
示例#3
0
    def create_launch_config(self, user_obj, lc):
        (dt_name, site_name) = _breakup_name(lc.LaunchConfigurationName)

        # see if that name already exists
        dt_def = None
        exists = self._check_dt_name_exists(dt_name, user_obj.access_id)
        if exists:
            dt_def = self._get_dt_details(dt_name, user_obj.access_id)
        if not dt_def:
            dt_def = {}
            dt_def['mappings'] = {}

        if site_name in dt_def['mappings']:
            raise PhantomAWSException('InvalidParameterValue',details="Name already in use")

        dt_def['mappings'][site_name] = {}
        # values needed by the system
        dt_def['mappings'][site_name]['iaas_allocation'] = lc.InstanceType
        dt_def['mappings'][site_name]['iaas_image'] = lc.ImageId
        dt_def['mappings'][site_name]['key_name'] = phantom_get_default_key_name()

        # user defined values
        dt_def['mappings'][site_name]['CreatedTime'] = make_time(lc.CreatedTime.date_time)
        #dt_def['mappings'][site_name]['BlockDeviceMappings'] = lc.BlockDeviceMappings
        dt_def['mappings'][site_name]['InstanceMonitoring'] = lc.InstanceMonitoring.Enabled
        dt_def['mappings'][site_name]['KernelId'] = lc.KernelId
        dt_def['mappings'][site_name]['RamdiskId'] = lc.RamdiskId
        dt_def['mappings'][site_name]['RequestedKeyName'] = lc.KeyName
        dt_def['mappings'][site_name]['LaunchConfigurationARN'] = lc.LaunchConfigurationARN

        if lc.UserData:
            try:
                lc.UserData = base64.b64decode(lc.UserData)
            except:
                raise PhantomAWSException('InvalidParameterValue', details="UserData should be base64-encoded")

            dt_def['contextualization'] = {}
            dt_def['contextualization']['method'] = 'userdata'
            dt_def['contextualization']['userdata'] = lc.UserData

        if exists:
            self._dtrs_client.update_dt(user_obj.access_id, dt_name, dt_def)
        else:
            self._dtrs_client.add_dt(user_obj.access_id, dt_name, dt_def)
示例#4
0
    def create_autoscale_group(self, user_obj, asg):
        log(logging.DEBUG, "entering create_autoscale_group with %s" % (asg.LaunchConfigurationName))

        (definition_name, domain_opts) = tags_to_definition(asg.Tags.type_list)
        domain_opts['minimum_vms'] = asg.DesiredCapacity

        dt_name = asg.LaunchConfigurationName
        site_name = ""
        if dt_name.find('@') > 0:
            (dt_name, site_name) = _breakup_name(asg.LaunchConfigurationName)

        if definition_name == 'sensor_engine':
            domain_opts['deployable_type'] = dt_name
            domain_opts['dtname'] = dt_name
            domain_opts['iaas_site'] = site_name
            domain_opts['iaas_allocation'] = "m1.small"
            domain_opts['minimum_vms'] = asg.MinSize
            domain_opts['maximum_vms'] = asg.MaxSize
            domain_opts['opentsdb_host'] = self._opentsdb_host
            domain_opts['opentsdb_port'] = self._opentsdb_port
        else:
            domain_opts['dtname'] = dt_name
            domain_opts['minimum_vms'] = asg.MinSize
            domain_opts['maximum_vms'] = asg.MaxSize
            domain_opts['opentsdb_host'] = self._opentsdb_host
            domain_opts['opentsdb_port'] = self._opentsdb_port
        #domain_opts['force_site'] = site_name
        domain_opts['CreatedTime'] =  make_time(asg.CreatedTime.date_time)
        domain_opts['AutoScalingGroupARN'] =  asg.AutoScalingGroupARN
        domain_opts['VPCZoneIdentifier'] =  asg.VPCZoneIdentifier
        domain_opts['HealthCheckType'] =  asg.HealthCheckType
        domain_opts['PlacementGroup'] =  asg.PlacementGroup

        conf = {'engine_conf': domain_opts}
        
        log(logging.INFO, "Creating autoscale group with %s" % (conf))
        try:
            self._epum_client.add_domain(asg.AutoScalingGroupName, definition_name, conf, caller=user_obj.access_id)
        except DashiError, de:
            if de.exc_type == u'WriteConflictError':
                raise PhantomAWSException('InvalidParameterValue', details="auto scale name already exists")
            log(logging.ERROR, "An error creating ASG: %s" % (str(de)))
            raise
示例#5
0
 def add_xml(self, doc, container_element):
     tm_str = make_time(self.date_time)
     txt_el = doc.createTextNode(tm_str)
     container_element.appendChild(txt_el)
示例#6
0
 def add_xml(self, doc, container_element):
     tm_str = make_time(self.date_time)
     txt_el = doc.createTextNode(tm_str)
     container_element.appendChild(txt_el)