Class: StackMate::CloudStackIpAddress

Inherits:
CloudStackResource show all
Includes:
Intrinsic, Logging, Resolver
Defined in:
lib/stackmate/participants/cloudstack_ipaddress.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
46
47
48
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 9

def create
  logger.debug("Creating resource #{@name}")
  workitem[@name] = {}
  name_cs = workitem['StackName'] + '-' + @name
  args={}
  begin
    args['networkid'] = get_networkid if @props.has_key?('networkid')
    args['domainid'] = get_domainid if @props.has_key?('domainid')
    args['account'] =  if @props.has_key?('account')
    args['vpcid'] = get_vpcid if @props.has_key?('vpcid')
    args['regionid'] = get_regionid if @props.has_key?('regionid')
    args['zoneid'] = get_zoneid if @props.has_key?('zoneid')
    args['projectid'] = get_projectid if @props.has_key?('projectid')
    args['isportable'] = get_isportable if @props.has_key?('isportable')

    logger.info("Creating resource #{@name} with following arguments")
    p args
    result_obj = make_async_request('associateIpAddress',args)
    resource_obj = result_obj['IpAddress'.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'],"IpAddress") 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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 50

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('disassociateIpAddress',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



100
101
102
103
104
105
106
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 100

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

#get_domainidObject



92
93
94
95
96
97
98
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 92

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_isportableObject



140
141
142
143
144
145
146
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 140

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

#get_networkidObject



84
85
86
87
88
89
90
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 84

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

#get_projectidObject



132
133
134
135
136
137
138
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 132

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

#get_regionidObject



116
117
118
119
120
121
122
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 116

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

#get_vpcidObject



108
109
110
111
112
113
114
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 108

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

#get_zoneidObject



124
125
126
127
128
129
130
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 124

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

#on_workitemObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/stackmate/participants/cloudstack_ipaddress.rb', line 71

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