Class: Nephophobia::Resource::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/nephophobia/resource/project.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Project

Returns a new instance of Project.



7
8
9
# File 'lib/nephophobia/resource/project.rb', line 7

def initialize client
  @client = client
end

Instance Method Details

#add_member(user_name, project_name) ⇒ Object

Adds the given ‘user_name’ to the specified ‘project_name’. Returns a response to the state change.

user_name: A String representing a nova user_name. project_name: A String representing a nova project_name name.



18
19
20
# File 'lib/nephophobia/resource/project.rb', line 18

def add_member user_name, project_name
  modify_membership user_name, "add", project_name
end

#all(user_name = nil) ⇒ Object

Returns information about all projects, or all projects the given ‘user_name’ is in.

user_name: An optional String representing a nova user_name.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nephophobia/resource/project.rb', line 28

def all user_name = nil
  response = @client.action "DescribeProjects", {}

  item     = response.body['DescribeProjectsResponse']['projectSet']['item']
  projects = Nephophobia::Util.coerce(item).collect do |data|
    Response::Project.new data
  end

  return projects unless user_name
  projects.map { |project| project if @client.project.member? user_name, project.name }.compact
end

#create(project_name, user_name) ⇒ Object

Creates the given ‘project_name’ and adds the specified ‘user_name’ as the manager. Returns a response to the state change.

project_name: A String representing a nova project name. user_name: A String representing a nova user_name.



47
48
49
50
51
52
53
54
55
56
# File 'lib/nephophobia/resource/project.rb', line 47

def create project_name, user_name
  params = {
    "Name"        => project_name,
    "ManagerUser" => user_name
  }

  response = @client.action "RegisterProject", params

  Response::Project.new response.body['RegisterProjectResponse']
end

#destroy(project_name) ⇒ Object

Removes the given ‘project_name’. Returns a response to the state change.

project_name: A String representing a nova project name.



64
65
66
67
68
# File 'lib/nephophobia/resource/project.rb', line 64

def destroy project_name
  response = @client.action "DeregisterProject", "Name" => project_name

  Response::Return.new response.body['DeregisterProjectResponse']
end

#find(project_name) ⇒ Object

Returns information about the given ‘project_name’.

project_name: A String representing a nova project name.



75
76
77
78
79
80
# File 'lib/nephophobia/resource/project.rb', line 75

def find project_name
  response = @client.action "DescribeProject", "Name" => project_name

  Response::Project.new response.body['DescribeProjectResponse']
rescue Hugs::Errors::BadRequest
end

#member?(user_name, project_name) ⇒ Boolean

Return a Boolean if the given ‘user_name’ is a member of the specified ‘project_name’.

user_name: A String representing a nova user_name. project_name: A String representing a nova project_name name.

Returns:

  • (Boolean)


103
104
105
# File 'lib/nephophobia/resource/project.rb', line 103

def member? user_name, project_name
  members(project_name).any? { |f| f.member == user_name }
end

#members(project_name) ⇒ Object

Returns information about all members of the given ‘project_name’.

project_name: A String representing a nova project name.



87
88
89
90
91
92
93
94
95
# File 'lib/nephophobia/resource/project.rb', line 87

def members project_name
  response = @client.action "DescribeProjectMembers", "Name" => project_name

  item = response.body['DescribeProjectMembersResponse']['members']['item']
  Nephophobia::Util.coerce(item).collect do |data|
    Response::Member.new data
  end
rescue Hugs::Errors::BadRequest
end

#remove_member(user_name, project_name) ⇒ Object

Removes the given ‘user_name’ from the specified ‘project_name’. Returns a response to the state change.

user_name: A String representing a nova user_name. project_name: A String representing a nova project_name name.



114
115
116
# File 'lib/nephophobia/resource/project.rb', line 114

def remove_member user_name, project_name
  modify_membership user_name, "remove", project_name
end