Class: StackMate::CloudStackCondition

Inherits:
CloudStackResource show all
Includes:
Intrinsic, Logging, Resolver
Defined in:
lib/stackmate/participants/cloudstack_condition.rb

Constant Summary

Constants included from Resolver

Resolver::INTEXP, Resolver::STRINGEXP, Resolver::UUIDEXP

Instance Attribute Summary

Attributes inherited from CloudStackResource

#name

Instance Method Summary collapse

Methods included from Resolver

#get_named_tag, #get_resolved, #resolve_tags, #resolve_to_deviceid, #validate_param

Methods included from Intrinsic

#fn_base64, #fn_getatt, #fn_join, #fn_lookup, #fn_map, #fn_ref, #fn_select, #intrinsic

Methods included from Logging

configure_logger_for, #logger, logger_for

Methods inherited from CloudStackResource

#initialize

Constructor Details

This class inherits a constructor from StackMate::CloudStackResource

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 9

def create
  logger.debug("Creating resource #{@name}")
  workitem[@name] = {}
  name_cs = workitem['StackName'] + '-' + @name
  args={}
  begin
    args['threshold'] = get_threshold
    args['relationaloperator'] = get_relationaloperator
    args['counterid'] = get_counterid
    args['account'] =  if @props.has_key?('account')
    args['domainid'] = get_domainid if @props.has_key?('domainid')

    logger.info("Creating resource #{@name} with following arguments")
    p args
    result_obj = make_async_request('createCondition',args)
    resource_obj = result_obj['Condition'.downcase]
    #doing it this way since it is easier to change later, rather than cloning whole object
    resource_obj.each_key do |k|
      val = resource_obj[k]
      if('id'.eql?(k))
        k = 'physical_id'
      end
      workitem[@name][k] = val
    end
    set_tags(@props['tags'],workitem[@name]['physical_id'],"Condition") if @props.has_key?('tags')
    workitem['ResolvedNames'][@name] = name_cs
    workitem['IdMap'][workitem[@name]['physical_id']] = @name
  
  rescue NoMethodError => nme
    logger.error("Create request failed for resource . Cleaning up the stack")
    raise nme
  rescue Exception => e
    logger.error(e.message)
    raise e
  end
  
end

#deleteObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 47

def delete
  logger.debug("Deleting resource #{@name}")
  begin
    physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
    if(!physical_id.nil?)
      args = {'id' => physical_id
            }
      result_obj = make_async_request('deleteCondition',args)
      if (!(result_obj['error'] == true))
        logger.info("Successfully deleted resource #{@name}")
      else
        logger.info("CloudStack error while deleting resource #{@name}")
      end
    else
      logger.info("Resource  not created in CloudStack. Skipping delete...")
    end
  rescue Exception => e
    logger.error("Unable to delete resorce #{@name}")
  end
end

#get_accountObject



105
106
107
108
109
110
111
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 105

def 
   = get_resolved(@props['account'],workitem)
  if .nil? || !validate_param(,"string")
    raise "Malformed optional parameter account for resource #{@name}"
  end
  
end

#get_counteridObject



97
98
99
100
101
102
103
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 97

def get_counterid
  resolved_counterid = get_resolved(@props["counterid"],workitem)
  if resolved_counterid.nil? || !validate_param(resolved_counterid,"uuid")
    raise "Missing mandatory parameter counterid for resource #{@name}"
  end
  resolved_counterid
end

#get_domainidObject



113
114
115
116
117
118
119
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 113

def get_domainid
  resolved_domainid = get_resolved(@props['domainid'],workitem)
  if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
    raise "Malformed optional parameter domainid for resource #{@name}"
  end
  resolved_domainid
end

#get_relationaloperatorObject



89
90
91
92
93
94
95
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 89

def get_relationaloperator
  resolved_relationaloperator = get_resolved(@props["relationaloperator"],workitem)
  if resolved_relationaloperator.nil? || !validate_param(resolved_relationaloperator,"string")
    raise "Missing mandatory parameter relationaloperator for resource #{@name}"
  end
  resolved_relationaloperator
end

#get_thresholdObject



81
82
83
84
85
86
87
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 81

def get_threshold
  resolved_threshold = get_resolved(@props["threshold"],workitem)
  if resolved_threshold.nil? || !validate_param(resolved_threshold,"long")
    raise "Missing mandatory parameter threshold for resource #{@name}"
  end
  resolved_threshold
end

#on_workitemObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/stackmate/participants/cloudstack_condition.rb', line 68

def on_workitem
  @name = workitem.participant_name
  @props = workitem['Resources'][@name]['Properties']
  @props.downcase_key
  @resolved_names = workitem['ResolvedNames']
  if workitem['params']['operation'] == 'create'
    create
  else
    delete
  end
  reply
end